Вопрос

I am working with SharePoint PnP PowerShell and using below command. This command works but when the site does not exist it gives me an error on the screen even if I specified -ErrorAction:SilentlyContinue.

$objSite = Get-SPOSite -Identity $siteUrl
Это было полезно?

Решение

There are 2 ways you can avoid such cases, 1. Use Try Catch block Reference msdn

try{ Get-SPOSite -Identity $siteUrl }
Catch { write-host “error in finding the site”}

2. Change the logic and use filter to handle the null variable something like this

$objSite = Get-SPOSite -Filter {Title -eq “XYZ”} 

This way if the site title is not found, you will end up with null variable rather than an powershell error message. Null variable can easily be handled with IF conditions.

Cheers! Happy to help.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top