Hello,
I wrote a script to rename computer and checking its new name in AD and use another (add 1) if exists. But I find a way to rewrite this script to avoid using Get-ADComputer, because I do not want to install RSAT and AD Module on each client machine. Please give advice. I saw examples (ADO) using VB, but I need to write using PS.
import-module ActiveDirectory
$pass = 'Pass'
$password = ConvertTo-SecureString -String 'Pass' -AsPlainText -Force
$login = 'contoso\administrator'
$ComputerName = (Get-WmiObject - Class Win32_ComputerSystem).Name
$ComputerName = $ComputerName -replace "NT","7"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $login, $password
try {
Get-ADComputer $ComputerName -Credential $cred -ErrorAction Stop
$ComputerName = $ComputerName + '1'
$ComputerInfo.Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($ComputerName, $pass,$login)
}
catch {
$ComputerInfo.Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($ComputerName, $pass,$login)
}