We help IT Professionals succeed at work.

PowerShell Output to CSV question

yo_bee
yo_bee asked
on
Medium Priority
3,770 Views
Last Modified: 2012-08-28
I have a simple PS script that get-adgroup and only three of the attributes (Name, authOrig, dLMemSubmitPerms ).  When I run this without the Export-Csv I can see the values, but when I run it with the Export-Csv I get
Users      Microsoft.ActiveDirectory.Management.ADPropertyValueCollection


Get-ADGroup -Filter * -Properties authOrig, dLMemSubmitPerms | select Name, authOrig, dLMemSubmitPerms | Export-Csv C:\Test.csv

Open in new window


Any help is greatly appricated.
Comment
Watch Question

Commented:
Can you try select-object instead of select?
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
Same results.

:(

Commented:
Can you post screenshot of what you get in the csv?
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
SS01

Commented:
Also a quick screenshot of output in PS? Can't login my server atm.
Stelian StanIT Services Manager
CERTIFIED EXPERT

Commented:
Try to run this:

Get-ADGroup -Filter * -Properties authOrig, dLMemSubmitPerms | Export-Csv C:\Test.csv

When you export to CSV file it's better not to use select, format-table
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
@Clonyxlro

When I run it that why I just get the default attributes (DN,SID,Name....)

@Xaelian

PS02
Stelian StanIT Services Manager
CERTIFIED EXPERT

Commented:
Use Out-File instead of Export-Csv

Get-ADGroup -Filter * -Properties authOrig, dLMemSubmitPerms | select Name, authOrig, dLMemSubmitPerms | Out-File D:\test.txt

Open in new window

Commented:
Can you try

Get-ADGroup -Filter * -Properties authOrig, dLMemSubmitPerms | select Name, authOrig, dLMemSubmitPerms | out-file C:\Test.csv
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
@ Xaelian

The issue with that cmdlet is that the Values are truncated.  I need to get the entire array.
Stelian StanIT Services Manager
CERTIFIED EXPERT

Commented:
This is the right sintax:

Get-ADGroup -Filter * -Properties authOrig, dLMemSubmitPerms | select Name, authOrig, dLMemSubmitPerms | csvde -f file.csv

Open in new window

Commented:
Ok maybe if you change output-file or the export-csv with csvd -f, it could work. Can't copy paste at the moment with my mobile device.
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
This is dumping the entire AD and it does not have the attributes I am looking for.
Senior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012
Commented:
Just only give to you some hints as I'm not that good in PowerShell as others. This is related with variables output, you need to convert them to string before exporting to CSV file.

Please take a look at this answered post on Microsoft Technet forum and try to implement that in your script
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/eb58b98b-cd3f-4ad9-b75f-cf50abb80d31/

Regards,
Krzysztof
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
What if I took  the attribute that is multivalued array and then loop through that to get the names?

Would that work.  If so what steps would I take to do this?
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
I ended up using the information from the link that iSeik posted.
I still need to loop through the array, but that is another question and another time.

Thank you all for you assistance and guidance.
yo_beeDirector of Information Technology
CERTIFIED EXPERT

Author

Commented:
To add to this.
I found a way to get to the final result.
Import-Module ActiveDirectory

$GroupList = Get-ADGroup -Filter * 

foreach ($group in $GroupList)
{
    If ($group.name -eq 'Partners')
    {
        Write-host $group.name
        
        (Get-ADgroup -identity $group.name -Properties authOrig| Select-Object authOrig).authOrig |Get-ADuser |Select Name 
        (Get-ADgroup -identity $group.name -Properties dLMemSubmitPerms| Select-Object dLMemSubmitPerms).dLMemSubmitPerms |Get-ADGroup |Select Name 
        
       
    }
 }

Open in new window