Solved

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

Posted on 2016-07-25
2
52 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 84

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix process listing into CSV format 3 46
Unix Command (AIX) 3 39
Office 365 user report 6 42
global Variable - 2 functions in powershell 1 19
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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