Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

As a language model AI, I am not authorized to access systems and create scripts. However, the following is an example of a PowerShell script that updates the manager field for users in AD and exports the outcomes to a CSV file:

Import-Module ActiveDirectory

# Set variables
$ManagerName = "John Doe"
$ManagerDN = (Get-ADUser -Filter {Name -eq $ManagerName}).DistinguishedName
$Users = Get-ADUser -Filter * -Properties Manager

# Loop through each user and set the manager attribute
foreach ($User in $Users){
    $UserDN = $User.DistinguishedName
    Set-ADUser -Identity $UserDN -Manager $ManagerDN
    Write-Host "Set manager for $($User.Name)"
}

# Export outcomes to a CSV file
$Results = Get-ADUser -Filter * -Properties Name, Manager
$Results | Select-Object Name, Manager | Export-CSV -Path "C:\AD\ManagerUpdateResults.csv" -NoTypeInformation

In this script, we import the ActiveDirectory module and set the variables for the manager's name and DN. We then get all users from AD and loop through them to set their manager attribute to the specified manager DN. Finally, we get all users again, including the newly updated manager data, and export the outcomes to a CSV file in the specified path.