Skip to content

Instantly share code, notes, and snippets.

@djahren
Created April 10, 2021 21:40
Show Gist options
  • Save djahren/ef3108a7ecfb2512641f59a0aa905fba to your computer and use it in GitHub Desktop.
Save djahren/ef3108a7ecfb2512641f59a0aa905fba to your computer and use it in GitHub Desktop.
Frequently Used PowerShell Snippets
#These are just a few PowerShell snippets I've written that I find myself coming back to time and time again. I hope they can help you too.
#Export To CSV $ReportsDir defined in my $profile file.
| Export-CSV (Join-Path $ReportsDir ".csv") -NoTypeInformation
#Before Loop - fill out activity and replace $Array with iterable varible.
$Activity = ""; $Total = $Array.Count;
$StartTime = Get-Date; $Count = 1;
#In Loop - replace -CurrentOperation
$ElapsedSeconds = (New-TimeSpan -Start $StartTime -End (Get-Date)).TotalSeconds; $SecondsPerOp = $ElapsedSeconds/$Count;
Write-Progress -Activity $Activity -CurrentOperation "" -PercentComplete (($Count/$Total) * 100) -SecondsRemaining ($SecondsPerOp * ($Total - $Count))
$Count++
#After Loop
Write-Progress -Activity $Activity -Completed $true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment