VMware Communities > Blogs > John Tuffin's Blog > 2008 > April

Blog Posts

John Tuffin's Blog : April 02, 2008

Previous Next

2

This bit of code takes the output from Get-Datastore and converts it from megabytes to Gigabytes. It also labels the columms as FreespaceGB and CapacityGB. This is from the forums as well.


<code>Get-Datastore | ft name,@{ Label = "FreespaceGB"; Expression = { $_.FreeSpaceMB * 1MB / 1GB } }, @{ Label = "CapacityGB"; Expression = { $_.CapacityMB * 1MB / 1GB } } </code>

2 Comments Permalink
0

This little snippet of PoweShell Code will create a virtual switch on an ESX Host. I found this while hunting through the VMware comunities for why I couldn't create a portgroup with Powershell. Using this code I was able to create a Virtual Switch called vSwitch1 with a VM portgroup called Production. I still have no idea what the policy setting does or do I know of any other values that could go there.

$ESXhost = "sc-gallium04.pso.vmware.com"

$vSwitch = "vSwitch1"

$user = "scriptuser"

$password = "vmware"

$VC = "10.18.138.187"

*
Get-VIServer $VC -User $user -Password $password

*

$NewSwitch = New-VirtualSwitch -vmhost (*Get-VMHost* $ESXhost ) -Name $vSwitch -NIC "vmnic1"

$net = Get-View(Get-View(*Get-VMHost* -Name $ESXHost).ID).configmanager.networksystem

$PortgroupSpec = New-Object vmware.Vim.hostportgroupspec

$PortgroupSpec.vswitchname = $vSwitch

$PortgroupSpec.Name = "Production"

$PortgroupSpec.policy = New-Object vmware.Vim.HostNetworkPolicy

$net.AddPortgroup($PortGroupSpec)

0 Comments Permalink