cheatsheet-powershell
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| cheatsheet-powershell [2025/06/01 11:59] – created - external edit 127.0.0.1 | cheatsheet-powershell [2025/11/19 20:07] (current) – sjoerd | ||
|---|---|---|---|
| Line 107: | Line 107: | ||
| [datetime]$endDate = (Get-Date).AddDays(+90) | [datetime]$endDate = (Get-Date).AddDays(+90) | ||
| [datetime]$endDate = (Get-Date).AddDays(-90) | [datetime]$endDate = (Get-Date).AddDays(-90) | ||
| + | </ | ||
| + | |||
| + | == PowerShell Measure Command Time == | ||
| + | |||
| + | Sometimes it's useful to measure how long a command takes. I create the snippet below to measure the amount of time a Test-NetConnection commando took and used it to replicate a sort of ping utility. | ||
| + | |||
| + | <code powershell> | ||
| + | $counter = 0 | ||
| + | while ($true){ | ||
| + | $timer = [Diagnostics.Stopwatch]:: | ||
| + | Test-NetConnection kv-shift-001.privatelink.vaultcore.azure.net -port 443 -InformationLevel Quiet | ||
| + | $timer.Stop() | ||
| + | $elapsed = $timer.elapsed | ||
| + | $counter ++ | ||
| + | Write-Host " | ||
| + | Sleep 1 | ||
| + | } | ||
| </ | </ | ||
| Line 299: | Line 316: | ||
| $user = ${env: | $user = ${env: | ||
| </ | </ | ||
| + | \\ | ||
| + | > Check if a variable is null or empty | ||
| + | <code powershell> | ||
| + | if ([string]:: | ||
| + | do something | ||
| + | } | ||
| + | </ | ||
| == Remote PowerShell == | == Remote PowerShell == | ||
| Line 600: | Line 623: | ||
| ((Invoke-AzRestMethod -Path "/ | ((Invoke-AzRestMethod -Path "/ | ||
| </ | </ | ||
| + | |||
| + | == PowerShell Commandlets == | ||
| + | |||
| + | > New-Guid | ||
| + | <code powershell> | ||
| + | # Create a new guid and expected output | ||
| + | New-Guid | ||
| + | |||
| + | Guid | ||
| + | ---- | ||
| + | |||
| + | 2bc75dce-01e6-4f8b-ae06-3fc6c6657dac | ||
| + | </ | ||
| + | |||
| + | //This wiki has been made possible by:// | ||
| + | |||
| + | < | ||
| + | <script async src=" | ||
| + | | ||
| + | <!-- Wiki End of Page --> | ||
| + | <ins class=" | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | < | ||
| + | | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | |||
cheatsheet-powershell.1748779162.txt.gz · Last modified: by 127.0.0.1
