• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 76
  • Last Modified:

Get-adcomputer script, I'm missing something

$OU = Get-content 'C:\Powershell Projects\computerOU\OU.txt' |
ForEach-Object {Get-adcomputer -filter {(enabled -eq $True)} -SearchBase $OU} | Export-Csv 'C:\Powershell Projects\ComputerOU\results.csv'

Open in new window


Error

Get-ADComputer : Cannot validate argument on parameter 'SearchBase'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:2 char:74
+ ... Object {Get-adcomputer -filter {(enabled -eq $True)} -SearchBase $OU}
+                                                                      ~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADComputer], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADComputer


Why doesn't that work?

If I wrap the $OU variable in "$OU" it gives me

Get-adcomputer : An empty SearchBase is only supported while connected to a GlobalCatalog.
At line:2 char:17
+ ... ach-Object {Get-adcomputer -filter {(enabled -eq $True)} -SearchBase  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADComputer], ArgumentException
    + FullyQualifiedErrorId : An empty SearchBase is only supported while connected to a GlobalCatalog.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
0
Alex Green
Asked:
Alex Green
1 Solution
 
oBdACommented:
$OU would receive the results of the pipeline; line 1 is not a simple statement, it opened a pipeline (note the pipe symbol at the end).
Get-Content 'C:\Powershell Projects\computerOU\OU.txt' |
	ForEach-Object {Get-ADComputer -Filter {(enabled -eq $True)} -SearchBase $_} |
	Export-Csv 'C:\Powershell Projects\ComputerOU\results.csv'

Open in new window

One of the reasons why proper indentation is so helpful ...
0
 
Alex Green3rd Line Server SupportAuthor Commented:
URRRGHHHHHH

Thank you :D
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now