Quantcast
Channel: How can you use an object's property in a double-quoted string? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by Ramandeep Singh for How can you use an object's property in a double-quoted string?

$
0
0

If you want to use properties within quotes follow as below. You have to use $ outside of the bracket to print property.

$($variable.property)

Example:

$uninstall= Get-WmiObject -ClassName Win32_Product |    Where-Object {$_.Name -like "Google Chrome"

Output:

IdentifyingNumber : {57CF5E58-9311-303D-9241-8CB73E340963}Name              : Google ChromeVendor            : Google LLCVersion           : 95.0.4638.54Caption           : Google Chrome

If you want only name property then do as below:

"$($uninstall.name) Found and triggered uninstall"

Output:

Google Chrome Found and triggered uninstall

Viewing all articles
Browse latest Browse all 6

Trending Articles