Created
April 10, 2021 21:40
-
-
Save djahren/ef3108a7ecfb2512641f59a0aa905fba to your computer and use it in GitHub Desktop.
Frequently Used PowerShell Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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