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

Powershell – Set SSL Certificate on https Binding

You have to assign the certifcate to a specific site. You can retrieve the binding information of your site using the Get-WebBinding cmdlet and set the SSL Certificate using the AddSslCertificate function: $siteName=”mywebsite” $dnsName=”www.mywebsite.ru” # create the ssl certificate $newCert = New-SelfSignedCertificate -DnsName $dnsName -CertStoreLocation cert:\LocalMachine\My # get the web binding of the site $binding … Read more