Getting computername in PowerShell is quite straight forward using environments variable.
Example: $computerName = $env:ComputerName
Write-Host "The computer name is: $computerName"
With the right credentials and as long as WinRM or Windows Remote Management is enabled we can use the Environment ComputerName variable to shutdown a remote PC.
This command runs or shutdown a remote pc, by invoking a local command to shutdown the PC.
Invoke-Command -ComputerName remote_computer_name -ScriptBlock {Stop-Computer -ComputerName $env:ComputerName }
The above invokes shutdown command locally, just like you were in front of the server or computer.
Above is just a demonstration on how to use ComputerName environment variable.
Shutting down a remote computer with a valid domain credentials, doesn't need the invoke-command instead command below can be used.
Stop-Computer -ComputerName "RemotePC1", "Server2" -Force
1 Peter 5:6: "Humble yourselves, therefore, under God’s mighty hand, that he may lift you up in due time."
In layman terms, be humble so you will not stumble.
Example: $computerName = $env:ComputerName
Write-Host "The computer name is: $computerName"
With the right credentials and as long as WinRM or Windows Remote Management is enabled we can use the Environment ComputerName variable to shutdown a remote PC.
This command runs or shutdown a remote pc, by invoking a local command to shutdown the PC.
Invoke-Command -ComputerName remote_computer_name -ScriptBlock {Stop-Computer -ComputerName $env:ComputerName }
The above invokes shutdown command locally, just like you were in front of the server or computer.
Above is just a demonstration on how to use ComputerName environment variable.
Shutting down a remote computer with a valid domain credentials, doesn't need the invoke-command instead command below can be used.
Stop-Computer -ComputerName "RemotePC1", "Server2" -Force
1 Peter 5:6: "Humble yourselves, therefore, under God’s mighty hand, that he may lift you up in due time."
In layman terms, be humble so you will not stumble.
Comments
Post a Comment