VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

powercli_script_structure

Hi Luc,

can yu please check following code  specifically orange code to get information about os type of vcenter.for some reasons i m not getting right output.

$path1 = 'D:\hc'

$path = "D:\hc\additional-$(Get-Date -Format 'yyyyMMdd-HHmm').html"

Connect-VIServer -server "vcenter1" -Credential $credentials

$head = @'

<style>

body { background-color:#dddddd;

       font-family:Tahoma;

       font-size:12pt; }

td, th { border:1px solid black;

         border-collapse:collapse; }

th { color:white;

     background-color:black; }

table, tr, td, th { padding: 2px; margin: 0px }

table { margin-left:50px; }

</style>

'@

$fragments = @()

$vc=$global:defaultviserver

$ostype=$vc.ExtensionData.Content.about.ostype

$fragments += $ostype |

   ConvertTo-Html -PreContent '<h2>ostype </h2>' |

   Out-String

$embeddedorexternal=$global:DefaultVIServer |

Select Name,

    @{N='PSC';E={

        $pscUri = Get-AdvancedSetting -Entity $_ -Name config.vpxd.sso.admin.uri | select -ExpandProperty Value

        if(([System.Uri]$_.ServiceUri).Host -eq ([System.Uri]$pscUri).Host){'Embedded'}else{'External'}

    }}

$fragments += $embeddedorexternal |

   ConvertTo-Html -PreContent '<h2>embeddedorexternal </h2>' |

   Out-String

   ConvertTo-HTML -head $head -PostContent $fragments |

   Out-String | Out-File -FilePath $path

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The ConvertTo-Html cmdlet expects an object, where it converts the properties to column headers and the values to entries under that column.
And you're presenting it with a string.

Try that part like this

$vc=$global:defaultviserver

$ostype= $vc.ExtensionData.Content.about | Select ostype

$fragments += $ostype |

   ConvertTo-Html -Property ostype -PreContent '<h2>ostype </h2>' |

   Out-String

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

The ConvertTo-Html cmdlet expects an object, where it converts the properties to column headers and the values to entries under that column.
And you're presenting it with a string.

Try that part like this

$vc=$global:defaultviserver

$ostype= $vc.ExtensionData.Content.about | Select ostype

$fragments += $ostype |

   ConvertTo-Html -Property ostype -PreContent '<h2>ostype </h2>' |

   Out-String

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Tx I m checking.

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks  Luc,

I changed to what you suggest to make it pscustom object.

however in second part iam not giving properties (though it is pscustom object )

$embeddedorexternal=$global:DefaultVIServer |

Select Name,

    @{N='PSC';E={

        $pscUri = Get-AdvancedSetting -Entity $_ -Name config.vpxd.sso.admin.uri | select -ExpandProperty Value

        if(([System.Uri]$_.ServiceUri).Host -eq ([System.Uri]$pscUri).Host){'Embedded'}else{'External'}

    }}

$fragments += $embeddedorexternal |

   ConvertTo-Html -PreContent '<h2>embeddedorexternal </h2>' |

   Out-String

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, I know.
I'm afraid that is a "feature" of ConvertTo-Html.
If there is only 1 property in an object, and you don't use the Property parameter, the header of that property will be shown as an *

issue.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks.

0 Kudos