Custom export to CSV

avatar

Hi all

Many customers ask for a special export that would contain specific fields. Here is a small script that can be used to generate URLs for our new web protocol handler. We generate a csv file that contains the name and the URL.

## get the data source ID, note that the "Create Web Url" button generates a different ID, but both are accepted

$dsid = Get-RDM-DataSource | where {$_.IsCurrent -eq "X"} | select -expand "ID"

## get the RDP sessions, create a new object with the desired fields.

## Simply append "add-member" commands to include a new field

$s = Get-RDM-Session |

where {$_.Session.Kind -eq "RDPConfigured"} |

foreach {

new-Object Object |

Add-Member NoteProperty Name $_.Name –PassThru |

Add-Member NoteProperty URL "rdm://open?DataSource=$dsid&Session=$($_.ID)" –PassThru

};

## save to csv, the field names are used as column headers.

$s | export-csv c:\temp\sessions.csv -notypeinformation;

edited by mcote on 7/4/2014

Maurice

All Comments (1)

avatar

Hello

Here's one with another structure, it goes deeper in the XML structure, namely accessing our MetaInformation object.

$s = Get-RDM-Session |

where {$_.Session.Kind -eq "RDPConfigured"} |

foreach { New-Object PSObject -Property @{

Name = $_.Session.ToString()

Domain = ($_.Session.GetProperty("MetaInformation", "Domain"))

Architecture = ($_.Session.GetProperty("MetaInformation", "Architecture"))

OS = ($_.Session.GetProperty("MetaInformation", "OS"))

Description = ($_.Session.GetProperty("", "Description"))

}};

## save to csv, the field names are used as column headers.

$s | export-csv c:\temp\sessions.csv -notypeinformation;

Maurice