wiki.getshifting.com

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


cheatsheet-powershell
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
cheatsheet-powershell [2025/06/01 11:59] – created - external edit 127.0.0.1cheatsheet-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)
 +</code>
 +
 +== 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]::StartNew()
 +  Test-NetConnection kv-shift-001.privatelink.vaultcore.azure.net -port 443 -InformationLevel Quiet
 +  $timer.Stop()
 +  $elapsed = $timer.elapsed
 +  $counter ++
 +  Write-Host "Counter: $counter; in $elapsed seconds"
 +  Sleep 1
 +}
 </code> </code>
  
Line 299: Line 316:
 $user = ${env:test-app_user} $user = ${env:test-app_user}
 </code> </code>
 +\\ 
 +> Check if a variable is null or empty 
 +<code powershell> 
 +if ([string]::IsNullOrEmpty($VarToCheck)){ 
 +  do something 
 +
 +</code>
 == Remote PowerShell == == Remote PowerShell ==
  
Line 600: Line 623:
 ((Invoke-AzRestMethod -Path "/subscriptions/$subId/resourcegroups?api-version=2020-06-01&`$expand=createdTime" -Method GET).Content | ConvertFrom-Json).value | Select-Object name,createdTime ((Invoke-AzRestMethod -Path "/subscriptions/$subId/resourcegroups?api-version=2020-06-01&`$expand=createdTime" -Method GET).Content | ConvertFrom-Json).value | Select-Object name,createdTime
 </code> </code>
 +
 +== PowerShell Commandlets ==
 +
 +> New-Guid
 +<code powershell>
 +# Create a new guid and expected output
 +New-Guid
 +
 +Guid
 +----
 +
 +2bc75dce-01e6-4f8b-ae06-3fc6c6657dac
 +</code>
 +
 +//This wiki has been made possible by://
 +
 +<HTML>
 +<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8613096447910897"
 +     crossorigin="anonymous"></script>
 +<!-- Wiki End of Page -->
 +<ins class="adsbygoogle"
 +     style="display:block"
 +     data-ad-client="ca-pub-8613096447910897"
 +     data-ad-slot="6221699236"
 +     data-ad-format="auto"
 +     data-full-width-responsive="true"></ins>
 +<script>
 +     (adsbygoogle = window.adsbygoogle || []).push({});
 +</script>
 +</HTML>
 +
 +
  
cheatsheet-powershell.1748779162.txt.gz · Last modified: by 127.0.0.1