Скрипт на PowerShell. Запуск с повышением прав.
CSV файл создается в Excel. Одна колонка. Первая строка содержит name. Ниже логин пользователя без домена.
clear
# Import AD Module
import-module ActiveDirectory
# Import CSV
$MoveList = Import-Csv -Path "C:\export\otherUser.csv"
# Specify target OU.This is where users will be moved.
$TargetOU = "OU=otherUser,OU=LOCK-OBJ,OU=MAIN,DC=gladspir,DC=ru"
# Import the data from CSV file and assign it to variable
$Imported_csv = Import-Csv -Path "C:\export\otherUser.csv"
$Imported_csv | ForEach-Object {
# Retrieve DN of User.
$UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
Write-Host " Moving Accounts ..... "
# Move user to target OU.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}
Write-Host " Completed move "
$total = ($MoveList).count
Write-Host " $total accounts have been moved succesfully..."
CSV файл создается в Excel. Одна колонка. Первая строка содержит name. Ниже логин пользователя без домена.
clear
# Import AD Module
import-module ActiveDirectory
# Import CSV
$MoveList = Import-Csv -Path "C:\export\otherUser.csv"
# Specify target OU.This is where users will be moved.
$TargetOU = "OU=otherUser,OU=LOCK-OBJ,OU=MAIN,DC=gladspir,DC=ru"
# Import the data from CSV file and assign it to variable
$Imported_csv = Import-Csv -Path "C:\export\otherUser.csv"
$Imported_csv | ForEach-Object {
# Retrieve DN of User.
$UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
Write-Host " Moving Accounts ..... "
# Move user to target OU.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}
Write-Host " Completed move "
$total = ($MoveList).count
Write-Host " $total accounts have been moved succesfully..."
Комментариев нет:
Отправить комментарий