Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Disable accounts from CSV file

$
0
0

Hi,

 

We receive a weekly csv file about users who left the company and we need to disable there administrative account if it exists. The only unique identifier i have in the file is the user's last name and first name, no samaccount. From this data, I would like to use PS to read the input csv file and search specific OU's if there is an account that matches the last name and first name, if there is a match to disable the account.

 

This is what i have so far (newbie) ... but not sure im on right path .. any advice would be appreciated

 

$FileListOfUsers = "C:\Temp\leavers.csv"

$SearchBaseCA = "OU=Admin Users,OU=Accounts,OU=CA,DC=A,DC=B,DC=C,DC=D"

$SearchBaseBR = "OU=Admin Users,OU=Accounts,OU=CA,DC=A,DC=B,DC=C,DC=D"

$SearchBaseUS = "OU=Admin Users,OU=Accounts,OU=CA,DC=A,DC=B,DC=C,DC=D"

 

$LogPath = "C:\Temp\Logs"

 

IF ( -Not (Test-Path -Path $LogPath)) {New-Item -Path $LogPath -ItemType Directory}

 

$ListOfUsers = Import-CSV $FileListOfUsers -Delimiter ';' | select "Last Name","First Name" | ft

 

ForEach ($Users in $ListofUsers) {

    Get-ADUser -SearchBase $SearchbaseCA -Filter "Last Name" -eq $($Users."Last Name") -and "First Name" -eq $($Users.First Name)" | Disable-ADAccount

  Get-ADUser -SearchBase $SearchbaseBR -Filter "Last Name" -eq $($Users."Last Name") -and "First Name" -eq $($Users.First Name)" | Disable-ADAccount

  Get-ADUser -SearchBase $SearchbaseUS -Filter "Last Name" -eq $($Users."Last Name") -and "First Name" -eq $($Users.First Name)" | Disable-ADAccount

}


Viewing all articles
Browse latest Browse all 6937

Trending Articles