Solved

Powershell Script, I need to add a comma between the results

Posted on 2014-09-04
6
491 Views
Last Modified: 2014-09-04
I have this script that I found and it works.  But I need to have a comma between the name attribute and the managedby attribute.  The result is in csv format but it is all in one cell.  Not sure how to make it work.  Here is the PS cmdlets

$test = 'OU=test,DC=mydomain,DC=int'
$test | ForEach {Get-ADComputer -Filter * -Properties ManagedBy -SearchBase $_ } |
 Select Name, ManagedBy |
 Sort -Property Name |
 Out-File C:\test.csv

Your help is much appreciated.
0
Comment
6 Comments
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
ID: 40304630
Use Export-csv instead
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40304639
You can use Export-Csv to export the details to a csv file..
$test = 'OU=test,DC=mydomain,DC=int'
$test | ForEach {Get-ADComputer -Filter * -Properties ManagedBy -SearchBase $_ } | 
Select Name, ManagedBy |
Sort -Property Name |
Export-Csv C:\test.csv -nti

Open in new window

Refer : http://technet.microsoft.com/en-us/library/ee176825.aspx
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40304810
Note that Export-CSV will enclose all values in double quotes. Since you are talking about "cells", I assume you import the CSV file into Excel - than the double quotes do not matter.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4
ID: 40304836
I can't believe that it was that simple.  I guess it's not simple if you really don't know all the functionality.  That worked.  I appreciate all your help.  Thank you Subsun, as you have been instrumental in my Powershell learning.  To be fair, ( and not get in trouble)  I will award the points to Neilsr as he came in first with the working solution.

Thanks again.
0
 
LVL 4

Author Closing Comment

by:get-ADuser -F ($_.Name -eq "Todd")
ID: 40304838
Very much appreciated.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40304876
No problem... You could also accept multiple comments as answer and split points (assist)  if the experts comments are helpful..
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

777 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