Could you guys please help me with the following scenario . Here is what i am trying to accomplish .
I generate a report of computers that need that need to be disabled in AD = file1.txt
I have a pre-made list of Computers to exclude from getting disabled = file2.txt
- I have a script to disable a list of computers from a text file but i would like to exclude whatever computer that exist in the file2.txt .
Here is what i have so far
$toBeDisabled = Import-CSV \\SERVER\file1.csv
$toBeExcluded = Import-CSV \SERVER\file2.csv
$toBeDisabled = $toBeExcluded | Where-Object {($toBeExcluded | Select-Object -ExpandProperty Name) -NotContains $_.Name}
ForEach ($Computer in $toBeDisabled.DeviceName)
{ $Computer = $Computer.Trim()
$ADComputer = Get-ADComputer $Computer -Properties Description
If ($ADComputer)
{ Add-Content c:\temp\computers.log -Value "The following PC $Computer has been found and disabled"
Set-ADComputer $ADComputer -Description "$($ADComputer.Description)- Disable due to inactivity - $(Get-Date) - by $env:UserName " -Enabled $False
}
Else
{ Add-Content c:\temp\computers.log -Value "$Computer not Found in Active Directory or Was disabled before"
}
}
Im getting the following error (Select-Object : Property "Name" cannot be found)
Thanks
file1.csv
seems to have the headerDeviceName
- this is what I call layout. It's your task to include such information in your edited question. – user6811411