Hi,
A quick question for you experts.
If I have an object with multiple properties, and I put that object into a variable, I can’t always reuse a single property of the object using this format $variable.property
Using $variable.property in a path for example results in the object type being used, rather than the property value. I’ve come across this problem in few different scenarios, I’ve copied in an example below. I’ve tried different combinations of double and single quotes, brackets etc, but the only way I can get it to work is by creating a new variable (as shown below).
Is there a way to use $variable.property rather than making a new variable each time?
PS D:\scripts\modules> get-item IIS:\AppPools\* | select -First 1
Name State Applications
---- ----- ------------
.NET v2.0 Started
PS D:\scripts\modules> $pool = get-item IIS:\AppPools\* | select -First 1
PS D:\scripts\modules> $pool.name
.NET v2.0
PS D:\scripts\modules> Get-ItemProperty IIS:\AppPools\$pool.name
Get-ItemProperty : Cannot find path 'IIS:\AppPools\Microsoft.IIs.PowerShell.Framework.ConfigurationElement.name' because it does not
exist.
At line:1 char:1
+ Get-ItemProperty IIS:\AppPools\$pool.name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (IIS:\AppPools\M...ionElement.name:String) [Get-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
PS D:\scripts\modules> $name = $pool.name
PS D:\scripts\modules> Get-ItemProperty IIS:\AppPools\$name
Name State Applications
---- ----- ------------
.NET v2.0 Started