Extract private key from pfx file or certificate store WITHOUT using OpenSSL on Windows

I had the same problem and solved it with the help of PSPKI Powershell module from PS Gallery. While I understand that you look for a solution that preferably uses some built in functionality in Windows, installing a module from PS Gallery might be acceptable. At least it was in my case. First install the … Read more

PowerShell Add-WindowsFeature unrecognized

This is probably because the PowerShell script is being launched from a 32 bit instance of PowerShell. The ServerManager commands are only available from 64 bit version of PowerShell. See: Can’t access ServerManager module via PowerShell –Edit – To add to jbsmith’s comments— Extra things to try: When you ran the Get-Command cmdlt: gcm | … Read more

On Windows what is the difference between Git Bash vs Windows Power Shell vs Command prompt

Git bash is bash, which is IIRC also the default shell on MacOS. It is not the default shell on Windows, although several implementations exist (CygWin, MinGW, …). Git is bundled with a number of POSIX (UNIX/Linux/etc.) utilities in addition to bash; in order to avoid “collisions” with similarly named Windows commands, the most common … Read more

Get target of shortcut (.lnk) file with powershell

You have made an error in the property; as wOxxOm suggests, you should be using TargetPath rather than Target: $sh = New-Object -ComObject WScript.Shell $target = $sh.CreateShortcut(‘<full-path-to-shortcut>’).TargetPath Google and MSDN were indeed helpful here; additionally, piping objects to Get-Member can often be useful and educational. This question also shows how to manipulate shortcuts using PowerShell, … Read more

Powershell: Get-Item vs Get-ChildItem

Get-Item Gets the item at the specified location. Get-Item .\foo # returns the item foo Get-ChildItem Gets the items and child items in one or more specified locations. Get-ChildItem .\foo # returns all of the children within foo note: Get-ChildItem can also recurse into the child directories Get-ChildItem .\foo -Recurse # returns all of the … Read more

How can I start a background job in Powershell that outlives it’s parent?

If you use Start-Process, you create a new child process that has your powershell session as its parent process. If you kill the powershell parent process that starts this, the new process will be orphaned and keep running. It will, however, not survive if you kill the parent’s process tree Start-Process -FilePath notepad.exe Powershell cannot … Read more

Why are all newlines gone after PowerShell’s Get-Content, Regex, and Set-Content?

For the $replacement variable, you don’t really need to specify the type [string], PowerShell will infer that from the assignment. For the $template variable, [string] is actually wrong. By default, Get-Content will give you an array of strings (i.e. lines) instead of one string. But in fact you don’t even want to split the input … Read more

Remove alias in script

The following seems to work If (Test-Path Alias:wget) {Remove-Item Alias:wget} If (Test-Path Alias:wget) {Remove-Item Alias:wget} wget The first line removes the Script level alias, and the second removes the Global level alias. Note that both need to be tested, because if the Global doesn’t exist the Script isn’t created. Also this misbehaves in that it … Read more