Quantcast
Viewing latest article 3
Browse Latest Browse All 6

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

@Joey has a good answer. There is another way with a more .NET look with a String.Format equivalent, I prefer it when accessing properties on objects:

Things about a car:

$properties = @{ 'color'='red'; 'type'='sedan'; 'package'='fully loaded'; }

Create an object:

$car = New-Object -typename psobject -Property $properties

Interpolate a string:

"The {0} car is a nice {1} that is {2}" -f $car.color, $car.type, $car.package

Outputs:

# The red car is a nice sedan that is fully loaded

Viewing latest article 3
Browse Latest Browse All 6

Trending Articles