new1234.jpg

Archive

Posts Tagged ‘Script’

VMware: Disable HotPlug capability for virtual machines with PowerCLI

January 16th, 2016 2 comments

Last week I had to change VMX files for 500 XenDesktop machines because the users where able to eject removable devices

To mass disable HotPlug capability by editing the .vmx file via PowerCLI I used the following script:

$key = "devices.hotplug"
$value = "false"
get-cluster "CL02.XD" | get-VM -Name 000-CXD* | foreach {
  $vm = Get-View $_.Id
  $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
  $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
  $vmConfigSpec.extraconfig[0].Key=$key
  $vmConfigSpec.extraconfig[0].Value=$value
  $vm.ReconfigVM($vmConfigSpec)
}


Optional (manual) options:

You can disable HotPlug capability using the vSphere Client or by editing the .vmx file.
Note: You can disable HotPlug capability for PCI devices such as e1000 or vmxnet3 NICs.
To disable HotPlug capability using the vSphere Client:

  1. Connect to the ESXi/ESX host or vCenter Server using the vSphere Client.
  2. Power off the virtual machine.
  3. Right-click the virtual machine and click Edit Settings.
  4. Click the Options tab.
  5. Click General > Configuration Parameters > Add Row.
  6. Insert a new row with the name devices.hotplug and a value of false.
  7. Power on the virtual machine.

To disable HotPlug capability using the vSphere Web Client:

  1. From a web browser, connect to the vSphere Web Client.
  2. Log in with Administrator credentials.
  3. Navigate to the virtual machine you want to modify.
  4. Right-click the virtual machine and select Edit Settings.
  5. Click the VM Options tab.
  6. Click Advanced > Edit Configuration > Add Row.
  7. Insert a new row with the name devices.hotplug and a value of false.
  8. Power on the virtual machine.

To disable HotPlug capability by editing the .vmx file:

  1. Power off the virtual machine.
  2. Access the ESXi/ESX service console using an SSH client.
  3. Open the virtual machine configuration file (.vmx) in a text editor. The default location is:
    /vmfs/volumes/datastore_name/vm_name/vm_name.vmx
  4. Add the line:
    devices.hotplug = "false"
    Note: This setting does not interfere with HotPlug CPU/memory.
  5. Save and close the file.
  6. Power on the virtual machine.
    More information:

VMware

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Configure new vSphere 6 host with PowerCLI

August 17th, 2015 2 comments

Last week I upgraded my original Configure vSphere 4 PowerCLI script I created in 2011 . When you run the script with PowerShell ICE or PowerCLI you have two options: 1. Configure a new vSphere 6 host. 2. Add the new configured host to vCenter Server. I’m still not a PowerCLI Pro so.. please comment if you have any tips or suggestions.

Benefits:

— When you use this script, the script is your vSphere configuration documentation
— You don’t need a license for Host Profiles or revert temporary to Evaluation Mode
— Fresh (new) host configuration takes ~10 minutes
— vSphere Host configuration standardization
— Easy add variables during deployment
— Easy GUI menu

 

Function:

Menu option: 1 – Configure new vSphere host

— Connect to the target ESXi Host
— Enter Maintenance mode
— Set Hostname and Domain name
— Configure DNS settings
— Configure NTP settings
— Configuring Simple Network Management Protocol (SNMP)
— Delete the default VM Network
— Configure vSwitch0 – Management / vMotion
— Configure vSwitch1 – Production Network
— Configure vSwitch2 – iSCSI
— Configure vSwitch3 – iSCSI
— Install Software iSCSI Initiator
— Configure iSCSI target address
— Configure iSCSI initiator name
— Enable iSCSI Initiator
— Rescan on all HBAs and Rescan for VMFS volumes
— Exit Maintenance Mode

Menu option: 2 – Configure new vSphere host to vCenter Server

— Connect vCenter server
— Add vSphere Host to vCenter server
— Re-balance Cluster

Menu option: 0 – Quit

 


Script upgraded for hardware setup:

Host

— Type: Dell PowerEdge R630
— Network: 6x 10 GB
— Storage: flash (2×8 GB)
— Memory: 256 GB
— CPU:  2x E5-2660 v3

Storage

— Dell Compellent SC4020 (iSCSI)

Network

— DellForce 10


Script:

