Skip to content

Instantly share code, notes, and snippets.

@dpo007
Last active January 14, 2020 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpo007/104c09da58fa3ad910e3f47958d8cefa to your computer and use it in GitHub Desktop.
Save dpo007/104c09da58fa3ad910e3f47958d8cefa to your computer and use it in GitHub Desktop.
PowerShell script :: Wraps Rename-Computer, for use during scheduled/remote launches on Domain-Attached machines.
#################
# Wrapper for Rename-Computer
# - Intended to be used with an RMM/automated script launcher.
# - DPO, Jan. 2020
#################
param (
[Parameter(Mandatory=$True)]
[string]$NewName,
[Parameter(Mandatory=$True)]
[string]$DomainCreds,
[Parameter(Mandatory=$True)]
[string]$DomPass
)
$plainPass = $DomPass | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($DomainCreds, $plainPass)
Write-Host "Renaming `"$env:computername`" to `"$NewName`", and then rebooting..."
Rename-Computer -NewName $NewName -DomainCredential $credential -Force -Restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment