[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2016-07-25
2
Medium Priority
?
63 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
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…

656 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