#====================================================================#
#   SCRIPT:        VMP_Configure_new_vSphere6_Host_with_Menu.ps1     #
#   FUNCTION:      Configure fresh installed host                    #
#   CREATED:       05/07/2011                                        #
#   MODIFIED:      17/08/2015                                        #
#   OWNER:         S.Daems / VMpros.nl                               #
#   VERSION:       v.1.7                                             #
#====================================================================#
#   CHANGELOG:                                                       #
#                                                                    #
#   v.1.7                                                            #
#                                                                    #
#    - Script upgraded to vSphere 6.0                                #
#    -- Updated obsolete commands (vSphere 6 proof)                  #
#    - Install and configure 10GB iSCSI storage network              #
#    -- Configure iSCSI initiator                                    #
#    -- Configure iSCSI initator IQN name                            #
#    - Updated and configure SMNP                                    #
#    - Updated DNS settings                                          #
#    - Updated Custom Definitions field                              #
#    - Updated Network Configuration parameters                      #
#                                                                    #
#   USAGE:                                                           #
#                                                                    #
#    - Edit script in Windows PowerShell ISE / Notepad ++            #
#    - Add static values in "Custom Definitions" section             #
#    - Run script with Windows PowerShell ISE or PowerCLI 6.0        #                                                                    #
#    - Answer dynamic values during script                           #                                                                 #
#    - Enjoy!                                                        #
#                                                                    #
#                                                                    #
#   NOTE:                                                            #
#                                                                    #
#    - Run this script only on a empty vSphere 6 host                #
#    - Check if the correct pNIC's are configured for NIC Teaming    #
#    - This script is written with VMware vSphere PowerCLI 6.0       #
#                                                                    #
#                                                                    #
#====================================================================#
#   MENU                                                             #
#====================================================================#
do {
 
Write-Host "Please make your choice:" -foregroundcolor yellow
Write-Host " 1. Configure new vSphere host"
Write-Host " 2. Configure new vSphere host to vCenter Server"
Write-Host " 0. Quit"
Write-Host " "
$response = Read-Host "Select 0-2"
Write-Host " "
 
switch ($response)
{
1 {
#====================================================================#
#   HOST = CUSTOM DEFINITIONS                                        #
#====================================================================#
$ESX_host = read-host "Select ESXi host by DNS to connect"
$New_hostname = read-host "Select hostname to configure"
$New_domainname = "VMpros.lan"
$Root_user = "root"
$Root_password = "VMpros#2015!"
$DNS01 = "10.32.17.5"
$DNS02 = "10.32.17.6"
$VMK01 = read-host "Select iSCSI VMkernel 01 IP-address to configure"
$VMK02 = read-host "Select iSCSI VMkernel 02 IP-address to configure"
$VLAN01_label = "VMP-VLAN200"
$VLAN02_label = "VMP-VLAN300"
$VLAN03_label = "VMP-VLAN400"
$VLAN04_label = "VMP-VLAN500"
$VLAN05_label = "VMP-VLAN600"
$VLAN06_label = "VMP-VLAN700"
$VLAN01_id = "200"
$VLAN02_id = "300"
$VLAN03_id = "400"
$VLAN04_id = "500"
$VLAN05_id = "600"
$VLAN06_id = "700"
$iSCSI_sub = "255.255.255.0"
$iSCSI_target_A = "172.45.21.40"
$iSCSI_target_B = "172.45.22.40"
$vMotion_ip = read-host "Select vMotion VMkernel IP-address to configure"
$vMotion_sub = "255.255.255.0"
$NTP01 = "0.nl.pool.ntp.org"
$NTP02 = "1.nl.pool.ntp.org"
$MTU = "9000"
#
#
#
#====================================================================#
# ***LOAD PLUGINS***                                                 #
#====================================================================#
Add-PSSnapin vmware.vimautomation.core
#====================================================================#
#
#
#
#====================================================================#
Write-Host "-- vSphere Host-configuration starting..." -foregroundcolor yellow
#====================================================================#
Write-Host "-- Connect to the target ESXi Host" -foregroundcolor green
#====================================================================#
Set-PowerCLIConfiguration -invalidCertificateAction "ignore" -confirm:$false | out-null
Connect-VIServer "$ESX_host" -User "$Root_user" -Password "$Root_password" | out-null
Start-Sleep -Seconds 10
#--------------------------------------------------------------------#
Write-Host "-- Enter Maintenance mode" -foregroundcolor green | out-null
#--------------------------------------------------------------------#
Get-VMHost | Set-VMHost -State maintenance | out-null
#--------------------------------------------------------------------#
#
#
#
#====================================================================#
# ***CONFIGURE HOST SETTINGS***                                      #
#====================================================================#
Write-Host "-- Set Hostname and Domain name" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHostNetwork | Set-VMHostNetwork -DomainName $New_domainname -HostName $New_hostname | out-null
Start-Sleep -Seconds 10
#--------------------------------------------------------------------#
Write-Host "-- Configure DNS settings" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress "$DNS01" , "$DNS02" -SearchDomain "$New_domainname" | out-null
#--------------------------------------------------------------------#
Write-Host "-- Configure NTP settings" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHost | Add-VmHostNtpServer -NtpServer "$NTP01" , "$NTP02" | out-null
Get-VMHost | Get-VMHostFirewallException | where {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true | out-null
Get-VMHost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService | out-null
Get-VMhost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "automatic" | out-null
#--------------------------------------------------------------------#
Write-Host "-- Configuring Simple Network Management Protocol (SNMP)" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHostSNMP | Set-VMhostSnmp -ReadOnlyCommunity 'public' | out-null
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true | out-null
#--------------------------------------------------------------------#
#
#
#
#====================================================================#
# ***CONFIGURE NETWORK SWITCHES***                                   #
#====================================================================#
Write-Host "-- Delete the default VM Network" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VirtualPortGroup -Name "VM Network" | Remove-VirtualPortGroup -Confirm:$false | out-null
#--------------------------------------------------------------------#
Write-Host "-- Configure vSwitch0 - Management / vMotion" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VirtualSwitch -Name vSwitch0 | Set-VirtualSwitch -Nic vmnic0,vmnic7 -Confirm:$false | out-null
New-VMHostNetworkAdapter -PortGroup vMotion -VirtualSwitch vSwitch0 -IP "$vMotion_ip" -SubnetMask "$vMotion_sub" -vMotionEnabled:$true -Confirm:$false | out-null
Get-virtualportgroup -name vMotion | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic7 | out-null
Get-virtualportgroup -name vMotion | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic0 | out-null
Get-virtualportgroup -name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic7 | out-null
Get-virtualportgroup -name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0 | out-null
#--------------------------------------------------------------------#
Write-Host "-- Configure vSwitch1 - Production Network" -foregroundcolor green
#--------------------------------------------------------------------#
New-VirtualSwitch -Name vSwitch1 -Nic vmnic4,vmnic6 -Confirm:$false | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "$VLAN01_label" -VLANID "$VLAN01_id" | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "$VLAN02_label" -VLANID "$VLAN02_id" | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "$VLAN03_label" -VLANID "$VLAN03_id" | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "$VLAN04_label" -VLANID "$VLAN04_id" | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "$VLAN05_label" -VLANID "$VLAN05_id" | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "$VLAN06_label" -VLANID "$VLAN06_id" | out-null
#--------------------------------------------------------------------#
Write-Host "-- Configure vSwitch2 - iSCSI" -foregroundcolor green
#--------------------------------------------------------------------#
New-VirtualSwitch -Name vSwitch2 -Nic vmnic5 -MTU $MTU | out-null
New-VMHostNetworkAdapter -PortGroup "iSCSI01" -VirtualSwitch vSwitch2 -IP $VMK01 -SubnetMask "$iSCSI_sub" -MTU "$MTU" | out-null
#--------------------------------------------------------------------#
Write-Host "-- Configure vSwitch3 - iSCSI" -foregroundcolor green
#--------------------------------------------------------------------#
New-VirtualSwitch -Name vSwitch3 -Nic vmnic1 -MTU $MTU | out-null
New-VMHostNetworkAdapter -PortGroup "iSCSI02" -VirtualSwitch vSwitch3 -IP $VMK02 -SubnetMask "$iSCSI_sub" -MTU "$MTU" | out-null
#------------------------------------------------------------------
#
#
#
#=====================================================================#
# ***CONFIGURE STORAGE***                                             #
#=====================================================================#
Write-Host "-- Install Software iSCSI Initiator" -foregroundcolor green
#---------------------------------------------------------------------#
Get-VMHostStorage $ESX_host | Set-VMHostStorage -SoftwareIScsiEnabled $false | out-null
Start-Sleep -Seconds 15 
#---------------------------------------------------------------------#
Write-Host "-- Configure iSCSI target address" -foregroundcolor green
#---------------------------------------------------------------------#
$iSCSI_HBA = Get-VMHost | Get-VMHostHba | Where {$_.Type -eq "Iscsi"} | Where {$_.Model -eq "iSCSI Software Adapter"}
Get-VMHostHba "$iSCSI_HBA" | New-IScsiHbaTarget -Address "$iSCSI_target_A" | out-null
Get-VMHostHba "$iSCSI_HBA" | New-IScsiHbaTarget -Address "$iSCSI_target_B" | out-null
#---------------------------------------------------------------------#
Write-Host "-- Configure iSCSI initiator name" -foregroundcolor green
#---------------------------------------------------------------------#
Get-VMHost | Get-VMHostHba | Where {$_.Type -eq "Iscsi"} | Where {$_.Model -eq "iSCSI Software Adapter"} | Set-VMHostHba -IScsiName "iqn.1998-01.com.vmware$ESX_host" | out-null
#---------------------------------------------------------------------#
Write-Host "-- Enable iSCSI Initiator" -foregroundcolor green
#---------------------------------------------------------------------#
Get-VMHostStorage $ESX_host | Set-VMHostStorage -SoftwareIScsiEnabled $True | out-null
#---------------------------------------------------------------------#
Write-Host "-- Rescan on all HBAs and Rescan for VMFS volumes" -foregroundcolor green
#---------------------------------------------------------------------#
Get-VMHostStorage -VMHost $ESX_host -RescanAllHba | out-null
Get-VMHostStorage -VMHost $ESX_host -RescanVmfs | out-null
#---------------------------------------------------------------------#
#
#
#
#=====================================================================#
# ***FINISHING CONFIGURATION***                                       #
#=====================================================================#
Write-Host "-- Exit Maintenance Mode" -foregroundcolor green
#---------------------------------------------------------------------#
Get-VMHost | Set-VMHost -State connected | out-null
#---------------------------------------------------------------------#
#
#
#
Write-Host "vSphere Host-configuration has finished.." -foregroundcolor yellow
break;
}
2 {
#====================================================================#
#   vCenter - CUSTOM DEFINITIONS                                     #
#====================================================================#
$vCenter_server = read-host "Select vCenter server to connect"
$vCenter_administrator = read-host "Select vCenter Administrator"
$vCenter_password = read-host "Select vCenter Administrator password"
$vCenter_cluster = read-host "Select Cluster to add host"
Write-Host "vSphere Host will be added in vCenter server..." -foregroundcolor Green
#====================================================================#
Write-Host "Connect to the target vCenter server" -foregroundcolor green
#====================================================================#
Connect-VIServer "$vCenter_server" -User "$vCenter_administrator" -Password "$vCenter_password"
#====================================================================#
Add-VMHost $ESX_host -Force -Location (Get-Cluster "$vCenter_cluster") -User root -Password "$Root_password" | out-null
#====================================================================#
#
#
#
#====================================================================#
# ***FINISHING CONFIGURATION***                                      #
#====================================================================#
Write-Host "Re-balance VMs in cluster using DRS" -foregroundcolor green
#====================================================================#
Get-DrsRecommendation -Cluster (Get-Cluster "$vCenter_cluster") -Refresh | out-null
#====================================================================#
#
#
#
Write-Host "Host is added to vCenter Server.." -foregroundcolor yellow
break;
}
}
 
}
while ($response -ne "0")

 

 

Script output:

image

 

 

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Migrate vSphere hosts to new ip subnet, new DNS servers, new gateway and rejoin vCenter server with PowerCLI

January 30th, 2012 12 comments

Last month I’ve wrote a script for a company that is merging with a new company in a different datacenter, that means new ip-addresses, new subnet, new gateway, new DNS servers and rejoin vCenter server.. my part was to migrate all (60) VMware vSphere hosts to the new subnet and rejoin the vSphere vCenter cluster… without downtime!

Function:

#Connect to vCenter server
— Specify host
— Enter Host Standby mode
— Move all VM’s to other hosts in cluster
— Re-balance with DRS
— Disconnect host
— Remove host from cluster

#Connect to ESXi Server
— Add new VMKernel Management Network with new range in vSwitch0
— Enable Management option for new VMkernel
— Configure NIC Teaming policy
— Configure new DNS servers
— Configure new VMkernel gateway
— Reboot host

#MANUAL ACTION: Update DNS records at configured DNS servers

#Connect to vCenter server
— Add new record in vCenter server host file with new host ipaddress Management VMkernel
— Add host with new VMkernel Management Network
— Delete old VMkernel from vSwitch0
— Exit Host Standby mode
— Rebalance cluster with DRS

#Script finished
— Next host…>


The script
:

#====================================================================#
#   SCRIPT:       VMware_vSphere_IP_Redesign_v.1.0.ps1               #
#   AUTHOR:       S.Daems - VMpros.nl                                #
#   CREATED:      22/01/2012                                         #
#   MODIFIED:     30/01/2012                                         #
#   VERSION:      v.1.0                                              #
#                                                                    #
#====================================================================#
#   CHANGELOG:                                                       #
#                                                                    #
#    v.1.0                                                           #
#     - Script created                                               #
#                                                                    #
#====================================================================#
#   FUNCTION:                                                        #
#                                                                    #
#   #Connect to vCenter server                                       #
#     Specify host                                                   #
#     Enter Host Standby mode                                        #
#     Move all VM's to other hosts in cluster                        #
#     Re-balance with DRS                                            #
#     Disconnect host                                                #
#     Remove host from cluster                                       #
#                                                                    #
#   #Connect to ESXi Server                                          #
#     Add new VMKernel Management Network with new range in vSwitch0 #
#     Enable Management option for new VMkernel                      #
#     Configure NIC Teaming policy                                   #
#     Configure new DNS servers                                      #
#     Configure new VMkernel gateway                                 #
#     Reboot host                                                    #
#                                                                    #
#   #MANUAL ACTION: Update DNS records at configured DNS servers     #
#                                                                    #
#   #Connect to vCenter server                                       #
#     Add new record in vCenter server host file with new host ip-   #
#     address Management VMkernel                                    #
#     Add host with new VMkernel Management Network                  #
#     Delete old VMkernel from vSwitch0                              #
#     Exit Host Standby mode                                         #
#     Rebalance cluster with DRS                                     #
#                                                                    #
#   #Script finished                                                 #
#     Next host...>                                                  #
#                                                                    #
#====================================================================#
#   NOTE:                                                            #
#                                                                    #
#     - Run this script first in a test environment                  #
#     - Make sure youre ESXi host - vSwitch0 have multiple pNIC's    #
#       and can access both networks/gateway's                       #
#     - Don't forgot to update vCenter Cluster das.isolationaddress2 #
#       if vCenter is configured in a new subnet                     #
#     - Don't forgot to update DNS (A) records at your DNS servers   #
#       with with new ESXi host Management ip-addresses              #
#     - Check if the correct pNIC's are configured for NIC Teaming   #
#     - Check if the correct VMkernel is selected for gateway config #
#     - This script is written with VMware vSphere PowerCLI 5.0.0    #
#                                                                    #
#====================================================================#
#   CUSTOM DEFINITIONS                                               #
#====================================================================#
$vCenterServer = "vCENTER SERVER NAME BY DNS"
$vCenterUsername = "vCENTER DOMAIN\USERNAME"
$vCenterPassword = "vCENTER PASSWORD"
$vCenterDatacenter = "vCENTER DATACENTER NAME"
$vCenterCluster = "vCENTER CLUSTERNAME"
$ESXiHost = "ESXi HOSTS BY DNS"
$RootUser = "ROOT USER ACCOUNT TO CONFIGURE/CONNECT HOST"
$RootPassword = "ROOT PASSWORD TO CONFIGURE/CONNECT HOST"
$Old_MGMT_Network = "ORIGINAL MANAGEMENT VMKERNEL NAME"
$New_MGMT_Network = "NEW MANAGEMENT VMKERNEL IPADDRESS"
$New_MGMT_Subnet = "NEW MANAGEMENT VMKERNEL SUBNET"
$New_VMK_Gateway = "NEW MANAGEMENT VMKERNEL GATEWAY"
$New_DNS01 = "NEW PRIMARY DNS SERVER TO CONFIGURE"
$New_DNS02 = "NEW SECUNDARY DNS SERVER TO CONFIGURE"
New-VICredentialStoreItem -Host "$vCenterServer" -User "$vCenterUsername" -Password "$vCenterPassword" | out-null
New-VICredentialStoreItem -Host "$ESXiHost" -User "$RootUser" -Password "$RootPassword" | out-null
Write-Host "Script will start..." -foregroundcolor yellow

#====================================================================#
#   FASE 1  - vCENTER: MAINTENANCE AND REMOVE HOST FROM vCENTER      #
#====================================================================#
Write-Host "Connect to vCenter Server" -foregroundcolor green
#====================================================================#
Connect-VIServer "$vCenterServer" | out-null
Sleep 10
#====================================================================#
Write-Host "Enter host in Maintenance mode" -foregroundcolor green
#====================================================================#
Set-VMHost "$ESXiHost" -State "Maintenance" -RunAsync | out-null
#====================================================================#
Write-Host "Disconnect host from vCenter Server" -foregroundcolor green
#====================================================================#
Set-VMHost "$ESXiHost" -State "Disconnected" -RunAsync | out-null
#====================================================================#
Write-Host "Tell DRS to re-balance VMs including the rejoined host" -foregroundcolor green
#====================================================================#
Get-DrsRecommendation -Cluster "$vCenterCluster" | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation | out-null
#====================================================================#
Write-Host "Remove host from vCenter Server" -foregroundcolor green
#====================================================================#
Remove-VMHost "$ESXiHost" -Confirm:$false | out-null
#====================================================================#
Write-Host "Disconnect from vCenter Server" -foregroundcolor green
#====================================================================#
Disconnect-VIServer -Confirm:$False | out-null

#====================================================================#
#   FASE 2 - HOST: RE-CONFIGURE MANAGEMENT NETWORK                   #
#====================================================================#
Write-Host "Connect directly to ESXi host" -foregroundcolor green
#====================================================================#
Connect-VIServer "$ESXiHost" | out-null
Sleep 10
#====================================================================#
Write-Host "Configure new management network" -foregroundcolor green
#====================================================================#
Get-VMHost "$ESXiHost" | New-VMHostNetworkAdapter -VirtualSwitch "vSwitch0" -PortGroup "MGMT Network" -IP "$New_MGMT_Network" -SubnetMask "$New_MGMT_Subnet" -ManagementTrafficEnabled:$true -Confirm:$false | out-null
#====================================================================#
Write-Host "Configure vSwitch0 - MGMT NIC Teaming Policy" -foregroundcolor green
#====================================================================#
Get-VMHost "$ESXiHost" | Get-VirtualPortGroup -name "MGMT Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0 | out-null
Get-VMHost "$ESXiHost" | Get-VirtualPortGroup -name "MGMT Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic2 | out-null
#====================================================================#
Write-Host "Configure new DNS servers" -foregroundcolor green
#====================================================================#
Get-VMHost "$ESXiHost" | Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress "$New_DNS01","$New_DNS02" | out-null
#====================================================================#
Write-Host "Change VMkernel Gateway" -foregroundcolor green
#====================================================================#
$net = Get-VMHostNetwork
$net | Set-VMHostNetwork -VMKernelGateway "$New_VMK_Gateway" -VMKernelGatewayDevice "vmk2" | out-null
#====================================================================#
Write-Host "Reboot ESXi Host" -foregroundcolor green
#====================================================================#
Restart-VMHost -VMHost "$ESXiHost" -Confirm:$false | out-null
#====================================================================#
Write-Host "Disconnect from ESXi host" -foregroundcolor green
#====================================================================#
Disconnect-VIServer -Confirm:$False | out-null
Write-Host "Update DNS (A) records at you're Domain Controller with new ESXi ipaddress, otherwise the script will fail..!!" -foregroundcolor white
Write-Host "Update DNS (A) records at you're Domain Controller with new ESXi ipaddress, otherwise the script will fail..!!" -foregroundcolor white
Write-Host "Update DNS (A) records at you're Domain Controller with new ESXi ipaddress, otherwise the script will fail..!!" -foregroundcolor white
Sleep 360

#====================================================================#
#   FASE 3  - vCENTER: EXIT MAINTENANCE AND RE-ADD HOST TO vCENTER   #
#====================================================================#
Write-Host "Connect to vCenter Server" -foregroundcolor green
#====================================================================#
Connect-VIServer "$vCenterServer" | out-null
Sleep 10
#====================================================================#
Write-Host "New Management Network to vCenter Server host file" -foregroundcolor green
#====================================================================#
$hostsPath = “$env:windir\System32\drivers\etc\hosts”
$hosts = get-content $hostsPath
$string = “$New_MGMT_Network             $ESXiHost”
$hosts = $hosts + $string
$hosts | Out-File $hostsPath -enc ascii
#====================================================================#
Write-Host "Add ESXi host to vCenter Server" -foregroundcolor green
#====================================================================#
Add-VMHost "$ESXiHost" -location (Get-Datacenter -name "$vCenterDatacenter" | Get-Cluster -name "$vCenterCluster") -user root -password $RootPassword -force | out-null
#====================================================================#
Write-Host "Remove old Management Network from host" -foregroundcolor green
#====================================================================#
#$vNic = Get-VMHostNetworkAdapter -VMHost $ESXiHost | where {$_.PortgroupName -eq $Old_MGMT_Network} | out-null
#Remove-VMHostNetworkAdapter -Nic $vNic | out-null
#====================================================================#
Write-Host "Exit host from Maintenance mode" -foregroundcolor green
#====================================================================#
Set-VMHost "$ESXiHost" -State "Connected" -RunAsync | out-null
#====================================================================#
Write-Host "Tell DRS to re-balance VMs including the rejoined host" -foregroundcolor green
#====================================================================#
Get-DrsRecommendation -Cluster "$vCenterCluster" | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation | out-null
#====================================================================#
Write-Host "Disconnect from vCenter Server" -foregroundcolor green
#====================================================================#
Disconnect-VIServer -Confirm:$False | out-null

#====================================================================#
#   FASE 4  - SCRIPT FINISHED                                        #
#====================================================================#
Write-Host "Script finished, please check error log..." -foregroundcolor yellow
#====================================================================#

The script is finished:

image

Custom settings:

$vCenterServer = "vCENTER SERVER NAME BY DNS"
$vCenterUsername = "vCENTER DOMAIN\USERNAME"
$vCenterPassword = "vCENTER PASSWORD"
$vCenterDatacenter = "vCENTER DATACENTER NAME"
$vCenterCluster = "vCENTER CLUSTERNAME"
$ESXiHost = "ESXi HOSTS BY DNS"
$RootUser = "ROOT USER ACCOUNT TO CONFIGURE/CONNECT HOST"
$RootPassword = "ROOT PASSWORD TO CONFIGURE/CONNECT HOST"
$Old_MGMT_Network = "ORIGINAL MANAGEMENT VMKERNEL NAME"
$New_MGMT_Network = "NEW MANAGEMENT VMKERNEL IPADDRESS"
$New_MGMT_Subnet = "NEW MANAGEMENT VMKERNEL SUBNET"
$New_VMK_Gateway = "NEW MANAGEMENT VMKERNEL GATEWAY"
$New_DNS01 = "NEW PRIMARY DNS SERVER TO CONFIGURE"
$New_DNS02 = "NEW SECUNDARY DNS SERVER TO CONFIGURE"


sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Easy menu to find VM network adapter by MAC address

November 1st, 2011 6 comments

Last week I need to locate some traffic from physical switches to my virtual environment.. I need to find out which MAC address belong to which virtual machine (+ adapter).. time to script this include menu

#====================================================================#
#   SCRIPT:        Find_VM_by_MAC_address_menu.ps1                   #
#   FUNCTION:      Find VM (+ adapter) by MAC address with easy menu #
#   OWNER:         Sander Daems                                      #
#   CREATED:       11/01/2011                                        #
#   MODIFIED:      11/01/2011                                        #
#   VERSION:       v.1.0                                             #
#====================================================================#
#   CHANGELOG:                                                       #
#                                                                    #
#    v.1.0                                                           #
#	 - Created script;                                               #
#                                                                    #
#====================================================================#
#   HOST - CUSTOM DEFINITIONS                                        #
#====================================================================#
Write-Host "Let's find that damn address" -foregroundcolor green
#====================================================================#
$cluster = read-host "Select Cluster name"
$macaddress = read-host "Select MAC Address to find"
#====================================================================#
#   Script                                                           #
#====================================================================#
Get-Cluster $cluster | Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress -eq "$macaddress"} | Format-List -Property *
#====================================================================#

