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 y...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.