What does this line of Powershell do?
I am new to PowerShell and don't know what the first line does exactly.
PowerShell was designed to be more secure than batch. Therefore, by default, running PowerShell scripts is limited by Windows. It's dangerous to allow script execution if that (perhaps unauthorized) script is downloading malicious software or creating other security holes.
In the case of the first line, the Execution Policy (limits placed on the script) are being set so that scripts created locally will run without problems, but scripts fetched from another computer (e.g. the internet) as determined by Windows, have additional restrictions placed on them.
Is it needed if the script is run locally on a Windows 10 PC?
As far as I am aware, no new installation of (non-Server) Windows allows PowerShell scripts to be run automatically -- an Execution Policy needs to be set to allow scripts to run (though non-Windows computers have their execution policies set to Unrestricted
as of PowerShell 6.0+, apparently). However, this does not necessarily need to be done for every script. That is, you can change these settings once from the command line rather than on a per-script basis.
I found this, but don't fully understand if it is applicable to my case since it mentions "for Windows server computers."
It is stating that RemoteSigned
is the default Execution Policy for PowerShell on Windows Server, as opposed to Undefined
(I believe) for non-Server versions of Windows -- not that it applies to Window Server only.
The official documentation for the Set-Execution
cmdlet can be found here.