How to serialize/deserialize data back and forth between Windows PowerShell and PowerShell core?

Advertisements I’ve been trying to find a solution to work with a specific cmdlet from ConfigCi built-in module that is incompatible with PowerShell core. The cmdlet is New-CIPolicyRule I want to use it in my module that targets PowerShell 7.3+. Here is the command that fails in PowerShell core but works in Windows PowerShell 5.1… Read More How to serialize/deserialize data back and forth between Windows PowerShell and PowerShell core?

How to have index variable increase in ForEach-Object?

Advertisements I have this strange observation: I want to run an expression for as many times as there are files. Yet, the following script always executes only once, no matter how many files are found by Get-ChildItem: (Get-ChildItem -Filter ‘*.png’), (Get-ChildItem -Filter ‘*.jpg’) | Sort-Object -Property ‘Name’ | ForEach-Object -Begin { $idx = 0 }… Read More How to have index variable increase in ForEach-Object?

PowerShell – How can I use regex in the middle of registry file path to perform remove-item operation?

Advertisements I’ve looked at many similar questions and tried lots of things, but I can’t make it work. $Regex = ‘RegexPattern’ Remove-Item -Path ‘HKCU:System\somePath\’ + $Regex + ‘\MorePath\*’ -Recurse Remove-Item -Path "HKCU:System\somePath\$Regex\MorePath\*" -Recurse Remove-Item -Path "HKCU:System\somePath\$($Regex)\MorePath\*" -Recurse Remove-Item -Path "HKCU:System\somePath\’RegexPattern’\MorePath\*" -Recurse Remove-Item -Path ‘HKCU:System\somePath\"RegexPattern"\MorePath\*’ -Recurse None of those work. I have a regex, want to… Read More PowerShell – How can I use regex in the middle of registry file path to perform remove-item operation?

How to show all the available options for a PowerShell command?

Advertisements For example, this command: get-netadapter -name "WI-FI" shows my WIFI network adapter’s details with 5 columns of information about it. but if i do this: (get-netadapter -name "WI-FI"). and then press tab, I can see a whole lot more information about it that show up after the dot. now this is only a simple… Read More How to show all the available options for a PowerShell command?