Monday, July 28, 2014

PowerShell Oddities

On the whole I quite like working with PowerShell, but there sure are some weird quarks that you stumble upon from time to time. In general, the object passing model is pretty neat. At times it’s so much more powerful than Linux’s text passing model. However, there are times where it’s just infuriating. For example, when you so soomething like:

PS C:\Users\Swoogan> Import-Module WebAdministration
PS C:\Users\Swoogan> $apps = Get-WebApplication
PS C:\Users\Swoogan> $apps

Name             Application pool   Protocols    Physical Path
----             ----------------   ---------    -------------
WebServices      DefaultAppPool     http         C:\Temp
Admininistration DefaultAppPool     http         C:\Temp

PS C:\Users\Swoogan> $apps[0].Name
PS C:\Users\Swoogan> 

See, what it looks like you got was a collection of Web Application objects, but what you really got was a collection of XML Nodes:

PS C:\Users\Swoogan> $apps | Get-Member

   TypeName: Microsoft.IIs.PowerShell.Framework.ConfigurationElement#site#application

Name                     MemberType            Definition
----                     ----------            ----------
ClearLocalData           Method                System.Void ClearLocalData()
Copy                     Method                System.Void Copy(Microsoft.IIs.PowerShell.Framework.ConfigurationElem...
Delete                   Method                System.Void Delete()
Equals                   Method                bool Equals(System.Object obj)
GetAttribute             Method                Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute GetAttribut...
...
Schema                   Property              Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema Schema ...
PhysicalPath             ScriptProperty        System.Object PhysicalPath {get=$pquery = $this.ItemXPath + "/virtual...

Granted, this is not really an issue with PowerShell. It has more to do with the module’s authors than the system, but it’s still par for the course when using PowerShell.
Another one that’s got me a few times is this:

PS C:\Users\Swoogan> Get-ItemProperty "IIS:\AppPools\ASP.NET v4.0" -name managedPipelineMode
Integrated
PS C:\Users\Swoogan> Set-ItemProperty "IIS:\AppPools\ASP.NET v4.0" -name managedPipelineMode -value Integrated
Set-ItemProperty : Integrated is not a valid value for Int32.
At line:1 char:17
+ Set-ItemProperty <<<<  "IIS:\AppPools\ASP.NET v4.0" -name managedPipelineMode -value Integrated
    + CategoryInfo          : NotSpecified: (:) [Set-ItemProperty], Exception
    + FullyQualifiedErrorId : System.Exception,Microsoft.PowerShell.Commands.SetItemPropertyCommand

I don’t even know what to say about that!

No comments:

Post a Comment