Automating Active Directory with PowerShell ??
Piotr Klepuszewski
Director General @ CyberSentinelSolutionsLTD | Kali Linux Expert
Introduction Welcome to the world of Active Directory (AD) automation! ?? With PowerShell, administrators can streamline various tasks in both Windows Server Active Directory and Azure Active Directory. Let's explore some practical script examples. #TechSavvy #ADAutomation #PowerShellMagic
1. Creating New AD Users in Windows Server ?? Automate the process of creating users in AD using a CSV file with this PowerShell script. #BulkCreation #UserManagement
Import-Module ActiveDirectory
$users = Import-Csv -Path "C:\path\to\userlist.csv"
foreach ($user in $users) {
$password = ConvertTo-SecureString $user.Password -AsPlainText -Force
New-ADUser -Name $user.Name -GivenName $user.FirstName -Surname $user.LastName -SamAccountName $user.SamAccountName -UserPrincipalName $user.UPN -Path "OU=Users,DC=example,DC=com" -AccountPassword $password -Enabled $true
}
2. Managing GPO in Active Directory ??? This script helps you back up all your Group Policy Objects (GPO) efficiently. #GPOBackup #PolicyManagement
Import-Module GroupPolicy
$GPOs = Get-GPO -All
foreach ($GPO in $GPOs) {
Backup-GPO -Guid $GPO.Id -Path "C:\path\to\backup\folder"
}
3. Azure Active Directory Management ?? Easily add a user to a group in Azure AD with this script. #AzureAD #GroupManagement
领英推荐
Connect-AzureAD
$User = Get-AzureADUser -ObjectId "[email protected]"
$Group = Get-AzureADGroup -SearchString "Group Name"
Add-AzureADGroupMember -ObjectId $Group.ObjectId -RefObjectId $User.ObjectId
4. AD Reports and Diagnostics ?? Automate the creation of comprehensive reports and diagnostics for AD. #ADHealthCheck #Reporting
# AD User Report
Get-ADUser -Filter * -Properties * | Select-Object Name, SamAccountName, Enabled, Created, LastLogonDate | Export-Csv -Path "C:\AD_Users_Report.csv" -NoTypeInformation
# AD Computers Report
Get-ADComputer -Filter * -Property * | Select-Object Name, DNSHostName, Enabled, Created, LastLogonDate | Export-Csv -Path "C:\AD_Computers_Report.csv" -NoTypeInformation
# AD Health Diagnostics
dcdiag > C:\AD_Health_Report.txt
Notes
Managing Remote Desktop Access ??? Manage user "Piotr's" access to Remote Desktop effectively using PowerShell. #AccessControl #RemoteDesktop
Conclusion PowerShell in Active Directory offers a powerful suite of tools for efficient IT management, from user creation to policy enforcement and health monitoring. Customizable and adaptable, these scripts are an administrator's ally. #PowerShellPro #EfficientIT