Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

PowerTip: Count backwards in array

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to count backwards in a Windows PowerShell array. (image)  I know I can access the first, second, and third items in an array by using $Array[0], $Array[1], and $Array[2], but how can I count backwards? (image)  Use negative numbers, for example: $Array = @('first','...

PowerTip: Use positional parameters

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to use positional parameters in Windows PowerShell. (image)  I always see people pass variables or data to a function without specifying the parameter name that the data is for, for example: “copy-item $source $destination” acts like “copy-item –path $source –...

PowerTip: Use PowerShell to add exclusion folder to Windows Defender

Summary: Use Windows PowerShell to add an exclusion folder to Windows Defender. (image)  How can I add the C:\temp folder to the exclusion list so it is not scanned by Windows Defender? (image)  Use the Add-MpPreference cmdlet and specify the exclusion path, for example: Add-MpPreference -ExclusionPath "C:\Temp" Note  You must run Windows ...