VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

convert-html command

Hi luc ,

can yu please check html command to get proper output .

$path1 = 'D:\hc'

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

#(get-credential).password | ConvertFrom-SecureString | set-content "$path1\password.txt"

$password = Get-Content "$path1\password.txt" | ConvertTo-SecureString

$credential = New-Object System.Management.Automation.PsCredential("administrator@vsphere.local",$password)

connect-viserver -server "vcenter01" -Credential $credential

$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>

'@

$esxi=get-vmhost

$deviated_esxi=@()

foreach($e in $esxi)

{

$v=get-vmhost -Name $e

$accountunlocktime_minutes=(Get-AdvancedSetting -Entity $v -Name Security.AccountUnlockTime).value/60

if($accountunlocktime_minutes -ne "60"){

[PSCustomObject]@{

                esxinmae = $v

               

                accountunlocktime_minutes=$accountunlocktime_minutes

               

               

            }

            $deviated_esxi += $v

            }

}

$deviated_esxi|ConvertTo-Html -Property name -Fragment -PreContent '<h2>esxiwithlockdowntime not60mins </h2>' |

   Out-String

   ConvertTo-HTML -head $head -PostContent $deviated_esxi |

   Out-String | Out-File -FilePath $path

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If I understand correctly what you are trying to do, you should probably do

$path1 = 'D:\hc'

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

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

$password = Get-Content "$path1\password.txt" | ConvertTo-SecureString

$credential = New-Object System.Management.Automation.PsCredential("administrator@vsphere.local",$password)

connect-viserver -server "vcenter01" -Credential $credential


$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>

'@


$deviated_esxi=@()


foreach($e in Get-VMHost)

{

    $accountunlocktime_minutes=(Get-AdvancedSetting -Entity $e -Name Security.AccountUnlockTime).value/60

    if($accountunlocktime_minutes -ne "60"){

        $deviated_esxi += [PSCustomObject]@{

            esxiname = $e.Name

            accountunlocktime_minutes=$accountunlocktime_minutes

        }

    }

}

$frag = $deviated_esxi|

    ConvertTo-Html -Property esxiname -Fragment -PreContent '<h2>esxiwithlockdowntime not60mins </h2>' |

    Out-String


ConvertTo-HTML -head $head -PostContent $frag |

Out-String | Out-File -FilePath $path


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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

If I understand correctly what you are trying to do, you should probably do

$path1 = 'D:\hc'

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

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

$password = Get-Content "$path1\password.txt" | ConvertTo-SecureString

$credential = New-Object System.Management.Automation.PsCredential("administrator@vsphere.local",$password)

connect-viserver -server "vcenter01" -Credential $credential


$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>

'@


$deviated_esxi=@()


foreach($e in Get-VMHost)

{

    $accountunlocktime_minutes=(Get-AdvancedSetting -Entity $e -Name Security.AccountUnlockTime).value/60

    if($accountunlocktime_minutes -ne "60"){

        $deviated_esxi += [PSCustomObject]@{

            esxiname = $e.Name

            accountunlocktime_minutes=$accountunlocktime_minutes

        }

    }

}

$frag = $deviated_esxi|

    ConvertTo-Html -Property esxiname -Fragment -PreContent '<h2>esxiwithlockdowntime not60mins </h2>' |

    Out-String


ConvertTo-HTML -head $head -PostContent $frag |

Out-String | Out-File -FilePath $path


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

jvm2016
Hot Shot
Hot Shot
Jump to solution

its still giving info in single row .

i want one column with header esxi name and below that names of esxi

esxinames

esxi1

esxi2

esxi3

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which is the output I'm getting.
Check your copy

out.png


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

very strange now i m getting this .if yu can suggest whats is wrong with my code .

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which code, the original code you posted?


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

yes

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Besides some minor issues, the main issue was that you used the Property parameter on the ConvertTo-Html cmdlet, while you were not presenting objects with properties to that cmdlet, but strings.
So that Property parameter didn't take anything.


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i want to add some other conditions in this report .for the time being i added following

if password length of root is not 16 characters(orange code ) it should print in the report .

can you please check if that has been added correctly to report

$path1 = 'D:\compliance'

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

#$path = "D:\Temp\compliance-$(Get-Date -Format 'yyyyMMdd-HHmm').html"

(get-credential).password | ConvertFrom-SecureString | set-content "$path1\password.txt"

$password = Get-Content "$path1\password.txt" | ConvertTo-SecureString

$credential = New-Object System.Management.Automation.PsCredential("administrator@vsphere.local",$password)

connect-viserver -server "ukpnnhvcsa001.ibm-infra.local" -Credential $credential

$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:violet; }

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

table { margin-left:50px; }

</style>

'@

$deviated_esxi=@()

foreach($e in Get-VMHost)

{

    $accountunlocktime_minutes=(Get-AdvancedSetting -Entity $e -Name Security.AccountUnlockTime).value/60

    if($accountunlocktime_minutes -ne "60"){

        $deviated_esxi += [PSCustomObject]@{

            esxiname = $e.Name

            accountunlocktime_minutes=$accountunlocktime_minutes

        }

    }

}

$frag = $deviated_esxi|

    ConvertTo-Html -Property esxiname -Fragment -PreContent '<h2>esxiwithlockdowntime not60mins </h2>' |

    Out-String

$esxi_pasword_length=read-host "please provide password for one of the esxi"

if($esxi_pasword_length.Length -ne "16")

{

write-host "password length is not as per agreed value "

$esxi_pasword_length.Length|

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

    Out-String

}

ConvertTo-HTML -head $head -PostContent $frag |

Out-String | Out-File -FilePath $path

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have to provide an object, or array of objects, to the ConvertTo-Html cmdlet.
You also have to specify it concerns a fragment.

$path1 = 'D:\compliance'

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

$password = Get-Content "$path1\password.txt" | ConvertTo-SecureString


$credential = New-Object System.Management.Automation.PsCredential("administrator@vsphere.local",$password)


connect-viserver -server "ukpnnhvcsa001.ibm-infra.local" -Credential $credential


$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:violet; }

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

table { margin-left:50px; }

</style>

'@


$deviated_esxi=@()

foreach($e in Get-VMHost)

{

    $accountunlocktime_minutes=(Get-AdvancedSetting -Entity $e -Name Security.AccountUnlockTime).value/60

    if($accountunlocktime_minutes -ne "60"){

        $deviated_esxi += [PSCustomObject]@{

            esxiname = $e.Name

            accountunlocktime_minutes=$accountunlocktime_minutes

        }

    }

}


$frag1 = $deviated_esxi|

    ConvertTo-Html -Property esxiname -Fragment -PreContent '<h2>esxiwithlockdowntime not60mins </h2>' |

    Out-String


$esxi_pasword_length=read-host "please provide password for one of the esxi"

if($esxi_pasword_length.Length -ne "16")

{

    write-host "password length is not as per agreed value "

    $frag2 = New-Object -Type PSObject -Property @{

        length = $esxi_pasword_length.Length

        } |

    ConvertTo-Html -Property length -FragMent -PreContent '<h2>paswordlength </h2>' |

    Out-String

}


ConvertTo-HTML -head $head -PostContent $frag1,$frag2 |

Out-String | Out-File -FilePath $path


Invoke-Item $path


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

jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks Luc .

i am going to ask other conditions in next post referring to this script only .i need to to add more to it to get proper compliance report .

thanks again ..

Reply
0 Kudos