export csv with personal column

export csv with personal column

avatar
vpierron
Disabled

hi,

i tried to export data of rdm in a xml file.

But i want to select only a few columns (domain, architecture, os and description).

My script is:

$s = Get-RDMSession | where {$_.ConnectionType -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;

but i have a lot of errors like:

You cannot call a method on a null-valued expression.

At C:\Travail\RDM\script_ps\export-csv.ps1:2 char:14

+ foreach { New-Object PSObject -Property @{

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (:) [], RuntimeException

+ FullyQualifiedErrorId : InvokeMethodOnNull

my version of rdm is 12.0.10.0

best regards

Vincent

All Comments (2)

avatar

Hi Vincent,

You have the PSConnection object in $_ when you do your foreach, you can use the properties directly.

Ex:

$s = Get-RDMSession | where {$_.ConnectionType -eq "RDPConfigured"} | foreach { New-Object PSObject -Property @{

Name = $_.Name

Domain = $_.MetaInformation.Domain

Architecture = $_.MetaInformation.Architecture

OS = $_.MetaInformation.OS

Description = $_.Description

}};

$s | Export-Csv C:\temp\sessions.csv -NoTypeInformation

Best regards,

Olivier Désalliers

avatar
vpierron
Disabled

thanks Olivier;)