Any guidance or help is appreciated. Where I am, we are trying to set up a quick script to get the contents of a csv (names - but not the dn, only full names are in the file), then search ad for a user that contains the name from the csv, maybe even like, then disable and move the account to an ou, pipe the results out to an excel sheet and open.
I’ve got the export, get the contents, and can even list the contents, but what I can’t do is figure out how to search for each line like a variable with a wildcard.
I tried (obviously wrong) - Get-Content c:\scripts\test.csv | Get-ADUser -Filter Name -contain * | Move-ADObject -TargetPath “OU=Disabled User Accounts,DC=ad,DC=library,DC=ucla,DC=edu” -PassThru | Disable-ADAccount
Tried then to get just the contents and assign each line as a variable then search that variable with a wildcard - wrong again
$fubar = Get-Content C:\scripts\test.csv | out-string
ForEach ($fubars in $fubar) {
$fubars -add ‘*’ | Out-File c:\scripts\new.txt -Append
}
Invoke-item c:\scripts\new.txt
Then I thought hmm - steal from another script of mine that gets group members and removes the disabled accounts from the group
$fubar = Get-Content C:\scripts\test.csv
$snooplion = Get-aduser $fubar -Recursive | where-object
and nope not gonna work.
My logic is
$get = get the contents of the csv
Get-aduser name (first and last name field property) filter on it so ( it either contains or is like each name in each line of the csv)
from there
pipe it to a excel file
and disable the account, and move it to another ou.
invoke item to open the excel file showing the moved accounts names
I can figure out the second half, but I can’t figure out the meat and bones of it. I use other scripts pieces and parts for examples, but this one I can’t seem to search it out correctly. If anyone has any imput, I appreciate it.
After I have the meat and bones, I can figure out how to put in the functions and make it more elaborate with other inputs and checks and balances.
Dave
UCLA Library