My thoughts on using sub-expressions to access object properties.

$serviceObj = Get-Service "wmi*"
Write-Output "Service Status $serviceObj.status"

Service Status System.ServiceProcess.ServiceController.status
Not really the output I was expecting.  This is where the sub-expression comes in handy!  I can use a sub-expression to extract the status property value and display without using another variable.
$serviceObj = Get-Service "wmi*"
Write-Output "Service Status $($serviceObj.status)"

Service Status Stopped
aplusd

Hello, Welcome to DevOpsUnleashed!

A blog dedicated to sharing information about DevOps. Here, you’ll find examples, tips, and tutorials on DevOps.

Feel free to share your experiences in the comments!

Blog Categories