Как объясняет Lotpings , сначала необходимо получить объект пользователя из AD с помощью значения (строки), введенного с помощью командлета Read-Host.
Убедитесь, что выпопросите SamAccountName
пользователя, потому что это то, что вам нужно, чтобы найти объект пользователя AD.
Import-Module ActiveDirectory
$accountName = Read-Host "Enter the SamAccountName of the terminated user: "
# find the user object using the SamAccountName entered
# Get-ADUser takes a DistinghuishedName, a GUID, a SID or SamAccountName as Identity parameter
$user = Get-ADUser -Identity $accountName
if ($user) {
# Move-ADObject takes a DistinghuishedName or GUID as Identity parameter
Move-ADObject -Identity $user.DistinguishedName -TargetPath "OU=DisabledAccounts,DC=nfii,DC=com"
# you can also pipe the object through:
# $user | Move-ADObject -TargetPath "OU=DisabledAccounts,DC=nfii,DC=com"
}
else {
Write-Warning "User with SamAccountName '$accountName' not found."
}