How can I enable or disable an AD user account from a csv based on an entry. If the status for both say Active, only one account gets enabled instead of both. Same for the disabled status.
CSV file:
Samaccountname,Status
john.doe,Active
jane.doe,Disabled
What I have so far:
$User = Import-Csv -Path c:\folder\adaccounts.csv
ForEach ($User in $Users)
{
IF ($User.Status -contains "Disabled")
{
Get-ADUser -Identity $user.samaccountname | Disable-ADAccount
}
elseif ($User.Status -contains "Active")
{
Get-ADUser -Identity $user.samaccountname | Enable-ADAccount
}
Disable/Enable AD user account from CSV
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 3
- Last visit: Thu Oct 28, 2021 5:00 pm
Disable/Enable AD user account from CSV
"-contains" only works for collections. Use "-match" or "-eq".
Here is a good place to start to learn basic PowerShell and programming: https://www.sapien.com/books_training/W ... werShell-4
Go to full postHere is a good place to start to learn basic PowerShell and programming: https://www.sapien.com/books_training/W ... werShell-4
Re: Disable/Enable AD user account from CSV
"-contains" only works for collections. Use "-match" or "-eq".
Here is a good place to start to learn basic PowerShell and programming: https://www.sapien.com/books_training/W ... werShell-4
Here is a good place to start to learn basic PowerShell and programming: https://www.sapien.com/books_training/W ... werShell-4