
Hi @Safak ,
The error message you are receiving indicates that the input object cannot be bound to any parameters for the command. This may be because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
To fix this issue, you can try removing the FORMAT-TABLE
cmdlet from the second GET-SPOSITE
command. This will ensure that the output is in the correct format for the SET-SPOSITE
command to accept it as input.
Here is the updated code:
# Customize these variables for your needs
$sharepointAdminURL = "https://abc-admin.sharepoint.com"
$currentSharingSetting = "ExistingExternalUserSharingOnly"
$desiredSharingSetting = "ExternalUserSharingOnly"
# Check if needed modules are installed
if ($module = Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version) {
#write-host "installed"
} else {
write-host "SharePoint module Not installed, install with Install-Module -Name Microsoft.Online.SharePoint.PowerShell" -ForegroundColor Red
exit
}
# Connect to SharePoint Online if needed
try {
$testConnection = Get-SPOGeoStorageQuota # Quick connection test
}
catch {
Write-Host "Not connected. Please authenticate in the pop-up window"; Connect-SPOService -Url $sharepointAdminURL
}
# Get sites that match our current sharing setting and write them to the screen
GET-SPOSITE -LIMIT ALL | WHERE-OBJECT {$_.SharingCapability -eq $currentSharingSetting} | FORMAT-TABLE Title,URL,SharingCapability
# If the output looks good, uncomment the following line and run the script again to make the change!
GET-SPOSITE -LIMIT ALL | WHERE-OBJECT {$_.SharingCapability -eq $currentSharingSetting} | SET-SPOSITE -SharingCapability $desiredSharingSetting
For your reference:
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.