Skip to content

Instantly share code, notes, and snippets.

@greglecki
Last active September 28, 2020 14:14
Show Gist options
  • Select an option

  • Save greglecki/c823370ee83f1e137c66340fc0537d97 to your computer and use it in GitHub Desktop.

Select an option

Save greglecki/c823370ee83f1e137c66340fc0537d97 to your computer and use it in GitHub Desktop.
Running scripts in PowerShell

View Execution Policy

Get-ExecutionPolicy

Edit Execution Policy

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Comments

'#'

Multi line comment

<# ... #>

Get user input and save it in variable

$ComputerName = Read-Host "Enter Computer name"

Defining parameter

Param ( [Parameter(Mandatory=$true)] [string[]] #Additional [] after string denotes this parameter accepts multiple inputs $Computername #Parameter name )

Foreach loop

Foreach ($target in $Computername) { }

If-Else condition

If ($ServiceStatus -eq 'Running') { } Else { }

Stub for new script - used by help

<#

.Synopsis

Short description

.DESCRIPTION

Long description

.EXAMPLE

Example of how to use this cmdlet

.EXAMPLE

Another example of how to use this cmdlet

#>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment