Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How to check computer name in AD without Get-ADComputer?

$
0
0

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)

}




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>