This code will get all of the host names in a cluster, parse the names (if you use FQDN for your hostnames), and rename the default “datastore1” to “hostname-local” format
This will help resolve the issue of having a lot of “datastore1 (99)” showing in your Datastores view.
***Note, if you use the word “datastore1” for other storage locations or have a host with more than one local storage device named “datastore1” this may explode.

$hostnames = get-cluster mycluster | get-vmhost | %{$_.name}
foreach($ahost in $hostnames){
$one1 = $ahost.split(“.”)
$two2 = $one1[0]
$thename = $two2+”-local”
get-vmhost $ahost | get-datastore | where {$_.name -match “datastore1”} | set-datastore -name $thename
}

Vmware Link:
http://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/Set-Datastore.html

This will work for a standard switch and only if a vswitch is already configured.
If you want to create the vSwitch first, check this post >http://www.pcli.me/?p=28

###Edit the four vars and paste the script.

$thecluster = “MyCluster”
$vswitch = “vSwitch1”
$PG = “MyProdNetwork”
$vlan = “1337”

$thehosts = get-cluster $thecluster | get-vmhost | %{$_.name}
foreach($ahost in $thehosts){
New-VirtualPortGroup -VirtualSwitch ( Get-VirtualSwitch -Name $vswitch -VMHost $ahost ) -Name $PG -VLanId $vlan
}

##########################################

If you need the portgroup to contain a vmKernel for vmotion, use the following instead:
#######  Set the four cluster vars then the hash table for the different vmkernel IP addresses
$thecluster = “MyCluster”
$vswitch = “vSwitch1”
$PG = “vmotion0”
$vlan = “0”

####### Create the vmk IP hashtable #######

$myvmkips = @{}
$myvmkips.add(“host1.pcli.me”,”10.10.10.10″)
$myvmkips.add(“host2.pcli.me”,”10.10.10.11″)
.
.
.
$myvmkips.add(“host9.pcli.me”,”10.10.10.19″)
####### end hashtable #######

 

$thehosts = get-cluster $thecluster | get-vmhost | %{$_.name}
foreach($ahost in $thehosts){
New-VirtualPortGroup -VirtualSwitch ( Get-VirtualSwitch -Name $vswitch -VMHost $ahost ) -Name $PG -VLanId $vlan
$vmkip = $myvmkips.get_item(“ahost”)
New-VMHostNetworkAdapter -VMHost $ahost -VirtualSwitch $vswitch -PortGroup $PG” -IP $vmkip -SubnetMask 255.255.255.0 -VMotionEnabled $true -Confirm:$false
}

 

Vmware Links:
VirtualPortGroup – http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/New-VirtualPortGroup.html
VMHostNetworkAdapter = http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/New-VMHostNetworkAdapter.html

This will enable vmotion on an existing vmkernel portgroup for all hosts in a cluster.
If you want to create the port group first, check this post > http://www.pcli.me/?p=16

$ClusterName = “MyCluster”
$MyPortGroup = “MyPortGroup”
get-cluster $ClusterName | Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | where {$_.PortGroupName -eq $MyPortGroup} | Set-VMHostNetworkAdapter -VMotionEnabled $true -Confirm:$false

This runs slow and you cannot use a “-RunAsync” to make it faster.

Vmware Link:
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-VMHostNetworkAdapter.html