Thursday, January 6, 2011

PowerShell | Starting running scripts

For first steps,
- Install / make sure PS is installed
- Run PS command-line with admin privileges
- Run "Set-ExecutionPolicy Unrestricted" to enable the system to run scripts

"By default, PowerShell has scripting support disabled. If you try and run a PowerShell script, you will be greeted with an error stating that the execution of scripts is disabled on your system."

This is usually needed when running scripts for the first time. System presents us with errors such as:
File C:\Common\Scripts\hello.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

Update: Output of "help set-executionpolicy -detail" command

    Changes the user preference for the Windows PowerShell execution policy.

    Set-ExecutionPolicy [-ExecutionPolicy] {Unrestricted | RemoteSigned | AllSigned | Restricted | Default | Bypass | Undefined} [[-Scope] {Process | CurrentUser | LocalMachine | UserPolicy | MachinePolicy}] [-Force] [-Confirm] [-WhatIf] []

    The Set-ExecutionPolicy changes the user preference for the Windows PowerShell execution policy.

    To run this command on Windows Vista, Windows Server 2008, and later versions of Windows, you must start Windows PowerShell with the "Run as administrator" option, even if you are a member of the Administrators group on the computer.

    The execution policy is part of the security strategy of Windows PowerShell. It determines whether you can load configuration files (including your Windows PowerShell profile) and run scripts, and it determines which scripts, if any, must be digitally signed before they will run.

    For more information, see about_Execution_Policies.

    -ExecutionPolicy Specifies a new execution policy for the shell. The parameter name ("Name") is optional.

        Valid values are:

        -- Restricted: Does not load configuration files or run scripts. "Restricted" is the default.

        -- AllSigned: Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.

        -- RemoteSigned: Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.

        -- Unrestricted: Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.

        -- Bypass: Nothing is blocked and there are no warnings or prompts.

        -- Undefined: Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.

    -Force []
        Suppresses all prompts. By default, Set-ExecutionPolicy displays a warning whenever you change the execution policy.

        Specifies the scope of the execution policy. The default is LocalMachine.

        Valid values are:

        -- Process: The execution policy affects only the current Windows PowerShell process.
        -- CurrentUser: The execution policy affects only the current user.
        -- LocalMachine: The execution policy affects all users of the computer.

        To remove an execution policy from a particular scope, set the execution policy for that scope to Undefined.

    -Confirm []
        Prompts you for confirmation before executing the command.

    -WhatIf []
        Describes what would happen if you executed the command without actually executing the command.

        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        "get-help about_commonparameters".

No comments:

Post a Comment