PowerShell – Get WebAdministration

|

If you are on a newly installed server and trying any of the IIS PowerShell scripts on this site that call “Import WebAdministration” you may have some issues if the “WindowsPowerShellWebAccess” feature isn’t installed, this script below should help.

clear

try
	{
		$ImportSucceeded = import-module WebAdministration -ErrorAction Stop
	}
catch
	{
		Write-Output "Unable to Import"

		try
			{
				$AddSucceeded = add-pssnapin WebAdministration -ErrorAction Stop
			}
		catch
			{
				Write-Output "Unable to Add PS Snapin"
				try
					{
						$AddFeatureSucceeded =  Add-WindowsFeature WindowsPowerShellWebAccess -ErrorAction Stop
					}
				catch
					{
						Write-Output "Unable to Add PS Feature"
						Write-Output $PSVersionTable
					}
			}

		# Break
	}
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.