Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Move-ADobject challenges

$
0
0

Hello,

After struggeling a few day's I do not come any further :

I build a basic script tjat iomports a csv with expired and/or disabled users.
It checks if they reaily are disabled and if not it sets them "Disabled"

Now I need to move these disabled accounts to a target OU , for this I did some research on my own and used some pre-made examples. None of this will get me to move these disabed / expired users however.

Hopefully somebody can point me to the right path..

$Users = Import-CSV "D:\Users\Documents\PS-script\Input\Sam.csv"

$TargetOU = "OU=Inactief,OU=xxxxx,DC=xxxxx,DC=ad,DC=xxxxx,DC=nl"

foreach($name in $users.sam){
  if ( Get-ADUser -Filter {Samaccountname -eq $Name}-ErrorAction SilentlyContinue ) {
       Get-ADUser -Filter {Samaccountname -eq $Name} | select Displayname | Export-Csv $ExportPadEnBestand -Append
       Write-Host "Gevonden: $name"
       $TellerGevonden++
        }
    else {
        Write-Host "Not found: $name"
        $TellerNietGevonden++
        variable
          }
         }

$result =@()
Foreach($name in $users.sam) {
$result += Get-ADUser -Filter{Samaccountname -eq $name -and enabled -eq $false} -Properties AccountExpirationDate | Select sAMAccountName, distinguishedName, AccountExpirationDate
        }
 $result | Out-GridView

 #If enabled is true, then disable
  Foreach($name in $result){
  Disable-ADAccount -Identity $name 
        }

# Move the accounts tho Target OU
 # Move user to target OU.
    Move-ADObject -Identity $result -TargetPath $TargetOU

For the Move-adobject it returns a 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.

When I type the $result  is does contain data.

So I hav eno idea at this moment why this is happening .


pba1211


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>