Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

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

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
get-ADuser -F ($_.Name -eq "Todd")
Asked:
get-ADuser -F ($_.Name -eq "Todd")
1 Solution
 
Neil RussellTechnical Development LeadCommented:
Use Export-csv instead
0
 
SubsunCommented:
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
 
QlemoC++ DeveloperCommented:
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
Technology Partners: 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!

 
get-ADuser -F ($_.Name -eq "Todd")Systems AdministratorAuthor Commented:
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
 
get-ADuser -F ($_.Name -eq "Todd")Systems AdministratorAuthor Commented:
Very much appreciated.
0
 
SubsunCommented:
No problem... You could also accept multiple comments as answer and split points (assist)  if the experts comments are helpful..
0

Featured Post

WatchGuard Case Study: NCR

With business operations for thousands of customers largely depending on the internal systems they support, NCR can’t afford to waste time or money on security products that are anything less than exceptional. That’s why they chose WatchGuard.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now