Bulk AD Update durch Excel Datei

On 21. Dezember 2021, in Allgemein, by

Comment : This script updates AD users attributes from excel sheet.

Version : 1.1

This command has been added to script.

[threading.thread]::CurrentThread.CurrentCulture = ‚en-US‘

#

Declare file path and sheet name

$credential=Get-Credential
$ErrorActionpreference = „continue“

[threading.thread]::CurrentThread.CurrentCulture = ‚de-DE‘

$file = „C:\Path\TEST.xlsx“

Create an Excel.Application instance and open that file

$Excelobject = New-Object -ComObject Excel.Application
$Workbook = $Excelobject.Workbooks.Open($file)
$sheetName = „Tabelle1“
$sheet = $Workbook.Worksheets.Item($sheetName)

$objExcel.Visible=$true

Count max row

$rowMax = ($sheet.UsedRange.Rows).count

Count max column

$colMax = ($sheet.UsedRange.Columns).count
$hash = @{}
$server = „DC01.company.com“

Specify starting positions

$row,$col = 1,1
$updatedCount = 0

loop for rows

for ($i=1; $i -le $rowMax-1; $i++)
{

#loop for columns
for($c=0; $c -le $colMax-1; $c++)
{
  #Get all columns values to a hash
  $hash += @{$sheet.Cells.Item($row,$col+$c).text =  $sheet.Cells.Item($row+$i,$col+$c).text}


}

#Create an object and assign hash keys as object property
$Object = New-Object -TypeName PSObject -Property $hash

#Get User via SamAccountname
$user = Get-ADUser -Filter {„SamAccountName -eq ‚$($Object.sAMAccountName)'“} -Server $server -Credential $credential

#Set Users attribute with matched object attribute
$user | Set-ADUser -GivenName $Object.GivenName -Surname $Object.SN
-DisplayName $Object.Displayname -OfficePhone $Object.PhoneNumber
# -Description $Object.Description -Country $Object.Country
-Office $Object.Office -Title $Object.Title
-Company $Object.Company -Department $Object.Department
-Manager $Object.Manager `
-Mobile $Object.Mobile
#-Fax $Object.Fax

#If you want to edit Object common name, you can remove enable two lines below.

#$userguid = $user.ObjectGUID.Guid
#$user | Rename-ADObject -NewName $Object.DisplayName -Server $server -Credential $credential

$hash = @{}
Write-Host $User.Name „- User attributes have been updated.“ -ForegroundColor Yellow
Start-Sleep -s 1
$updatedCount += 1

}

Write-Host $updatedCount „Users have been updated“ -ForegroundColor Green

close excel file

$Excelobject.quit()

 

Mit diesem PowerShell Befehl werden abgelaufene Computer Zertifikate aufgelistet:

Continue reading »

Tagged with:  

Mit Hilfe diesen PowerShell Befehls kann herausgefunden werden, wann die User zuletzt Ihr Passwort geändert haben und ob die Option „Passwort läuft nie ab“ gesetzt wurde:

get-aduser -filter * -properties Name,passwordlastset,passwordneverexpires | Select-Object Name,passwordlastset,passwordneverexpires | Export-Csv C:\Pfad\Last_PW_Set.csv -NoTypeInformation

Tagged with:  

Damit man nicht auf die E-Mails eines Benutzerpostfaches zur Fehlerbeseitigung zugreifen muss, kann man mit Hilfe diesen Befehls die aktuellen Mailregeln der Mailbox(en) exportieren:

$mailboxes = get-mailbox
foreach ($mailbox in $mailboxes) {get-InboxRule -Mailbox $mailbox.UserPrincipalName | export-csv "C:\$mailbox.csv"}

Natürlich kann man auch z.B.
$mailboxes = get-mailbox irgendeinPostfach@meineDomain.de verwenden um nur eine Mailbox abzufragen.

Über diesen Weg ist auch ein Export und Import von Mailregeln möglich.