filmov
tv
Bulk user attribute update as per HR data PowerShell script
Показать описание
This PowerShell script imports a CSV file containing user data and updates the corresponding user accounts in Active Directory based on the information in the file.
The ActiveDirectory module is first imported to enable the use of its cmdlets.
The CSV file is then imported using the Import-Csv cmdlet and stored in the $csv variable as an array.
The script then loops through each row of the CSV file using a foreach loop.
For each row, it gets the email address of the user from the Email column of the CSV file and stores it in the $email variable.
Then, it uses the Get-ADUser cmdlet to search for the user account in Active Directory with a matching email address. If a matching user account is found, the script updates the Mobile and value of the user account with the corresponding value from the Mobile columns of the CSV file.
Finally, the Set-ADUser cmdlet is used to save the changes made to the user account in Active Directory.
Below is the Powershell script:
# Import the ActiveDirectory module
Import-Module ActiveDirectory
# Set the path of the CSV file and import it as an array
#$csvData = Import-Csv $csvPath
# Loop through each row of the CSV file
foreach ($row in $csv) {
# Get the email address from the current row
$email = $row.Email
# If the user exists, update the mobile value from the CSV file
$user = Get-ADUser -Filter {EmailAddress -eq $email}
$user.Mobile = $row.Mobile
Set-ADUser -Instance $user
}
The ActiveDirectory module is first imported to enable the use of its cmdlets.
The CSV file is then imported using the Import-Csv cmdlet and stored in the $csv variable as an array.
The script then loops through each row of the CSV file using a foreach loop.
For each row, it gets the email address of the user from the Email column of the CSV file and stores it in the $email variable.
Then, it uses the Get-ADUser cmdlet to search for the user account in Active Directory with a matching email address. If a matching user account is found, the script updates the Mobile and value of the user account with the corresponding value from the Mobile columns of the CSV file.
Finally, the Set-ADUser cmdlet is used to save the changes made to the user account in Active Directory.
Below is the Powershell script:
# Import the ActiveDirectory module
Import-Module ActiveDirectory
# Set the path of the CSV file and import it as an array
#$csvData = Import-Csv $csvPath
# Loop through each row of the CSV file
foreach ($row in $csv) {
# Get the email address from the current row
$email = $row.Email
# If the user exists, update the mobile value from the CSV file
$user = Get-ADUser -Filter {EmailAddress -eq $email}
$user.Mobile = $row.Mobile
Set-ADUser -Instance $user
}