image

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Configure new vSphere 4 host with PowerCLI

July 5th, 2011 No comments

I’ve created a PowerCLI script that can be used to configure a vSphere 4 host with a custom configuration. And you can select in the menu to configure the host (option 1) + you can select (option 2) to add the host into a cluster on a vCenter Server. I’ll update this post with new configurations/versions, I’m still a PowerCLI beginner so.. please comment if you have any tips or suggestions.

Menu:

1. Configure new vSphere host:

– Connect vSphere host;
– Enter maintenance;
– Set the hostname and domain name;
– Configure DNS settings;
– Configure NTP Server;
– Configure Support User;
– Enable the software iSCSI initiator;
– Delete the default VM Network;
– Configure vSwitch0 – Management / vMotion (incl. failover en load balancing);
– Configure vSwitch1 – Network;
– Configure vSwitch2 – iSCSI (incl.VMkernels + failover en load balancing);
– Configure iSCSI target address;
– Exit Maintenance Mode

2. Configure new vSphere host to vCenter Server

– Connect vCenter server;
– Add vSphere Host to vCenter server;
– Re-Balance Cluster

0. Quit

The script: [updated: 07/07/2011 – v.1.5]

#====================================================================#
#   SCRIPT:        Configure_new_ESXi_Host_Menu.ps1                  #
#   FUNCTION:      Configure fresh installed host                    #
#   CREATED:       05/07/2011                                        #
#   MODIFIED:      07/07/2011                                        #
#   VERSION:       v.1.5                                             #
#====================================================================#
#   CHANGELOG:                                                       #
#                                                                    #
#    v.1.5                                                           #
#	 - Added answer field to configure host;                         #
#	 - Added start menu: config host and add to vCenter server       #
#	 - Hide config output, show's only when failure;                 #
#                                                                    #
#====================================================================#
# START MENU                                                         #
#====================================================================#
do {

Write-Host "Please make your choise:" -foregroundcolor yellow
Write-Host " 1. Configure new vSphere host"
Write-Host " 2. Configure new vSphere host to vCenter Server"
Write-Host " 0. Quit"
Write-Host " "
$response = Read-Host "Select 0-2"
Write-Host " "

switch ($response)
{
1 {
#====================================================================#
#   HOST = CUSTOM DEFINITIONS                                        #
#====================================================================#
$ESX_host = read-host "Select ESXi host by DNS to connect"
$newhostname = read-host "Select hostname to configure"
$newdomainname = read-host "Select domain name to configure"
$root_user = "root"
$root_password = read-Host "Select root password to connect"
$new_user = read-host "Select extra username to configure"
$new_user_password = read-Host "Select extra password to configure"
$dns01 = read-host "Select Primary DNS to configure"
$dns02 = read-host "Select Secundary DNS to configure"
$VMK01 = read-host "Select iSCSI VMkernel01 to configure"
$VMK02 = read-host "Select iSCSI VMkernel02 to configure"
$iSCSIsub = read-host "Select iSCSI Subnet Mask to configure"
$iSCSItarget = read-host "Select iSCSI target to configure"
$vMotiontcp = read-host "Select vMotion VMkernel to configure"
$vMotionsub = read-host "Select vMotion Subnet Mask to configure"
$NTPServer01 = "0.pool.ntp.org"
$NTPServer02 = "1.pool.ntp.org"
Write-Host "vSphere Host-configuration will begin..." -foregroundcolor Green
#====================================================================#
Write-Host "Connect to the target ESXi Host" -foregroundcolor green
#====================================================================#
Connect-VIServer "$ESX_host" -User "$root_user" -Password "$root_password"
Sleep 10
#--------------------------------------------------------------------#
Write-Host "Enter Maintenance mode" -foregroundcolor green | out-null
#--------------------------------------------------------------------#
Get-VMHost | Set-VMHost -State maintenance | out-null
#--------------------------------------------------------------------#
#
#
#====================================================================#
# ***CONFIGURE HOST SETTINGS***                                      #
#====================================================================#
Write-Host "Set the hostname and domain name" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHostNetwork | Set-VMHostNetwork -DomainName $newdomainname -HostName $newhostname | out-null
Sleep 10
#--------------------------------------------------------------------#
Write-Host "Configure DNS settings" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress $dns01 | out-null
#--------------------------------------------------------------------#
Write-Host "Configure NTP Server" -foregroundcolor green
#--------------------------------------------------------------------#
Add-VmHostNtpServer -NtpServer "$NTPServer01" , "$NTPServer02" | out-null
#--------------------------------------------------------------------#
Write-Host "Configure Support User" -foregroundcolor green
#--------------------------------------------------------------------#
New-VMHostAccount -Id "$new_user" -password "$new_user_password" -Description "Tech Support" -AssignGroups root -GrantShellAccess | out-null
#--------------------------------------------------------------------#
#
#
#====================================================================#
# ***CONFIGURE NETWORK***                                            #
#====================================================================#
Write-Host "Delete the default VM Network" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VirtualPortGroup -Name "VM Network" | Remove-VirtualPortGroup -Confirm:$false | out-null
#--------------------------------------------------------------------#
Write-Host "Configure vSwitch0 - Management / vMotion" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VirtualSwitch -Name vSwitch0 | Set-VirtualSwitch -Nic vmnic0,vmnic1 -Confirm:$false | out-null
New-VMHostNetworkAdapter -PortGroup vMotion -VirtualSwitch vSwitch0 -IP "$vMotiontcp" -SubnetMask "$vMotionsub" -vMotionEnabled:$true -Confirm:$false | out-null
get-virtualportgroup -name vMotion | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic1 | out-null
get-virtualportgroup -name vMotion | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic0 | out-null
get-virtualportgroup -name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic0 | out-null
get-virtualportgroup -name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic1 | out-null
#--------------------------------------------------------------------#
Write-Host "Configure vSwitch1 - Network" -foregroundcolor green
#--------------------------------------------------------------------#
New-VirtualSwitch -Name vSwitch1 -Nic vmnic2,vmnic3 -Confirm:$false | out-null
Get-VirtualSwitch -Name vSwitch1 |Set-VirtualSwitch -NumPorts "256" -Confirm:$false | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "VLAN-100-Production" -VLANID 100 | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "VLAN-200-Management" -VLANID 200 | out-null
Get-VirtualSwitch -Name vSwitch1 | New-VirtualPortGroup -Name "VLAN-300-DMZ" -VLANID 300 | out-null
#--------------------------------------------------------------------#
Write-Host "Configure vSwitch2 - iSCSI" -foregroundcolor green
#--------------------------------------------------------------------#
New-VirtualSwitch -Name vSwitch2 -Nic vmnic4,vmnic5 | out-null
New-VMHostNetworkAdapter -PortGroup "iSCSI01" -VirtualSwitch vSwitch2 -IP "$VMK01" -SubnetMask "$iSCSIsub" | out-null
New-VMHostNetworkAdapter -PortGroup "iSCSI02" -VirtualSwitch vSwitch2 -IP "$VMK02" -SubnetMask "$iSCSIsub" | out-null
get-virtualportgroup -name "iSCSI01" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic4 | out-null
get-virtualportgroup -name "iSCSI01" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic5 | out-null
get-virtualportgroup -name "iSCSI02" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic5 | out-null
get-virtualportgroup -name "iSCSI02" | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby vmnic4 | out-null
#--------------------------------------------------------------------#
#
#
#====================================================================#
# ***CONFIGURE STORAGE***                                            #
#====================================================================#
Write-Host "Configure iSCSI target address" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHost | Get-VMHostHba -Type iScsi | New-IScsiHbaTarget -Address "$iSCSItarget" | out-null
#--------------------------------------------------------------------#
Write-Host "Configure iSCSI initiator" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHostStorage | Set-VMHostStorage -SoftwareIScsiEnabled $True | out-null
#--------------------------------------------------------------------#
#
#
#====================================================================#
# ***FINISHING CONFIGURATION***                                      #
#====================================================================#
Write-Host "Exit Maintenance Mode" -foregroundcolor green
#--------------------------------------------------------------------#
Get-VMHost | Set-VMHost -State connected | out-null
#--------------------------------------------------------------------#
#
#
Write-Host "vSphere Host-configuration has finished.." -foregroundcolor yellow
break;
}
2 {
#====================================================================#
#   vCenter - CUSTOM DEFINITIONS                                     #
#====================================================================#
$vCenterServer = read-host "Select vCenter server to connect"
$vCenterAdministrator = read-host "Select vCenter Administrator"
$vCenterPassword = read-host "Select vCenter Administrator password"
$cluster = read-host "Select Cluster to add host"
Write-Host "vSphere Host will be added in vCenter server..." -foregroundcolor Green
#====================================================================#
Write-Host "Connect to the target vCenter server" -foregroundcolor green
#====================================================================#
Connect-VIServer "$vCenterServer" -User "$vCenterAdministrator" -Password "$vCenterPassword"
#====================================================================#
Add-VMHost $ESX_host -Force -Location (Get-Cluster "$cluster") -User root -Password "$root_password" | out-null
#====================================================================#
#
#
#====================================================================#
# ***FINISHING CONFIGURATION***                                      #
#====================================================================#
Write-Host "Tell DRS to re-balance VMs including the new host" -foregroundcolor green
#====================================================================#
Get-DrsRecommendation -Cluster (Get-Cluster "$cluster") -Refresh | out-null
#====================================================================#
#
#
Write-Host "Host is added to vCenter Server.." -foregroundcolor yellow
break;
}
}

}
while ($response -ne "0")

