Automation

 View Only
  • 1.  vCenter licenses deatils

    Posted Nov 06, 2015 01:38 PM

    Hi All,

    Thanks in advance regarding to Audit my ESXi environment I required the Licenses details in following format. I tried with merging two script available in internet, but not getting the correct info.Any help will be much appreciated.I am attaching the script and excepted file output.

    Thanks

    Siv



  • 2.  RE: vCenter licenses deatils

    Posted Nov 06, 2015 06:58 PM

    Hi,

    Any good reasons for this specific format?


    It would be much easier to extract two files.
    One with all vCenter licenses.
    Another one that provides for each host the vCenter and the license associated.

    Then you will be in position to import the two files in two separate sheet in one excel file for example.



  • 3.  RE: vCenter licenses deatils

    Posted Nov 07, 2015 02:43 AM

    Hi ,

    Thanks for the reply, the format i am looking for in specific format is  to report my customer through the email  with this report attached.

    if even i can get a single file with those output is also fine.

    Thanks again.

    Siv



  • 4.  RE: vCenter licenses deatils

    Posted Nov 07, 2015 01:34 PM

    How about an html report?

    The CSS/HTML part of this code is inspired from http://hostilecoding.blogspot.no/2014/03/vmware-fancy-html-reports-using-powercli.html

    $PathToSaveTheReport = "C:\temp\Report.html"

    $vCenterName = "testvCenter"

    Connect-VIServer -Server $vCenterName

    $ServiceInstance = Get-View ServiceInstance

    $LicenseManager = Get-View $ServiceInstance.Content.LicenseManager

    $licenseAssignmentManager = Get-View $LicenseManager.licenseAssignmentManager

    #Get VC license Information

    $vCenterInformation= $LicenseManager.licenses | select @{Name="vCenter";Expression={$vCenterName}},Name,LicenseKey,Used,Total | ConvertTo-HTML -Fragment

    #Get Host license Information

    $HostInformation = Get-View -ViewType HostSystem | foreach-object{

    $AssignedLicense = ($licenseAssignmentManager.QueryAssignedLicenses($_.Moref.Value)).AssignedLicense

                $Output = New-Object -Type PSObject -Prop ([ordered]@{

                'vCenterName' = $vCenterName

                'Hostname' = $_.Name

                'version' = $_.Config.Product.Version

                'MemorySize' = $_.Hardware.MemorySize

                'core_num' =$_.Hardware.CpuInfo.NumCpuCores

                'cpu_num' =$_.Hardware.cpuinfo.Numcpupackages

                'Boottime' = $_.Summary.Runtime.BootTime

                'licenseKey' = $AssignedLicense.LicenseKey

                'Name' = $AssignedLicense.name

                })         

                Return $Output

    }| ConvertTo-HTML -Fragment

    #This is the CSS used to add the style to the report

    $Css="<style>

    body {

        font-family: Verdana, sans-serif;

        font-size: 14px;

        color: #666666;

        background: #FEFEFE;

    }

    #title{

        color:#90B800;

        font-size: 30px;

        font-weight: bold;

        padding-top:25px;

        margin-left:35px;

        height: 50px;

    }

    #subtitle{

        font-size: 11px;

        margin-left:35px;

    }

    #main {

        position:relative;

        padding-top:10px;

        padding-left:10px;

        padding-bottom:10px;

        padding-right:10px;

    }

    #box1{

        position:absolute;

        background: #F8F8F8;

        border: 1px solid #DCDCDC;

        margin-left:10px;

        padding-top:10px;

        padding-left:10px;

        padding-bottom:10px;

        padding-right:10px;

    }

    #boxheader{

        font-family: Arial, sans-serif;

        padding: 5px 20px;

        position: relative;

        z-index: 20;

        display: block;

        height: 30px;

        color: #777;

        text-shadow: 1px 1px 1px rgba(255,255,255,0.8);

        line-height: 33px;

        font-size: 19px;

        background: #fff;

        background: -moz-linear-gradient(top, #ffffff 1%, #eaeaea 100%);

        background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#ffffff), color-stop(100%,#eaeaea));

        background: -webkit-linear-gradient(top, #ffffff 1%,#eaeaea 100%);

        background: -o-linear-gradient(top, #ffffff 1%,#eaeaea 100%);

        background: -ms-linear-gradient(top, #ffffff 1%,#eaeaea 100%);

        background: linear-gradient(top, #ffffff 1%,#eaeaea 100%);

        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eaeaea',GradientType=0 );

        box-shadow:

            0px 0px 0px 1px rgba(155,155,155,0.3),

            1px 0px 0px 0px rgba(255,255,255,0.9) inset,

            0px 2px 2px rgba(0,0,0,0.1);

    }

    table{

        width:100%;

        border-collapse:collapse;

    }

    table td, table th {

        border:1px solid #98bf21;

        padding:3px 7px 2px 7px;

    }

    table th {

        text-align:left;

        padding-top:5px;

        padding-bottom:4px;

        background-color:#90B800;

    color:#fff;

    }

    table tr.alt td {

        color:#000;

        background-color:#EAF2D3;

    }

    </style>"

    #These are divs declarations used to properly style HTML using previously defined CSS

    $PageBoxOpener="<div id='box1'>"

    $ReportVClicense="<div id='boxheader'>vcenter license</div>"

    $BoxContentOpener="<div id='boxcontent'>"

    $PageBoxCloser="</div>"

    $br="<br>" #This should have been defined in CSS but if you need new line you could also use it this way

    $ReportEsxiLicense="<div id='boxheader'>ESXi license</div>"

    #Create HTML report

    #-Head parameter could be omitted if header is declared in body

    ConvertTo-Html -Title "Test Title" -Head "<div id='title'>PowerCLI Reporting</div>$br<div id='subtitle'>Report generated: $(Get-Date)</div>" -Body " $Css $PageBoxOpener $ReportVClicense $BoxContentOpener $vCenterInformation $PageBoxCloser $br $ReportEsxiLicense $BoxContentOpener $HostInformation $PageBoxCloser"  | Out-File $PathToSaveTheReport



  • 5.  RE: vCenter licenses deatils

    Posted Nov 08, 2015 06:24 AM

    Hi sir,

    Thanks for your reply & much appreciated for the effort.

    The scripts show the output of the 1st part but the 2nd part is not working as excepted and gives the result blank. I am getting the below error. Please let me know if any parameter is missing.

    Error

    Unable to find type [ordered]: make sure that the assembly containing this type

    is loaded.

    At C:\Users\Administrator\Desktop\vSphere-lic.ps1:15 char:65

    +             $Output = New-Object -Type PSObject -Prop ([ordered] <<<< @{

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

        + FullyQualifiedErrorId : TypeNotFound

    Error

    Thanks in Advance



  • 6.  RE: vCenter licenses deatils

    Posted Nov 08, 2015 01:47 PM

    it works perfectly after upgrading the power shell version from 2 to 4.

    Thanks for the good effort.