문제

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