VMware

John Tuffin's Blog

April 2008

Previous Next
0

Here is how you can use PowerShell to create a virtual machine:

get-vmhost ESX1 | new-vm -name `

"First VM User N" -memorymb 256 `

-diskmb 1024 -pool `

(get-resourcepool studentN-esx1) `

-location (get-folder studentN)

0 Comments Permalink
0

Returning the product information about the ESX host with a simple command

Get-VMHost | % { (Get-View $_.ID).Config.Product }

0 Comments Permalink
0

Thanks to LucD on the forum for showing me this little trick today. To prompt for a username and password in get-viserver pass a -credentials argument to the command. For example

get-viserver <Virtual Center Server Name> -Credentials (get-credential)

that will prompt for a username and password rather than having to put it into the script.

0 Comments Permalink
0

I found this little bit code useful on the forums. It returns a list of virtual machines and their mac addresses.

<code>Get-VM | select name, @{Name="MAC"; expression={foreach($nic in (Get-View $_.ID).guest.net) {$nic.macAddress}}} </code>

Note that the forums are putting the code tags in front of and at the end of the line of code. That is not part of the actual code that you run in Powershell

0 Comments Permalink
0

PowerShell and VMware Server

Posted by cpqarray VMware Apr 8, 2008

I just discovered that the Vmware VI Toolkit for Windows will work with VMware Server 2.0 Beta 2 as well with Virtual Infrastructure. I was able to connect with the command:

get-viserver <VMware Server Name> -port 8333 -user <User Name> -password <Password>

Then I was able to run the power commands as well as the new-snapshot command.

0 Comments Permalink
1

I found this while surfing the forums this little bit of code will place an ESX Host in maintenance mode. I wonder what other values might exist for the -State switch?

Get-VMHost -Name <hostname> | Set-VMHost -State maintenance

1 Comments Permalink
3

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>

3 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
Click to view cpqarray's profile Member since: Nov 24, 2005

John Tuffin's Personal Log about E-Learning Course Development

View cpqarray's profile

Communities