Hi,
in these days of deployment, playing fun moments to learn new things. One of them, and that gave us a headache for several minutes with Javi, was in the creation of an Application Pool using PowerShell. The following code is copied 100% an IIS.NET, for the creation of an Application Pool in IIS 7.0.
1: Import-Module WebAdministration
2: $userName = "ElBruno\Valentino"
3: $password = read-host "Type user password for Application Pool for >> $userName"
4:
5: write-host "set app pool properties"
6: $appPool.processModel.userName = $userName
7: $appPool.processModel.password = $password
8: $appPool.managedRuntimeVersion = "v4.0"
9: $appPool | set-item
If you try 99 environments, will surely work correctly, however to my touched me to try it in that environment number 100 where we had a type error when assigning the Password. Researching a bit, I have seen that the class ReadHost doesn’t return a type string, but something a little "more complicated", by default the return value is assigned to aSecureStringtype. From there who at the time of assigning the Password is possible that we have wrong permissions or access.
But worry that the solution only consists of "castear" to a string value that returns ReadHost. THE following example, evidenced on line 3
1: Import-Module WebAdministration
2: $userName = "ElBruno\Valentino"
3: [string] $password = read-host "Type user password for Application Pool for >> $userName"
4:
5: write-host "set app pool properties"
6: $appPool.processModel.userName = $userName
7: $appPool.processModel.password = $password
8: $appPool.managedRuntimeVersion = "v4.0"
9: $appPool | set-item
Greetings @ La Finca
The Bruno
Reference: http://ss64.com/ps/read-host.html


Leave a comment