5 полезных скриптов power shell, необходимых каждому администру share point

Reporting on SharePoint Online Storage per site PowerShell script

The PowerShell script below can help. Let me start by showing you the script and the result, and we’ll explain it right after.

Get-SPOSite -Limit All | Select Url, StorageUsageCurrent, StorageQuota, @{ Name = '% Used'; Expression = {'{0:P2}' -f ($_.StorageUsageCurrent / $_.StorageQuota) }} | Sort-Object StorageUsageCurrent -Descending
SharePoint Online Storage Report
  • All the different sites in your tenant.
  • How much storage each site is currently using.
  • The quota it’s presently configured at.
  • The percentage of the quota it used.

It will then sort sites by the ones that use the most storage at the top. Let’s break it down.

Get-SPOSite -Limit All
| Select Url, StorageUsageCurrent, StorageQuota, @{ Name = '% Used'; Expression = {'{0:P2}' -f ($_.StorageUsageCurrent / $_.StorageQuota) }}
| Sort-Object StorageUsageCurrent -Descending

Finally, the Sort-Object cmdlet is used to sort the output by the StorageUsageCurrent property in descending order. This means the sites using the most storage will be listed first. This is just a starter; feel free to save the information to a CSV file or modify the script however you want.

Setting the default sharing link type to existing people PowerShell script

Default Link Set to Only People in Your Organization
  • (Share with) Specific people that the user specifies.
  • Only people in your organization.
  • Anyone with the link.

In addition, you can also decide the default permission for those links to either be view or edit.

Tenant Level Default Link Settings
Site Level Default Link Settings
$sites = Get-SPOSite -Limit ALL | Where {$_.Template -ne "REDIRECTSITE#0" -and $_.Template -ne "SPSMSITEHOST#0" -and $_.Template -ne "POINTPUBLISHINGPERSONAL#0" -and $_.Template -ne "POINTPUBLISHINGHUB#0"}
foreach ($site in $sites) {	Write-Host -NoNewline "Changing settings for " $site.url	Try {	Set-SPOSite -Identity $site -DefaultLinkToExistingAccess $true -ErrorAction SilentlyContinue	Write-Host -ForegroundColor Green " Settings Changed Successfully"	}	Catch {	Write-Host -ForegroundColor Red " Failed to get info from " $site.url ". This can be because the site is locked or is using a template that does not support it"	}
}

The result should look like here, including the error on a currently locked site.

:/>  Исправлено: не удается извлечь внешний жесткий диск в Windows 10 -
Site Level Settings Being Changed By PowerShell Scripts

You can run the script regularly to ensure it applies to all newly created sites.

Sites that are about to be permanently deleted PowerShell script

Get-SPODeletedSite |Select Url, DaysRemaining | Sort-Object DaysRemaining
Sites in the SharePoint Online Recycle Bin and How Long Until They Get Deleted

Reporting on SharePoint Online external users PowerShell script

$sites = Get-SPOSite -Limit ALL | Where {$_.Template -ne "REDIRECTSITE#0" -and $_.Template -ne "SPSMSITEHOST#0" -and $_.Template -ne "POINTPUBLISHINGPERSONAL#0" -and $_.Template -ne "POINTPUBLISHINGHUB#0"}
$sites = Get-SPOSite -Limit ALL | Where {$_.Template -ne "REDIRECTSITE#0" -and $_.Template -ne "SPSMSITEHOST#0" -and $_.Template -ne "POINTPUBLISHINGPERSONAL#0" -and $_.Template -ne "POINTPUBLISHINGHUB#0"}
foreach ($site in $sites) {	Try {	Write-Host -NoNewline "Checking for guests on " $site.url	$Guests = Get-SPOUser -Limit All -Site $site.Url | Where {$_.LoginName -like "*urn:spo:guest*" -or $_.LoginName -like "*#ext#*"} | Select DisplayName,LoginName,@{Name = "Url" ; Expression = { $site.url }}	$ExternalUsers += $Guests	if ($Guests) {	Write-Host -ForegroundColor Green " Found Guests on this site"	}	else {	Write-Host -ForegroundColor Magenta " No Guests Found on this site"	}	}	Catch {	Write-Host -ForegroundColor Red " Change failed on" $site.url ". This can be because the site is locked or is using a template that does not support it"	}	$Guests = $null	}
$ExternalUsers

Finally, we can decide to output the array, or you can save it into a CSV file or any other storage location of your choosing.

$ExternalUsers

Here are the results:

External User Report running
External Users Found in The Tenant

Finding redirect sites in your tenant PowerShell script

The problem is that after a few years, you might have a lot of redirect sites hidden in your tenant and for sites that do not exist anymore. Also, since the redirect sites still use the URL, you cannot use the same URL for a new site either.

This PowerShell script will get all the redirect sites inside your tenant by filtering by the RedirectSite#0 template. Next, we will
select the URL of the redirect site. Finally, we create a custom property called “Redirects to” in which we use PowerShell’s web request capabilities to find out where the site redirects to. You can find the script and the results from my test tenant below.

Get-SPOSite -Template RedirectSite#0 | Select Url, @{ Name = 'Redirects to'; Expression = { (Invoke-WebRequest -Uri $_.Url -MaximumRedirection 0).Headers.Location}}
Redirect Sites and Their Redirect Location in SharePoint Online

Looking for more useful PowerShell scripts?

Subscribe to our Newsletter