2
votes

On server 2008 R2 Standard within Powershell. I am trying to run a script that uses Get-WebBinding

try{
Import-Module WebAdministration
Get-WebApplication

$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}

$item.WebAppName = $webapp.name
$item.Version = (Get-ItemProperty $name managedRuntimeVersion).Value
$item.State = (Get-WebAppPoolState -Name $webapp.name).Value
$item.UserIdentityType = $webapp.processModel.identityType
$item.Username = $webapp.processModel.userName
$item.Password = $webapp.processModel.password

$obj = New-Object PSObject -Property $item
$list += $obj
}

$list | Format-Table -a -Property "WebAppName", "Version", "State", "UserIdentityType", "Username", "Password" | Out-String

}catch
{
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
$ExceptionMessage
}

however, I am getting the following error:

The term 'Get-WebBinding' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:25 char:15 + Get-WebBinding <<<< | % { + CategoryInfo : ObjectNotFound: (Get-WebBinding:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

I tried to add the snapin and got this error:

PS C:\Windows\system32> add-pssnapin WebAdministration Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2. At line:1 char:13 + add-pssnapin <<<< WebAdministration + CategoryInfo : InvalidArgument: (WebAdministration:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

And per this article https://community.spiceworks.com/topic/370385-powershell-commands-to-export-iis7-sites-binding-information: since I am using iis 7, I tried to get the powershell extensions. I went to the iis.net link ( https://www.iis.net/downloads/microsoft/powershell ) and couldn't find the download. The button just takes you to a gallery search.

There is a button to install the extension but it doesn't pull up the installer.

1
Im guessing you need PS version higher than what you have (hmmm that does not seem right). Looking to find the min version you need. 08r2 have 2.0 by default I think. Is the snapin you got for x86 or x64 and which shell are you running. - Matt
I think i found the download for the extensions. microsoft.com/en-us/download/details.aspx?id=15488 However, when I run it, it says "Powershell snap-in' is part of Windows Operating System." I go into server roles and I have "Web Server (IIS)" Under web server role features I do have "IIS Management Scripts and Tools (Installed)" - JDPeckham
@Matt - I have version 2 on another 2008R2 std server and the script ran fine. I now have 2 servers that this won't run on and 1 that did run. OH i figured it out. They had Execution Policy of restricted. I'll update the answer for this. Thanks! - JDPeckham
PS (not pun intended) is it just me or is it terrible that the passwords are in reversible encryption? - JDPeckham

1 Answers

2
votes

Set-ExecutionPolicy RemoteSigned then restarting Powershell has resolved my issue.