Powershell Best Practice #15: Execute scripts with -NoProfile parameter

By | July 26, 2015

Best Practice: It is recommended to use -NoProfile parameter when executing scripts.

powershell.exe -NoProfile File "C:\scripts\Get-DiskSpace.ps1"

Explanation:

When you run a script via scheduled task or via a shortcut, PowerShell will first load profiles and then run the script.

You never know what contains these profiles, so it can be dangerous and you can have unexpected behaviors.

NoProfile : Does not load the Windows PowerShell profile.

Note: To see all the available parameters : powershell.exe /?


previous-buttonnext-button

Leave a Reply

Your email address will not be published.