Solved

Help with script to get OU of specific computer objects (from CSV)

Posted on 2016-07-25
2
48 Views
Last Modified: 2016-07-25
I am trying to display the OU of a set of computer objects in Active Directory(from CSV)
I wrote this up and, it doesn't do anything, seems like a simple thing....
import-module activedirectory
$cred = Get-Credential
import-CSV C:\Users\ME\Desktop\scripts\servers.csv |
foreach-object {
Get-ADComputer $_.name  -Properties * | FT name, Distinguishedname
}

Open in new window

This works fine, if I give it  a server name "Get-ADComputer servername  -Properties * | FT name, Distinguishedname"
0
Comment
Question by:SquigglyMonkey
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41727867
Should work (sort of), so your input file is probably incorrect.
You'll need a "real" csv with a header line, a column "Name", and only the host name in that column, not the FQDN.
As far as "sort of" is concerned:
- you're not using the credentials you're querying
- there's no need to retrieve all properties if you're filtering most of them out
- Format-Table should be at the very end, not inside the ForEach loop
Import-Module ActiveDirectory
$cred = Get-Credential
Import-CSV C:\Users\ME\Desktop\scripts\servers.csv |
	ForEach-Object {
		Get-ADComputer $_.name -Credential $cred
	} |
	Format-Table Name, Distinguishedname

Open in new window

0
 
LVL 1

Author Closing Comment

by:SquigglyMonkey
ID: 41727876
Derp..... i need more coffee.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question