Solved

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

Posted on 2016-07-25
2
33 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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
Derp..... i need more coffee.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
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 discusses moving either the default database or any database to a new volume.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now