-ErrorAction not working

Mar 7, 2015 at 3:56 PM
Edited Mar 7, 2015 at 3:57 PM
I need to check whether a mysite sitecollection exists or not.

$url = "https://company-my.sharepoint.com/personal/username_company_com"
$ctx = (Get-SPOContext $url $username $password -ErrorAction SilentlyContinue) -ne $null
Write-Host $ctx

My code return True if the mysite exist.
When the mysite not exists my code give error Message.

Any suggestion how to solve this?

Arnstein Fuglemsmo
Enable AS - http://www.enable.no
Mar 7, 2015 at 4:12 PM
Problem solved :)

$ctx = Get-SPOContext $url $username $password
catch [System.Exception]
write-host -f red "The MySite does not exists"    
Marked as answer by fugleman on 3/7/2015 at 8:12 AM