Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 4

A huge advantage to PowerShell is that as well as being able to run commands on the local

computer, it has a range of commands that can perform actions on remote computers:

Get-Eventlog
Get-Process
Start-Process
Stop-Process
Get-ACL
Set-ACL
Restart-Computer
Stop-Computer

You can even use PowerShell to connect to another computer, and then run whatever
commands you want on it. This is known as PowerShell remoting.

Enter-PSSession -ComputerName RemoteServer -Port 5353 -Credential Domain\Username


PowerShell scripts are restricted on Windows operating systems, by default. This is a
security measure. You have to change the policy before you can run any Powershell
scripts. Typically these are saved with the extension .PS1, e.g. script.PS1

To view the current PowerShell security policy:


Get-ExecutionPolicy

Possible results are:


• Restricted - No scripts can be run. Windows PowerShell can be used only in interactive
mode.
• AllSigned - Only scripts signed by a trusted publisher can be run.
• RemoteSigned - Downloaded scripts must be signed by a trusted publisher before
they can be run.
• Unrestricted - No restrictions; all Windows PowerShell scripts can be run.

To allow all scripts to run:


Set-ExecutionPolicy Unrestricted
Scenario: Fullname Username Password
Your company wants a way to automate Mike Tyson mtyson KOmofo123
creation of new local user accounts in bulk,
rather than creating them manually. You
Connor cmgreggor ZoomInFU123
need to create a PowerShell script to do
McGreggor
this. Sample user accounts for testing are Alice Glass aglass DeathRay666
listed on the right.
A partial script has already been created, which reads the information from a CSV file. Can you finish the
script by adding in the New-LocalUser PowerShell command?

ForEach ($user in (Import-CSV "C:\users\learner\desktop\users.csv")) {


Write-Host Creating account $user.username for $user.fullname with password $user.password
  $user.password = ConvertTo-SecureString -String $user.password -AsPlainText –Force

}
Scenario: Fullname Username Password
Your company wants a way to automate Mike Tyson mtyson KOmofo123
creation of new local user accounts in bulk,
rather than creating them manually. You
Connor cmgreggor ZoomInFU123
need to create a PowerShell script to do
McGreggor
this. Sample user accounts for testing are Alice Glass aglass DeathRay666
listed on the right.
A partial script has already been created, which reads the information from a CSV file. Can you finish the
script by adding in the New-LocalUser PowerShell command?

ForEach ($user in (Import-CSV "C:\users\administrator\desktop\users.csv")) {


Write-Host Creating account $user.username for $user.fullname with password $user.password
  $user.password = ConvertTo-SecureString -String $user.password -AsPlainText –Force
New-LocalUser -Name $user.username -FullName $user.fullname -Password $user.password
Add-LocalGroupMember -Group "Users" -Member $user.username
}

You might also like