Moving Inactive AD computer Accounts to other folder with adding description

Welcome Forums General PowerShell Q&A Moving Inactive AD computer Accounts to other folder with adding description

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
6 months, 3 weeks ago.

  • Author
    Posts
  • #101344

    Participant
    Points: 0
    Rank: Member
    $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.

  • #101352

    Participant
    Points: 268
    Helping Hand
    Rank: Contributor

    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"
        }

The topic ‘Moving Inactive AD computer Accounts to other folder with adding description’ is closed to new replies.