VMware Cloud Community
jt30605
Contributor
Contributor
Jump to solution

Simple question about views from a PowerShell beginner

Why is -MoRef needed in the script for setting up new virtual switches from the FAQ page? I guess I don't understand what -MoRef means. Could someone explain or point me to a document?

$HS = Find-EntityView -ViewType "HostSystem"

$nwSys = $HS.ConfigManager.NetworkSystem

$mor = Get-View -MoRef $nwSys

$networkConfig = New-Object Vmware.Vim.HostNetworkConfig

$vswtch = New-Object VMware.Vim.HostVirtualSwitchConfig

$networkConfig.vswitch = @($vswtch)

$networkConfig.vswitch[0].name = "SwitchName"

$spec = New-Object Vmware.Vim.HostVirtualSwitchSpec

$spec.numPorts = 1

$portgrp = New-Object VMware.Vim.HostPortGroupConfig

$networkConfig.portgroup = @($portgrp)

$portgropspec = New-Object VMware.Vim.HostPortGroupSpec

$portgropspec.vswitchName = "SwitchName"

$portgropspec.Name = "SwitchNamePort"

$portgropspec.Policy = New-Object VMware.Vim.HostNetworkPolicy

$networkConfig.vswitch[0].spec = $spec

$networkConfig.portgroup[0].spec = $portgropspec

$mor.AddVirtualSwitch("SwitchName",$spec ) $mor.AddPortGroup($portgropspec)

Thanks,

Jaime

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

MoRef stands for Managed Object Reference.

It is a pointer to the objects, also called inventory objects, that are the internal building blocks used by VI.

Attached to these objects are properties (data) and methods (functions) that allow one to manipulate (create, change, remove..) the objects.

The currently best explanation, till Hal's book is published Smiley Wink, can be found in the SDK 2.5 Programming Guide in chapter 2 in the section titled Managed Object Types.

And there is of course the main page in the SDK 2.5 API reference that gives a good explanation.

That's the shortest description I could manage.

In the script you retrieve a pointer to the HostNetworkSystem via the HostSystem object.

You use the AddVirtualSwitch method that is available on a HostNetworkSystem object to create the virtual switch.


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

MoRef stands for Managed Object Reference.

It is a pointer to the objects, also called inventory objects, that are the internal building blocks used by VI.

Attached to these objects are properties (data) and methods (functions) that allow one to manipulate (create, change, remove..) the objects.

The currently best explanation, till Hal's book is published Smiley Wink, can be found in the SDK 2.5 Programming Guide in chapter 2 in the section titled Managed Object Types.

And there is of course the main page in the SDK 2.5 API reference that gives a good explanation.

That's the shortest description I could manage.

In the script you retrieve a pointer to the HostNetworkSystem via the HostSystem object.

You use the AddVirtualSwitch method that is available on a HostNetworkSystem object to create the virtual switch.


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

0 Kudos
jt30605
Contributor
Contributor
Jump to solution

Cool, thanks for the explanation!

0 Kudos