In the future, a good troubleshooting step would be to eliminate the command
that's giving the error and make sure you know what's getting passed, like so:
foreach ($computer in $oldcomputers){$computer.CN}
That would narrow the problem down to the content you're pulling and not to
Get-ADComputer.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Kurt Buff
Sent: Friday, November 7, 2014 2:14 PM
To: [email protected]
Subject: Re: [NTSysADM] Powershell simpleton
It's a list of computer names, one per line, not FQDNs.
And....
It worked!
Many thanks for that...
Kurt
On Fri, Nov 7, 2014 at 12:08 PM, Michael B. Smith <[email protected]> wrote:
> Does computers.txt just contain a list of computer names?
>
> If so, change $computer.CN to simply $computer.
>
> If it is indeed a CSV, you'll need to use import-csv, not get-content.
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> On Behalf Of Kurt Buff
> Sent: Friday, November 7, 2014 3:02 PM
> To: [email protected]
> Subject: [NTSysADM] Powershell simpleton
>
> This is about as simple as it gets, and I'm flummoxed and frustrated.
> What on Earth am I doing wrong?
>
> Win7, powershell v2.
>
> I borrowed this script:
> http://community.spiceworks.com/topic/508041-bulk-move-computer-objects-powershell
>
> and run it like so (the 3rd line might be wrapped) and get the following
> error:
> Import-module activedirectory
> $oldcomputers = get-content c:\batchfiles\computers.txt
> foreach ($computer in $oldcomputers){Get-ADComputer $computer.CN
> | Move-ADObject -TargetPath 'ou=DeadComputers,dc=example,dc=com' }
>
> Get-ADComputer : Cannot validate argument on parameter 'Identity'. The
> argument is null. Supply a non-null argument and try the command again.
> At line:1 char:52
> + foreach ($computer in $oldcomputers){Get-ADComputer <<<<
> $computer.CN | Move-ADObject -TargetPath 'ou=DeadComputers,dc=example,dc=com'
> }
> + CategoryInfo : InvalidData: (:) [Get-ADComputer],
> ParameterBindingValidationException
>
>