A collection of common Powershell commands that I frequently use.
Write to the console with:
Write-Host "My message"
To execute scripts in a powershell console, use:
Set-ExecutionPolicy -Scope CurrentUser Bypass
To do a simple find and replace in a file, use:
(Get-Content [filename] -encoding UTF8) | foreach-object {
$_ -replace "[text-to-replace]", "[replacemet-text]"
} | Set-Content [filename] -encoding UTF8
Note: the brackets around
Get-Content
are important here, because they cause powershell to read the entire file out first, before starting to write it again.
[xml]$xmlFile = Get-Content -Path $xmlFilePath