Showing category results for PowerTip

Feb 18, 2016
Post comments count0
Post likes count0

PowerTip: Count backwards in array

Doctor Scripto
Doctor Scripto

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to count backwards in a Windows PowerShell array.  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?  Use negative numbers, for example: $Array = @('first','second','third') $Array[0...

Scripting Guy!Windows PowerShellPowerTip
Feb 17, 2016
Post comments count0
Post likes count0

PowerTip: Prompt user for value but provide default

Doctor Scripto
Doctor Scripto

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to set a variable to a default value in PowerShell.  How can I use Windows PowerShell to prompt a user for a value for a variable, but provide a default value if the user doesn’t enter anything?  First prompt the user for the value to the variable and then detect if the respo...

Scripting Guy!Windows PowerShellPowerTip
Feb 16, 2016
Post comments count0
Post likes count0

PowerTip: Use positional parameters

Doctor Scripto
Doctor Scripto

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to use positional parameters in Windows PowerShell.  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 –destination $destination...

Scripting Guy!Windows PowerShellPowerTip
Feb 15, 2016
Post comments count0
Post likes count0

PowerTip: Send output to file and screen at the same time

Doctor Scripto
Doctor Scripto

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to easily send data to the output of a script.  How can I use Windows PowerShell to send the same data that I’m writing to a file to the standard output of my script?  In Windows PowerShell 5.0, use Tee-Object, for example: PS C:\WINDOWS\system32> Tee-Object -InputObject '...

Scripting Guy!Windows PowerShellPowerTip
Feb 14, 2016
Post comments count1
Post likes count0

PowerTip: Use PowerShell to add exclusion folder to Windows Defender

Doctor Scripto
Doctor Scripto

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

Scripting Guy!Windows PowerShellPowerTip