PowerShell to the rescue

 If you want to update the ManagedBy field via Powershell, here is a script example (don’t use it without proper testing)
 
# Get the computer for which you want to update the field
$mycomp = Get-QADComputer -Name computername -SearchRoot ‘dc=DOMAIN,dc=com’
 
# provide requested credentials for updating the field
$cred = Get-Credential mydomainmyaccount
 
Foreach ($comput in $mycomp)
{
$name = $comput.Name
$desc = $comput.Description
$associated = $comput.ManagedBy
 
# Make sure the ManagedBy field is not populated yet, and the description field is not empty
if ($associated -like "")
{
if ($desc -notlike ”)
{
 
# get the AD user for which the Samaccountname matches the Description field of the computer
$myuser = Get-QADUser -searchroot ‘dc=domain,dc=com’ -samaccountname $desc | %{$_.DN}
 
# check also here that you get a valid field from AD (otherwise it means the user wasn’t found)
if ($myuser -ne ”)
{
if ($myuser -ne $null){
$name
 
# populate the field.
Set-QADObject $comput -ObjectAttributes @{ManagedBy=$myuser} -Credential $cred
}
}
}
}
}
 
Note that you will need to use the AD extensions from Quest to use this script as is.

A very good book / site

While I was looking for ways to improve the Sccm processes that i just discussed, I found a very usefull book and the blog that comes with it.
(If you read this blog, i am pretty sure you will get very valuable information here as well as new ways to do familiar things).

 Dan Holme’s Blog [Productivity Solutions for IT Professionals]

 

 

Advertisements