Saturday, March 5, 2011

Check if Web Application exists using PowerShell in SharePoint

To check if a web application exists in SharePoint environment using PowerShell, use this script.

Add-PsSnapin Microsoft.SharePoint.PowerShell

[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

$WebAppName = "IntranetPortal80"
$sp = Get-SPWebApplication | Where {$_.DisplayName -eq $WebAppName}
if($sp -eq $null)
{

        Write-host "Null"
}
else
{
        write-host "No Null"
}

In, if-else block do what you want to do.

1 comment:

  1. Nice script, I just need it for automatic deployment!

    Thanks for your effort.

    Best Regards,
    Mark

    ReplyDelete