image

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Change Alarm-Actions with PowerCLI

July 4th, 2011 5 comments

I’m working on a project for a company that is running a big cloud datacenter, the organization is 24/7 and some of my colleagues need to monitor the environment week by week (standby shifts). Once a week we need to change some alarm actions to send the Alarm notifications to a different email address.. because it’s a lot of work to do this by hand I tried to script this.

You must change the email address value in the script.. and automatically change the rest of the definitions.

$MailToRandom1 = "alert_random@vmpros.nl"

Here’s my script:

#====================================================================#
#   SCRIPT:        Change_Alarm_Datacenter.ps1                       #
#   FUNCTION:      Modify multiple Alarm definitions in vCenter      #
#   CREATED:       10/06/2011                                        #
#   VERSION:       v.1.1                                             #
#====================================================================#
#   CHANGELOG:                                                       #
#                                                                    #
#    v.1.1                                                           #
#    - Deleted email body                                            #
#    - Added Alarm definition                                        #
#    - Added changelog                                               #
#                                                                    #
#    v.1.0                                                           #
#    - First Release                                                 #
#                                                                    #
#====================================================================#
# Note: You only have to change the "MailToRandom1" value in "Custom #
#         Definitions" to change the alarm action                    #
#====================================================================#
# Connect vCenter server;
#--------------------------------------------------------------------#
$vCenterServer = "vcenter-server"
$user = "username"
$pass = "password"

