Created
August 24, 2016 17:52
-
-
Save mikebranstein/d5fabe101bcc705edfbdaa4f4bb3fc36 to your computer and use it in GitHub Desktop.
Full code for renaming a device remotely with PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trust the remote pi and connect to it | |
Write-Host "Configuring WinRM TrustedHosts..." | |
$trustedHosts = Get-Item WSMan:\localhost\Client\TrustedHosts | |
if ($trustedHosts.Value -eq "") { | |
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $ipAddress -Force | |
} | |
elseif (-not $trustedHosts.Value.Contains($ipAddress)) { | |
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "$($trustedHosts.Value),$($ipAddress)" -Force | |
} | |
Write-Host "Establishing PS Session to $deviceName..." | |
$pstimeout = New-PSSessionoption -OperationTimeout (1000*60*5) | |
$session = New-PSSession -computer $ipAddress -Credential $cred -ErrorAction Stop -SessionOption $pstimeout | |
#Rename Device to Device Name | |
Write-Host "Renaming Device $ipAddress to $deviceName" | |
Invoke-Command -Session $session -FilePath .\Rename-Device.ps1 -ArgumentList $deviceName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment