3 ms·
Yes, all Powershell objects can be cast to string ($strvar = [string]$var) or piped to Out-String.
by pzone 10y ago
Yes, all Powershell objects can be cast to string ($strvar = [string]$var) or piped to Out-String.
- milesrout 10y agoBut 'casting to string' isn't very specific. Does casting to string mean that you always get a unique identifier for the object? Does it mean you always get a dump of the object's contents?
- pjc50 10y agoYou get a printout of the object - effectively calling its toString() method. Note that this is not a reversible nor standard process. That's one of the main downsides of object-pipeline systems; in UNIX you can stop and serialise a pipeline to a file, then unserialise later. But you can't do this with object pipelines in Powershell because the objects have to be "live".