Die Reservierung aller Scopes exportieren:
$dhcpserver = "QuellServer.QuellDomain.com"
Get-DhcpServerv4Scope -ComputerName $dhcpserver | Get-DhcpServerv4Reservation -ComputerName $dhcpserver Export-Csv "pathtofile\ScopeReservation.csv" -Encoding UTF8 -Force -NoTypeInformation -Delimiter ";"
Als nächstes importieren wir die Reservierungen (ACHTUNG!: nicht mit Import, sondern mit Add)
$dhcpserver = "ZielServer.ZielDomain.com"
$scopes = Import-Csv -Path "pathtofile\ScopeReservation.csv" -Delimiter ";"
foreach ($scope in $scopes)
{
$name = $scope.name
$description = $scope.description
Write-Output "Creating scope $name"
Add-DhcpServerv4Reservation -ComputerName $dhcpserver -ScopeId $scope.ScopeId -IPAddress $scope.IPAddress -Description $scope.description -Name $scope.name -ClientId $scope.clientid -Type $scope.Type #-WhatIf
}
Aufgrund eines Firmenkaufs, mussten die DHCP Scopes eines Windows DHCP Server auf einen bereits bestehenden transferiert werden. Da die Standard Backup/Import Funktion die bestehende Konfiguration überschreiben würde, habe ich hierzu PowerShell genutzt:
Export der bestehenden Konfiguration:
$dhcpserver = "QuellServer.QuellDomain.com" Get-DhcpServerv4Scope -ComputerName $dhcpserver | Export-Csv "pathtofile\dhcpscopes.csv" -Encoding UTF8 -Force -NoTypeInformation
Import der Konfiguraton auf den Quellserver:
$dhcpserver = "ZielServer@ZielDomain.com"
$scopes = Import-Csv -Path "pathtofile\dhcpscopes.csv" -Delimiter ";"
foreach ($scope in $scopes)
{
$name = $scope.name
$description = $scope.description
Write-Output "Creating scope $name"
Add-DhcpServerv4Scope -ComputerName $dhcpserver -Name "$name" -Description "$description" -StartRange $scope.startrange -EndRange $scope.endrange -SubnetMask $scope.subnetmask -State Active
}
Wie die ScopeOptions und Reservierungen übernommen werden zeige ich in einem weiteren Beitrag.
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 »
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
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.
Neueste Kommentare