Author Posts

May 29, 2018 at 9:19 am

$fileDateTimeStamp = Get-Date -format "d-MMM-yyyy__HH-mm-ss"
$disableandmove = Import-Csv C:\ADCLeanUP\Final.xlsx
$disableandmove = $disableandmove | Where-Object {$_.Status -like "Offline"}
$disableandmove | Set-ADComputer -Description "Server computer account disabled on $fileDateTimeStamp due to 365+ days of inactivity" -Enabled $false
$disableandmove | Move-ADObject -TargetPath "OU=Computer Accounts,OU=Disabled Accounts,DC=xxx,DC=xxx,DC=xxx"

when i am running above script getting beloow error

Move-ADObject : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that
take pipeline input.
At C:\ADCLeanUP\ADcleanup.ps1:4 char:19

Can you help me.

May 29, 2018 at 10:10 am

It depends what you have in your csv file (I hope it is a CSV file – in your code you use the file extension ".xlsx"!).
You can make your code a little faster and maybe a little more reliable like this:

Import-Csv C:\ADCLeanUP\Final.xlsx | 
    Where-Object {$_.Status -like "Offline"} | 
    ForEach-Object{
        Set-ADComputer -Identity $_.Name -Description "Server computer account disabled on $fileDateTimeStamp due to 365+ days of inactivity" -Enabled $false
        Move-ADObject -Identity $_.Name -TargetPath "OU=Computer Accounts,OU=Disabled Accounts,DC=xxx,DC=xxx,DC=xxx"
    }