VMware Cloud Community
cstewart28
Contributor
Contributor

Documentation Report on all advanced settings in vCenter

Trying to set a list of all the advanced settings in vCenter for a "build-as" report in a 2 column format with a list of option and then the value. 

When trying to run this I get the information I want in the when I type $contents from the PS C:> prompt, but when I try to get in Word I get a bunch of VMWare.VIim.OptionDef[] and vmware.vim.optionvalue[]

Also get an error: method invocation failed because doesn't contain a method named 'op_addition'

Still learning, but here is what I have and help would be greatly appreciated:

$vcenter = '192.168.0.1'

Connect-VIServer -Server $vcenter

$vcenterSettings = get-View -Id 'OptionManager-VpxSettings'

$settings = @()

foreach ($settings in $vcenterSettings)

{

$a = "" | Select-object SupportedOption,Setting

$a.SupportedOption = $settings.SupportedOption

$a.Setting = $Settings.Setting

$settings += $a

}

$Contents = @($a.SupportedOption,$a.Setting)

$ColumnHeaders = @('Option','Setting')

$ColumnProperties = @('Option','Setting')

$columncount = $columnHeaders.Count

$msWord = New-Object -ComObject Word.Application

$wordDoc = $msWord.Documents.Add()

$msWord.Visible = $true

$wordDoc.Activate()

$doctable = $wordDoc.Tables.Add($wordDoc.Application.Selection.Range,$contents.Count,$Columncount)

for($col =0; $col -lt $columncount; col++)

{

$cell = $doctable.cell(1,$col+1).Range

$cell.font.bold = $true

$cell.InsertAfter($columnHeaders[$col])

}

#Insert Data into 1st Row

for ($row =0; $row -le ($contents.count); $row++)

{

$cell = $doctable.cell($row,1).Range

$cell.font.bold = $false

$cell.Text = $contents[$row -1]

}

#Insert Data into 2nd row

for ($row =0; $row -le ($contents.count); $row++)

{

$cell = $doctable.cell($row,2).Range

$cell.font.bold = $false

$cell.Text = $contents[$row -1]

}

#Table formatting stuff

$doctable.columns.autofit()

$objSelection = $msWord.Selection

$msWord.Selection.EndKey(6) > Null

$objSelection = TypeParagraph()

$msWord.Selection.EndKey(6) > Null

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

You're using the same variable name for the array that will hold the report, and for the index variable of the ForEach loop.

Change on of the names

$settings = @()

foreach ($settings in $vcenterSettings)

You are trying to assign an array to the Word selection range.

But Word doesn't know how to handle the row objects in your array called $Contents.

That's why you see the name of the objecttype in the Word document.

The screen output formatter does know how to display the contents of the array, that is why the screen output works.

Try something like this instead

$cell.Text = $contents[$row -1].Key

and

$cell.Text = $contents[$row -1].Value


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

Reply
0 Kudos
cstewart28
Contributor
Contributor

I changed the foreach($settings to $b to clear that up.  I also tried to add the .key and .value, but those options were not available form the drop down (I'm using PowerGUI as my editor).

I get the same response the cells are populated with VMware.Vim.OptionDEF[] in column 1 and Vmware.vim.opitonvalue[] in column 2.

When I look at the variable $contents it shows @{supportedoption=VMware.Vim.OptionDef[];Setting=Vmware.vim.opiotnvlaue[]}

Reply
0 Kudos
LucD
Leadership
Leadership

That indicates you have arrays under the 2 properties in the object.

Do a

$contents | Format-Custom -Depth 3

That should give you a better view of the object and it's properties.

The OptionDef object and the optionValue objects each have their own properties.

This

$contents.Settings[0].Key

$contents.Settings[0].Value

should give you the settings.

You will have to run through all elements of the array.


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

Reply
0 Kudos
cstewart28
Contributor
Contributor

I see that I was trying to combine two differnet arrays into one output, so I need to make two different tables one for each array output.

I have made the following changes it now have 3 columns to hold all the informaiton from the OptionDep object, but now I get nothing in the rows.

$settings = @()

foreach ($a in $vcenterSettings)

{

$b = "" | Select-object OptionDef

$b.key = $a.key

$b.label = $a.label

$b.summary = $a.summary

$settings += $b

}

Then on the row 1

for ($row =0; $row -le ($contents.Count); $row++)

{

$cell = $doctable.cell($row,1).range

$cell.text = $contents.Settings[0].key

}

Then for row 2 everything about and change

$cell.text = $contents.settings[0].label

Th for Row 3

$cell.text = $contents.settings[0].summary

Reply
0 Kudos