r/PowerShell • u/[deleted] • Jul 05 '17
Supercharge your PowerShell scripts with these five easy tips.
I am writing this from my phone, so Google is your friend here when looking for examples on how to quickly implement these. If enough folks are drawing a blank I will update this post with examples for each.
1: Replace Get-Content and Import-CSV with .NET's StreamReader.
Examples:
http://www.happysysadm.com/2014/10/reading-large-text-files-with-powershell.html?m=1
2: Replace Out-File and Export-CSV with .NET's StreamWriter.
Examples:
3: Replace Compare-Object with the Match operator using the GetHashCode() method for strings being compared, or for a RegEx generated at runtime.
Examples:
https://blogs.technet.microsoft.com/heyscriptingguy/2015/04/01/use-powershell-to-compare-two-files/
4: Replace Get-AD* with ADFind from JoeWare.NET.
Examples:
http://powershell-guru.com/fastest-powershell-1-count-all-users-active-directory/
5: Replace Set-AD* with ADMod from JoeWare.NET.
EDIT: Yay, downvotes because knowledge is power and power is bad.
1
u/[deleted] Jul 05 '17
Culture does matter, but when I am comparing long Unicode strings and doing 100k comparisons, the difference is staggering. From thirty minutes to thirty seconds.