Hello. Been searching other posts, forums, etc. and thought I would come here. I used the addsubnet.ps1 script from Jerry Martin to batch create thousands of subnets in AD using csv files for input. It works like a champ. However, we now have found that several hundred subnets already existed and none have a location field populated. We need the location field to be populated for use with printers etc.
I saw the script on updating AD users info at - http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/14/use-powershell-and-active-directory-cmdlets-to-update-users-in-active-directory.aspx
and thought that maybe that logic could be modified to update an existing subnet's location field?
Here is a code snip from the addsubnet.ps1 that creates a non-existing subnet...
#Test if the new subnet doesn't already exist
If (!(Test-XADObject -Identity $newSubnetDN))
{
#Creating the new subnet
$for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$fortyp = [System.DirectoryServices.ActiveDirectory.DirectoryContexttype]"forest"
$forcntxt = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext($fortyp, $for)
$subnet = new-object System.DirectoryServices.ActiveDirectory.ActiveDirectorySubnet($forcntxt, $SB.subnetname, $SB.sitename)
$Subnet.Location = $SB.subnetlocation
$subnet.Save()
#Set the Subnet Description
$subnetde = $subnet.GetDirectoryEntry()
$subnetde.Description = $SB.subnetdescription
$subnetde.CommitChanges()
Can anyone provide some direction on how to update the subnet.location field using a list of subnets in a csv or other method?
Thanks
Don K
Don K