Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 35
  • Last Modified:

Script to change ad office attribute bulk

Hi i am trying to change the office ad attribute for 100 users in a csv
0
Jorge Ocampo
Asked:
Jorge Ocampo
  • 2
2 Solutions
 
SubsunCommented:
Try..
Import-Module Activedirectory
Import-csv c:\input.csv | %{Set-ADUser $_.User -Office $_.Office}

Open in new window

Sample input csv file
User,Office
UserA,OfficeA
UserB,OfficeB

Open in new window

0
 
Todd NelsonSystems EngineerCommented:
This should accomplish your request...

Import-Module ActiveDirectory
Import-Csv "C:\Users.csv" | ForEach-Object { Set-ADUser -Identity $_.Name -Office $_.Office }

Open in new window

0
 
Jorge OcampoAuthor Commented:
asweome thanks guys any reason why my below query doesnt run?

Get-ADobject -Filter "*" -Properties mail,office | Where-Object {$_. -like "OFFICE12"} | Export-Csv C:\Temp\TEMP\file12.csv
0
 
SubsunCommented:
If you are trying to filter office attribute the you need to use $_.Office instead of $_.
Try using
Where-Object {$_.Office -like "OFFICE12"}

Open in new window

or
Where-Object {$_.Office -Match "OFFICE12"}

Open in new window

0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now