if ( $DefaultVIServers.Length -lt 1 )
{
  Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null
}

#--------------------------------------------------------------------#
# Custom Definitions;
#--------------------------------------------------------------------#
$actType = "SendEmailAction"
$MailToRandom1 = "alert_random@vmpros.nl"
$MailToDefault1 = "alert1@vmpros.nl"
$MailToDefault2 = "alert2@vmpros.nl"
$actAlarm1 = "Machine suspended"
$actAlarm2 = "Datastore usage"
$actAlarm3 = "Snapshot alarm"
$actSubject = "Get-AlarmDefinition"
#--------------------------------------------------------------------#
# Delete Alarm Trigger;
#--------------------------------------------------------------------#
Get-AlarmDefinition -Name "$actAlarm1" , "$actAlarm2" , "$actAlarm3" | Get-AlarmAction | Remove-AlarmAction -Confirm:$false
#--------------------------------------------------------------------#
# Create Alarm Trigger;
#--------------------------------------------------------------------#
Get-AlarmDefinition -Name "$actAlarm1" , "$actAlarm2" , "$actAlarm3" | New-AlarmAction -Email -To "$MailToRandom1" , "$MailToDefault1" , "$MailToDefault2"
Get-AlarmDefinition -Name "$actAlarm1" , "$actAlarm2" , "$actAlarm3" | Get-AlarmAction | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
#--------------------------------------------------------------------#
# Disconnect vCenter server;
#--------------------------------------------------------------------#
Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false
#--------------------------------------------------------------------#

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Add PortGroup to all hosts in cluster with PowerCLI

