I am using SharePoint 2016, and I have a small PowerShell Script that requires me to provide the SharePoint Site URL manually, so I need to check if the provided SharePoint Site URL already exists or not using PowerShell without raising errors.
I tried the below cmdlet to check if the SharePoint site exists
Get-SPWeb -Identity $url | Select-Object -Property Exists
but I got this error if the provided SharePoint URL is not valid or the SharePoint site is not exists
Get-SPWeb : Cannot find an SPSite object that contains the following Id or Url: http://test.
At line:1 char:1
+ Get-SPWeb -Identity $url | Select-Object -Property Exists
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletPip
eBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb
How can I ensure that the provided SharePoint Site URL is a valid URL and the SharePoint site exists using PowerShell without showing this error if the SharePoint URL was not found or incorrect?