What Library for Powershell 6 contains the get-wmiobject command?

Gert Jan Kraaijeveld’s helpful answer offers a solution for cmdlets that truly are available only in Windows PowerShell (not also in PowerShell [Core] 6+). In this particular case, however, as Lee_Daily notes in a comment, you can use the Get-CimInstance cmdlet, which is available in PowerShell [Core] 6+ too: Get-CimInstance CIM_Product | Select-Object Name, PackageCache … Read more

How do I write the value of a single property of a object?

qbanet359’s helpful answer uses direct property access (.LoadPercentage) on the result object, which is the simplest and most efficient solution in this case. In PowerShell v3 or higher this even works with extracting property values from a collection of objects, via a feature called member-access enumeration. E.g., ((Get-Date), (Get-Date).AddYears(-1)).Year returns 2019 and 2018 when run … Read more

pwsh -Command is removing quotation marks

Unfortunately, PowerShell’s handling of passing arguments with embedded ” chars. to external programs – which includes PowerShell’s own CLI (pwsh) – is fundamentally broken (and always has been), up to at least PowerShell 7.2.2: You need to manually \-escape ” instances embedded in your arguments in order for them to be correctly passed through to … Read more

PowerShell output is crossing between functions

tl; dr: Force synchronous output to the console with Out-Host: getUsersAndGroups | Out-Host getRunningProcesses | Out-Host Note: You can alternatively use one of the Format-* cmdlets, which also forces synchronous output; e.g., getUsersAndGroups | Format-Table. Inside a PowerShell session: This is primarily a display problem, and you do not need this workaround for capturing output … Read more

How do I pass a local variable to a remote `Invoke-Command`? [duplicate]

In PowerShell 4 (3+ actually) the easiest way is to use the Using scope modifier: Invoke-Command -ComputerName winserver -ScriptBlock { Get-FileHash E:\test\$Using:dest.zip -Algorithm SHA1 } For a solution that works with all versions: Invoke-Command -ComputerName winserver -ScriptBlock { param($myDest) Get-FileHash E:\test\$myDest.zip -Algorithm SHA1 } -ArgumentList $dest

Create objects with custom properties containing derived filesystem path information and export them to a CSV – calculated properties

The [System.IO.FileInfo] instances returned by Get-ChildItem for files do not have Folder or FolderName properties. Get-ChildItem -File $HOME\Desktop | Get-Member, for instance, will show you the available properties, and will show you that the desired information can be derived from the PSPath and PSParentPath properties. Select-Object allows hashtable-based property definitions, so-called calculated properties, which allow … Read more