Install powershell:
- Install .Net 2.0 SP1
- Install Powershell for Windows 2k3 64bit.
Config powershell:
- Start Windows PowerShell with the "Run as administrator" option.
- On server: enable-psremoting
- On server: Set-ExecutionPolicy Unrestricted
- On server: Set-Item wsman:\localhost\client\trustedhosts * (allows any computer to connect)
- On server: Restart-Service WinRM
- On client: Set-ExecutionPolicy Unrestricted
- On client: Set-Item wsman:\localhost\client\trustedhosts * (allows connections to any server)
- On client: Restart-Service WinRM
Syntax command for examples:
- Run in command line
- Command [IP server] [service name/process name]
Example 1:
Run command line to stop process on local or remote server:
@echo off
set arg1=%1
set arg2=%2
@powershell -command "Invoke-Command -ComputerName %arg1% -ScriptBlock {get-process %arg2% | stop-process -force}"
Example 2:
Run command line to show status of service on local or remote server:
@echo off
set arg1=%1
set arg2=%2
@powershell -command "Invoke-Command -ComputerName %arg1% -ScriptBlock {Get-Service -Name %arg2%}"
Example 3:
Run command line to stop service on local or remote server:
@echo off
set arg1=%1
set arg2=%2
@powershell -command "Invoke-Command -ComputerName %arg1% -ScriptBlock {Get-Service -Name %arg2% | Stop-Service}"
Example 4:
Run command line to start service on local or remote server:
@echo off
set arg1=%1
set arg2=%2
@powershell -command "Invoke-Command -ComputerName %arg1% -ScriptBlock {Get-Service -Name %arg2% | Start-Service}"
http://www.roelvanlisdonk.nl/?p=3162
Home / powershell / Windows / Powershell Install, config, example
Subscribe to:
Post Comments (Atom)
Post a Comment
Post a Comment