From wiki.adammorgan.org
Jump to: navigation, search

General Info and Getting Started

By default the "Execution Policy" is very restrictive, and you can't run your own .ps1 files (or do anything else)! To change this, open powershell and use this command. When prompted, type "Y" and hit enter.

Set-ExecutionPolicy Unrestricted
  • relax default script execution policy:
    • set-executionpolicy remotesigned

Import a module Assuming you've navigated to the folder where the .psm1 file lives:

Import-Module .\MODULE-NAME.psm1

Download modules List of popular modules: http://social.technet.microsoft.com/wiki/contents/articles/4308.popular-powershell-modules.aspx

Run a script

To run a script from the CMD shell:

powershell -file "c:\batch\demo.ps1"

To run a script file, from the Powershell console, use one of these methods:

PS C:\> & "C:\Belfry\My first Script.ps1"
PS C:\> C:\Belfry\Myscript.ps1              (if script path has no spaces)
PS C:\> .\Myscript.ps1                      (if script is in current directory)

WSUS Administration with Powershell

First Import the WSUS admin module.

  • The older version is PoshWSUS 1.1 [1]. There's a newer one that might use different commands. The following assumes you're using ver 1.1.
Import-Module .\PoshWSUS.psm1

Then connect to database

connect-wsusserver -wsusserver "MCSWSUS" -port "8530"