Author Posts

December 13, 2013 at 2:20 pm

Good night guys!
Need a little help!
I made a script to disable users in the ad but I need to make an if and else to take the test within a file .csv whether or not hesitate in AD and disable.

Add-PSSnapin Quest.ActiveRoles.ADManagement
Import-Module ActiveDirectory

$UsersToDisbableList=IMPORT-CSV C:\users.csv  
Get-Credential -Credential avista\adm
Connect-QADService -service $PrimaryDC 
 
Function DisableUsers 
{ 
    Param( 
        [string] $_SamAccountName
        ) 
 
Get-ADUser -filter { DisplayName -eq $_SamAccountName } | Set-ADUser -Enabled $false
write-host ("Usuario: $_SamAccountName [Inactive]")
Start-Sleep -s 2 
} 
 
FOREACH ($User in $UsersToDisbableList) { 
    DisableUsers $User.SamAccountName
}

December 14, 2013 at 2:39 pm

I'm sorry – I don't think I understand what you're asking for.

Are you saying you need it to take a CSV file as input? What does the CSV file look like?

Are you saying you want to check and see if the user exists first? What do you want it to do if the user does not exist?