How to pass a custom function inside a ForEach-Object -Parallel

The solution isn’t quite as straightforward as one would hope: # Sample custom function. function Get-Custom { Param ($A) “[$A]” } # Get the function’s definition *as a string* $funcDef = ${function:Get-Custom}.ToString() “Apple”, “Banana”, “Grape” | ForEach-Object -Parallel { # Define the function inside this thread… ${function:Get-Custom} = $using:funcDef # … and call it. Get-Custom … Read more

How to automate either PowerShell or PowerShell Core for same machine

Here’s an overview of the PowerShell SDK-related NuGet packages:Adapted from here. Note: System.Management.Automation is not recommended for direct use. To create stand-alone applications that host the PowerShell runtime in order to call PowerShell commands in-process: Use Microsoft.PowerShell.5.ReferenceAssemblies for .NET Framework (Windows-only) applications using the legacy Windows PowerShell runtime. Use Microsoft.PowerShell.SDK for (potentially cross-platform) .NET Core … Read more

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