Fork me on GitHub

This is the list of commandlets for standard Windows automation.

Users

New-LocalUser

Description

Creates a new local user.

Parameters

Name Type Required Description Example
Name string Name of the user to create Bob
Password string Associated password Password1

Code sample

New-LocalUser -Name "Bob" -Password "Password1"

Remove-LocalUser

Description

Deletes an existing local user.

Parameters

Name Type Required Description Example
Name string Name of the user to delete Bob

Code sample

Delete-LocalUser -Name "Bob"

Groups

Add-UserToGroup

Description

Adds the specified user to a group.
Note: both the user and group have to exist.

Parameters

Name Type Required Description Example
Username string Name of the user to add Bob or Domain/Bob
Group string Group to add the user to IIS_WPG

Code sample

Add-UserToGroup -Username "Bob" -Group "IIS_WPG"

Remove-UserFromGroup

Description

Removes the specified user from a group.

Parameters

Name Type Required Description Example
Username string Name of the target user Bill or Domain/Bill
Group string Group to remove the user from IIS_WPG

Code sample

Remove-UserFromGroup -Name "Bob" -Group "IIS_WPG"

Permissions

Set-FolderPermissions

Description

Sets user access permissions on a given folder.

Parameters

Name Type Required Description Example
Path string Target folder C:\My\Folder
Username string User to give permissions to Bill
Permission FileSystemRights Type of access to grant/revoke Read
Modifier AccessControlType New access value Allow

Code sample

Set-FolderPermissions -Path "C:\My\Folder" -Username "Bob" -Permission "Write" -Modifier "Allow"

Shares

Get-SharedFolders

Description

Gets the list of all shared folders on the computer.

Parameters

Name Type Required Description Example
MachineName string Target machine ComputerName

Code sample

Get-SharedFolders

New-SharedFolder

Description

Creates a new share.

Parameters

Name Type Required Description Example
Path string Path to an existing folder C:\Path\To\Folder
Name string Name of the share Public
Type int Share type 0
MaxConnectionsAllowed int Maximum number of concurrent connections 25
Description string Share description Public shares
Password string Share password P@ssw0rd
Access Win32_SecurityDescriptor Access restrictions

Code sample

New-SharedFolder -Path "C:\Public" -Name "Public"

Remove-SharedFolder

Description

Removes the shared status of a folder.

Parameters

Name Type Required Description Example
Name string Name of the share to remove Public

Code sample

Remove-SharedFolder -Name "Public"

Scheduled tasks

Get-ScheduledTask

Description

Find the scheduled task with the given name, and returns a full object if it exists.

Parameters

Name Type Required Description Example
Name string Task name MyTask

Code sample

$task = Get-ScheduledTask -Name "MyTask"
Write-Host $task.TaskName

Start-ScheduledTask

Description

Runs an existing scheduled task.

Parameters

Name Type Required Description Example
Name string Task name MyTask

Code sample

Start-ScheduledTask -Name "MyTask"

Enable-ScheduledTask

Description

Enables an existing scheduled task.

Parameters

Name Type Required Description Example
Name string Task name MyTask

Code sample

Enable-ScheduledTask -Name "MyTask"

Disable-ScheduledTask

Description

Disable an existing scheduled task.

Parameters

Name Type Required Description Example
Name string Task name MyTask

Code sample

Disable-ScheduledTask -Name "MyTask"

New-ScheduledTask

Description

Creates a new scheduled task.
Please refer to the code sample for the different schedule types.

Parameters

Name Type Required Description Example
Name string Task name MyTask
Path string Path to the program to run MyTask
User string Username to run the task under MyTask
Password string Corresponding password MyTask
AtStartup switch Run the task when the computer starts
WhenIdleFor int Run the task when the computer has been idle for N minutes 10 (minutes)
OnceOnThe DateTime Run the task once on a specific date "04-17-2010"(regional format depends on the computer)
Every int Run the task on a schedule
Minute(s) switch Run it every N minutes 2
Hour(s) switch Run it every N hours 2
Day(s) switch Run it every N days 2
Week(s) switch Run it every N weeks 2
Month(s) switch Run it every N months 2
On string Run it on specific days "Mon,Tue" (list of days)
In string Run it on specific months "Jan,Feb,Mar" (list of months)
At DateTime Time to run the task 6pm or 18:00 (24 hour clock)
OnThe int Day number on which to run the task (in month mode) 17
OnTheFirst string Run the task on the first day of the month "Mon" (first 3 letters)
OnTheLast string Run the task on the last day of the month "Mon" (first 3 letters)

Code sample

#The basic creation parameters are:
New-ScheduledTask -Name "MyTask" -Path "C:\Path\To.exe" -User "Username" -Password "Pass"

#They should be followed by one of the following schedule types:
-AtStartup
-WhenIdleFor 10
-OnceOnThe "17-04-2010"
-Every 1 -Minute
-Every 5 -Minutes
-Every 2 -Hours
-Every 10 -Days -At 9pm
-Every 2 -Weeks -On "Mon,Wed,Fri" -At 6pm
-Every 3 -Months -OnThe 17 -At 4am
-Every 1 -Month -In "Jan,Feb,Mar" -OnThe 17 -At 11pm
-Every 1 -Month -OnTheLast "Wed" -At 2am

Remove-ScheduledTask

Description

Deletes an existing scheduled task.

Parameters

Name Type Required Description Example
Name string Name of the task to delete MyTask

Code sample

Remove-ScheduledTask -Name "MyTask"

Network

New-NetworkDrive

Description

Mounts a new network drive from a UNC path.

Parameters

Name Type Required Description Example
UncPath string Path to mount \\Server\Folder
DriveLetter string Letter to mount the path under L

Code sample

New-NetworkDrive -UncPath "\\Server\Folder" -DriveLetter "L"

Services

Find-Service

Description

Returns a boolean indicating if the specified Windows service exists.
You can use this instead of Get-Service which returns an error message when the service does not exist.

Parameters

Name Type Required Description Example
Name string Name of the service to query MyService

Code sample

Find-Service -Name "MyService"

Set-ServiceCredentials

Description

Updates the user under which an existing service runs.

Parameters

Name Type Required Description Example
Name string Name of the target service MyService
Username string Fully qualified username to run under CORP\Bob
Password string Corresponding password Password1

Code sample

Set-ServiceCredentials -Name "MyService" -Username "CORP\Bob" -Password "Password1"

Update-Service

Description

Updates an existing service with the new version of its executable.
This will stop the service, copy the new version where the service reside, and restart the service.

Parameters

Name Type Required Description Example
Name string Name of the service to update MyService
NewVersionPath string Path to the new executable or folder C:\Builds\ServiceX\Version2

Code sample

Update-Service -Name "MyService" -NewVersionPath "C:\Builds\ServiceX\AFewFiles"
Update-Service -Name "MyService" -NewVersionPath "C:\Builds\ServiceY\JustAnExe.exe"