May 4th, 2011 14 comments

Today we configured a new VLAN on the physical switches, now we need to configure a portgroup with vlan id on multiple ESX hosts in our cluster. To do this by hand it will cost 3 minutes per host, to script this.. you configure this in 10 seconds!

The script:

Get-Cluster “clustername” | Get-VMHost | Get-VirtualSwitch -Name “vSwitch0” | New-VirtualPortGroup -Name “VLAN-23-Citrix Provisioning” -VLanId 23

image

image

Voila!

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Deploy multiple VM’s from template with PowerCLI

January 16th, 2011 30 comments

Last week I was working on a new project, they asked me to install 5 new fileservers based on Windows 2008R2, I installed a new VM and converted it to a template, next I configured a template in “Customization Specifications Manager” with the following details:

Customization template:

Registration information: name company

Computer name: Use the virtual machine name (important)

Product key: Didn’t need it because I’ve configured KMS

Password: Company default local administrator password, selected: Automatically login as the Administrator: 2

Timezone: GMT+0100 (Amsterdam)

Runonce: none

Network: Typical settings

Workgroup or Domain: selected to auto join the domain with domain administrator credentials + domain name (important)

Operation System Options: Selected: Generate New Security ID (SID)

VM template settings:

Hard disk: 40 GB with only OS configured with company standard policy

