Restart-Computer enhanced in powershell V3

In PowerShell v3, Restart-Computer now has a number of useful newparameters. For example, you can restart a remote machine and wait for thereboot process to finish.

-Wait: Halts the script until the machine has rebooted

-Timeout: Seconds to wait for the machine to restart

-For: Considers the computer to have restarted when the specified resourcesare available. Valid values: WMI, WinRM, and PowerShell.

-Delay: Interval in seconds used to query the remote computer to determineits availability specified by -For.


Before the PSv3 introduce, We have to use test-connection to make sure the IP connection already established , use get-service to make sure  some service already running like WinRM.

The old code like:

# Test connection
Test-Connection -ComputerName $hst.ComputerName -Quiet

# Check the WinRM services status.
Get-Service -ComputerName $hst.ComputerName -Name WinRM -ErrorAction SilentlyContinue | Where-Object{$_.Status -eq "Running"}

The new code like:

Restart-Computer -ComputerName $hst.ComputerName -For WinRM


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值