How to write out Parameter Names from Powershell

Hi

Wondering if there is a way to dynamically output result parameter names as well as values from commandlet output so I can create table rows in html.

for instance

Get-CsUser

will output in PowerShell

Identity                : CN=Mark Vale,OU=Users,OU=xxx
                         xxx,DC=xxxl,DC=xx
VoicePolicy             : Unrestricted
VoiceRoutingPolicy      :
ConferencingPolicy      :
PresencePolicy          :
DialPlan                : xxx Dial Plan
LocationPolicy          :
ClientPolicy            : IMSecurityWarning
ClientVersionPolicy     :
ArchivingPolicy         :
ExchangeArchivingPolicy : Uninitialized
PinPolicy               :
ExternalAccessPolicy    : Allow Federation+Public+Outside Access
MobilityPolicy          :
PersistentChatPolicy    :
UserServicesPolicy      :
HostedVoiceMail         : True
HostedVoicemailPolicy   : xxxUM
HostingProvider         : SRV:
RegistrarPool           : xxxx
Enabled                 : True
SipAddress              : sip:markv@xxxx.xx
LineURI                 : tel:+441785xxxxx;ext=xx46
EnterpriseVoiceEnabled  : True
ExUmEnabled             : False
HomeServer              : CN=Lc Services,CN=Microsoft,CN=1:34,CN=Pools,CN=RTC
                          Service,CN=Services,CN=Configuration,DC=xxx,DC=xxx
DisplayName             : Mark Vale
SamAccountName          : markv

What I want to be able to do is literally output the line name in a row of my choice and then the corresponding value in another row or column of my choice. Or even in a paragraph etc, so Convertto-html wouldn't work for me in this instance

July 30th, 2015 4:43am

You can get the property names using psbase 

$Obj = get-csuser
$obj.psbase.propertynames


  • Edited by Braham20 22 hours 23 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 4:48am

Get-CsUser | select <property list> | ConvertToo-Html -list

The key is to use select and the list option on the convert to get what you are asking for.

July 30th, 2015 6:38am

thanks

the psbase one I can only seem to output the values. I need the property names. Unfortunately the convert to html method as I explained cannot be used because I am creating a custom report where by I need the property names in paragraphs, columns and lines of my choice rather than just spitting them out.

thanks

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 7:04am

$obj.psobject.Properties.name

July 30th, 2015 7:10am

This:

$obj|ConvertTo-Html -As list

Produces this:

<table>
<tr><td>Name:</td><td>spooler</td></tr>
<tr><td>RequiredServices:</td><td>System.ServiceProcess.ServiceController[]</td></tr>
<tr><td>CanPauseAndContinue:</td><td>False</td></tr>
<tr><td>CanShutdown:</td><td>False</td></tr>
<tr><td>CanStop:</td><td>False</td></tr>
<tr><td>DisplayName:</td><td>Print Spooler</td></tr>
<tr><td>DependentServices:</td><td>System.ServiceProcess.ServiceController[]</td></tr>
<tr><td>MachineName:</td><td>.</td></tr>
<tr><td>ServiceName:</td><td>spooler</td></tr>
<tr><td>ServicesDependedOn:</td><td>System.ServiceProcess.ServiceController[]</td></tr>
<tr><td>ServiceHandle:</td><td></td></tr>
<tr><td>Status:</td><td>Stopped</td></tr>
<tr><td>ServiceType:</td><td>Win32OwnProcess, InteractiveProcess</td></tr>
<tr><td>Site:</td><td></td></tr>
<tr><td>Container:</td><td></td></tr>

Which looks like this: ( you can select and set the order of the properties in the command.)

Name: spooler
RequiredServices: System.ServiceProcess.ServiceController[]
CanPauseAndContinue: False
CanShutdown: False
CanStop: False
DisplayName: Print Spooler
DependentServices: System.ServiceProcess.ServiceController[]
MachineName: .
ServiceName: spooler
ServicesDependedOn: System.ServiceProcess.ServiceController[]
ServiceHandle:
Status: Stopped
ServiceType: Win32OwnProcess, InteractiveProcess
Site:
Container:
Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 7:13am

$obj.psobject.Properties.name

July 30th, 2015 7:16am

This:

PS C:\scripts> $obj|ConvertTo-Html -As list -Property DisplayName, MachineName, Status, ServiceName
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<tr><td>DisplayName:</td><td>Print Spooler</td></tr>
<tr><td>MachineName:</td><td>.</td></tr>
<tr><td>Status:</td><td>Stopped</td></tr>
<tr><td>ServiceName:</td><td>spooler</td></tr>
</table>
</body></html>

Produces this:

DisplayName: Print Spooler
MachineName: .
Status: Stopped
ServiceName: spooler

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 7:17am

You can get the property names using psbase 

$Obj = get-csuser
$obj.psbase.propertynames


  • Edited by Braham20 Thursday, July 30, 2015 8:48 AM
July 30th, 2015 8:45am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics