I have a script that I need to find the full Distinguished name ( CN=MyComputer, OU=Computers, DC=vw, DC=local) of the computer on which it is running, however I can not guarantee that the module ActiveDirectorywill be available on all computers, the script will be launched. Is there a way to get the full computer name different from the name without using Get-ADComputer $Env:COMPUTERNAME?
Just in case, this is an XY problem, what I'm trying to do is transfer the computer to a specific unit, but I need a way to get the ASDI record for the computer I'm running on.
[ADSI]$computer = ("LDAP://" + $localDN)
if($Production)
{
[ADSI]$destination = 'LDAP://ou=Production,ou=Computers,ou=VetWeb,dc=vw,dc=local'
$computer.MoveTo($destination);
}
else
{
[ADSI]$destination = 'LDAP://ou=Test,ou=Computers,ou=VetWeb,dc=vw,dc=local'
$computer.MoveTo($destination);
}
source
share