VMware tools: Latest, this must be installed for Specification Template and NIC

Network: VMXNET3 (needed VMware Tools for driver)

Script: (saved as: FileserverDeploy.ps1)

-vmhost = Target host;

-Name = Name of new VM;

-Template: From wich template you want to deploy the new VM;

-Datastore: Target datastore to place the new VM;

-OSCustomizationspec = Wich “prep” template you want to deploy the new VM;

New-vm -vmhost esx04.vmpros.local -Name FS-SVR01 -Template WIN2008R2_Template -Datastore datastore2 -OSCustomizationspec WIN2008R2_Template
New-vm -vmhost esx04.vmpros.local -Name FS-SVR02 -Template WIN2008R2_Template -Datastore datastore2 -OSCustomizationspec WIN2008R2_Template
New-vm -vmhost esx04.vmpros.local -Name FS-SVR03 -Template WIN2008R2_Template -Datastore datastore2 -OSCustomizationspec WIN2008R2_Template
New-vm -vmhost esx04.vmpros.local -Name FS-SVR04 -Template WIN2008R2_Template -Datastore datastore2 -OSCustomizationspec WIN2008R2_Template
New-vm -vmhost esx04.vmpros.local -Name FS-SVR05 -Template WIN2008R2_Template -Datastore datastore2 -OSCustomizationspec WIN2008R2_Template

PowerCLI:

Running the script:

image

image

image

Final result:

image

The 5 fileservers deployed from template and joined the domain.. great!

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

VMware: Purging old data from the database used by VirtualCenter Server (1000125)

February 18th, 2009 1 comment

VirtualCenter Server stores task, event, and performance data in the VirtualCenter database. Over time, data collection results in growth of the database files and a mechanism is needed to shrink these files. Although there is no feature in the product itself to purge or shrink old records from the database, it is possible to do so manually.

There are two variations of this solution, one for each of the supported VirtualCenter database platforms, Oracle and Microsoft SQL Server.

The attached scripts support purging the data from both VirtualCenter 2.0.x and VirtualCenter 2.5.x.

Note: The Oracle version of the scripts are not combined. When you extract the scripts, run the version of the script for the version of VirtualCenter that is in use.

For the solution check the source out.

Source: 1000125