Restart
To restart computer using powershell you can use the Restart-Computer cmdlet
For restarting multiple computers using restart computer cmdlet you can specify the computer names as comma separated values:
Restart-Computer -ComputerName Computer name1", "Computer name2", "Computer name3"
Shutdown/Stop
To shutting down computer using powershell you can use the Stop-Computer cmdlet
For shutting down computers using restart computer cmdlet you can specify the computer names as comma separated values:
Stop-Computer -ComputerName "Computer name1", "Computer name2", "Computer name3"
Start Process
Start-Process cmdlet is used to start one or more processes on the local computer.
Start-Process -FilePath "executable/exe name"
Execute process as an administrator
Start-Process -FilePath "powershell" -Verb runAs
Stop Process
To stop a running process use the stop-process cmdlet along with the name or id of the process.
Stop-Process -Name "exe name"
For example to stop notepad applications use:
Stop-Process -Name "notepad"
You can verify the above command by opening an instance of notepad and executing the above command.You will see that all the instances of notepad are closed after you execute the above command.
Help
To get information about any powershell command
Get-Help -Name Command-Name
Send object to next command
Sends the objects to the next command or displays in console if this is the last command
Write-Output Object
You can use Write_Output to just print text onscreen.Following will write “hello” on the display:
Write-Output "hello"
Perform an action for every item in a collection
ForEach-Object InputObject
Following will print 1,2,3 on the console
1,2,3 | ForEach-Object -Process {Write-Output $_}
$_ represents current item.
Read contents of an item such as file
Following will read the contents of the file at the specified path:
Get-Content -Path "C:\Test.txt"
Leave a Reply