{"id":571,"date":"2010-02-11T08:40:38","date_gmt":"2010-02-11T13:40:38","guid":{"rendered":"http:\/\/www.jasemccarty.com\/blog\/?p=571"},"modified":"2010-02-11T08:40:38","modified_gmt":"2010-02-11T13:40:38","slug":"esx-post-install-onfig-via-powercli","status":"publish","type":"post","link":"https:\/\/www.jasemccarty.com\/blog\/esx-post-install-onfig-via-powercli\/","title":{"rendered":"ESX Post install config via PowerCLI"},"content":{"rendered":"<p>Working from home yesterday, I saw a tweet, and linked blog post, by <strong><a title=\"VMware ESX Post installation configuration via PowerCLI\" href=\"http:\/\/www.ivobeerens.nl\/?p=509\" target=\"_blank\">Ivo Beerens<\/a><\/strong>, about configuring ESX via PowerCLI after the initial installation. Ivo has covered the bases pretty well for his environment.<\/p>\n<p>I recently wrote a PowerCLI script to do some of the same things, but I did choose a somewhat different approach.\u00a0 Our scripts differ in the following respects:<\/p>\n<ol>\n<li>My script is executed against the ESX host, and not against vCenter<\/li>\n<li>My script is geared toward a NetApp Filer as my backend storage<\/li>\n<li>My script operates as a menu, giving the flexibility to only configure one or more settings<\/li>\n<\/ol>\n<p>Now on to my script.\u00a0 I wrote this script knowing that I would have several hosts I needed to configure in a short amount of time.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n# ===============================================================\n#\u00a0\u00a0\u00a0 NAME: ConfigMenu.ps1\n#\u00a0 AUTHOR: Jase McCarty\n#\u00a0\u00a0\u00a0 DATE: 1\/28\/2010\n#\n# ===============================================================\n\n# Explain what the script does\nWrite-Host &quot;This script will allow for configuration of several &quot;\nWrite-Host &quot;different components of an ESX Host&quot;\n\n# Ask for the Host name or IP\n$ESXHOST = Read-Host &quot;Enter ESX Host Name or IP&quot;\nConnect-VIServer $ESXHOST\n\n# Setup Our Menu\ndo {\n\n# Select environment MENU\nWrite-Host &quot;*** Config Menu for $ESXHOST ***&quot;\nWrite-Host &quot;What task would you like to perform?&quot;\nWrite-Host &quot; 1. Adjust Service Console Memory&quot;\nWrite-Host &quot; 2. Adjust vSwtich0 Ports to 248&quot;\nWrite-Host &quot; 3. Add Port Groups to vSwitch0&quot;\nWrite-Host &quot; 4. Add VMKernel Port to vSwitch0 For VMotion Purpose&quot;\nWrite-Host &quot; 5. Add vSwitch1 for Storage Network&quot;\nWrite-Host &quot; 6. Update NFS &amp;amp; TCP settings for NFS Traffic&quot;\nWrite-Host &quot; 7. Update NTP Settings&quot;\nWrite-Host &quot; 8. Add Datastores to ESX Host&quot;\nWrite-Host &quot; 0. Quit&quot;\nWrite-Host &quot; &quot;\n$response = Read-Host &quot;Select 1-8&quot;\nWrite-Host &quot; &quot;\n\nswitch ($response)\n{\n1 {\n&quot;** Adjust the Service Console Memory Setting **&quot;;\nWrite-Host &quot;Setting Service Console Memory to 800MB&quot;;\n$consoleMemMb = 800;\nGet-VMHost | Get-View | %{(Get-View -Id $_.ConfigManager.MemoryManager).ReconfigureServiceConsoleReservation($consoleMemMb*1mb)};\nWrite-Host &quot;!!! The system will have to be rebooted for these settings to take place !!!&quot;;\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\n}\n2 {\n&quot;**Adjust Virtual Switch Ports for vSwitch0 to accomodate Many Virtual Machines **&quot;;\nGet-VMHost $ESXHOST | Get-VirtualSwitch -Name &quot;vSwitch0&quot; |Set-VirtualSwitch -NumPorts &quot;256&quot;;\nRead-Host &quot;Press return to continue...&quot;;\nClear-Host\nbreak;\n}\n3 {\n&quot;** Add Port Groups to vSwitch0 (Nics must be trunked) **&quot;;\nWrite-Host &quot;Adding Port Groups to vSwitch0&quot;;\n$NVPG = Get-VMHost $ESXHOST | Get-VirtualSwitch -Name &quot;vSwitch0&quot; | New-VirtualPortGroup -Name &quot;VLAN100&quot; -VLanId &quot;100&quot;;\n$NVPG = Get-VMHost $ESXHOST | Get-VirtualSwitch -Name &quot;vSwitch0&quot; | New-VirtualPortGroup -Name &quot;VLAN101&quot; -VLanId &quot;101&quot;;\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\n}\n4 {\n&quot;** Adding VMKernel Port to vSwitch0 For VMotion **&quot;;\nWrite-Host &quot;Adding VMKernel Port to vSwitch0 For VMotion&quot;;\n$VMOTIONIP = Read-Host &quot;Enter VMotion IP&quot;;\n$VMOTIONNM = Read-Host &quot;Enter VMotion Subnet Mask&quot;;\n$VMOTIONVLAN = Read-Host &quot;Enter VMotion VLAN&quot;;\n#Get-VMHost $ESXHOST | Get-VirtualSwitch -Name &quot;vSwitch0&quot;;\n$esxImpl = Get-VMHost $ESXHOST;\n$vSw0 = Get-VirtualSwitch -VMHost $esxImpl -Name vSwitch0;\nNew-VMHostNetworkAdapter -VMHost $esxImpl -PortGroup &quot;VMotion&quot; -VirtualSwitch $vSw0 -IP $VMOTIONIP -SubnetMask $VMOTIONNM -VMotionEnabled $true;\nSet-VirtualPortGroup -VirtualPortGroup &quot;VMotion&quot; -VlanId $VMOTIONVLAN\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\n}\n5 {\n&quot;**Add Second Virtual Switch to host for Storage Network **&quot;;\n$STORAGESCIP = Read-Host &quot;Enter Storage Service Console IP: &quot;;\n$STORAGESCNM = Read-Host &quot;Enter Storage Service Console NetMask: &quot;;\n$STORAGEVKIP = Read-Host &quot;Enter Storage VMKernel IP: &quot;;\n$STORAGEVKNM = Read-Host &quot;Enter Storage VMKernel NetMask: &quot;;\n\nWrite-Host &quot;Adding vSwitch1 to Host&quot;;\nGet-VMHost $ESXHOST | New-VirtualSwitch -Name &quot;vSwitch1&quot;;\n$esxImpl = Get-VMHost $ESXHOST;\n$vSw = Get-VirtualSwitch -VMHost $esxImpl -Name vSwitch1;\nSet-VirtualSwitch -VirtualSwitch $vsW -Nic vmnic1,vmnic2\nNew-VMHostNetworkAdapter -VMHost $esxImpl -PortGroup &quot;StorageSC&quot; -VirtualSwitch $vSw -IP $STORAGESCIP -SubnetMask $STORAGESCNM -ConsoleNic;\nNew-VMHostNetworkAdapter -VMHost $esxImpl -PortGroup &quot;StorageVMKernel&quot; -VirtualSwitch $vSw -IP $STORAGEVKIP -SubnetMask $STORAGEVKNM;\n\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n6 {\n&quot;**Update NFS\/TCP Settings for NFS Traffic **&quot;;\nWrite-Host &quot;Updating TCP and NFS Advanced Configuration Settings&quot;;\nSet-VMHostAdvancedConfiguration -VMHost $ESXHOST -Name Net.TcpipHeapSize -Value 30;\nSet-VMHostAdvancedConfiguration -VMHost $ESXHOST -Name Net.TcpipHeapMax -Value 120;\nSet-VMHostAdvancedConfiguration -VMHost $ESXHOST -Name NFS.MaxVolumes -Value 64;\nSet-VMHostAdvancedConfiguration -VMHost $ESXHOST -Name NFS.HeartbeatMaxFailures -Value 10;\nSet-VMHostAdvancedConfiguration -VMHost $ESXHOST -Name NFS.HeartbeatTimeout -Value 5;\nSet-VMHostAdvancedConfiguration -VMHost $ESXHOST -Name NFS.HeartbeatFrequency -Value 12;\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\n}\n7 {\n&quot;**Update NTP Settings **&quot;;\nWrite-Host &quot;Updating NTP Server Values&quot;;\nAdd-VMHostNtpServer -NtpServer &quot;ntp1.domain.com&quot;;\nAdd-VMHostNtpServer -NtpServer &quot;ntp2.domain.com&quot;;\nGet-VmhostFirewallException -Name \u201cNTP Client\u201c\u00a0 |Set-VMHostFirewallException -enabled:$true;\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\n}\n\n8 {\n&quot;**Add Datastores to ESX Host **&quot;;\nWrite-Host &quot;Adding Datastores to ESX Host&quot;;\nGet-VMHost | New-Datastore -Nfs -NAME nfs_datastore -Path \/vol\/nfs_datastore -NfsHost x.x.x.x;\nRead-Host 'Press return to continue...';\nClear-Host\nbreak;\n}\n0 {\n&quot;** Exiting Script **&quot;;\nWrite-Host &quot;Quit&quot;;\nbreak;\n}\ndefault {\n&quot;** The selection could not be determined **&quot;;\nbreak;\n}\n}\n\n}\nwhile ($response -ne &quot;0&quot;)\n<\/pre>\n<p>As can be seen, I am performing some of the same tasks as Ivo&#8217;s script.\u00a0 The script can be easily modified to fit just about any environment.\u00a0 I have not yet added the snippets of code to update vmnic load balancing, failover, etc&#8230;\u00a0 But it is on the way.<\/p>\n<p>Again, use this script only after sufficient testing.\u00a0 And as always, use of this script does not make me liable for any modifications to your environment.<\/p>\n<div id=\"_mcePaste\" style=\"overflow: hidden; position: absolute; left: -10000px; top: 1309px; width: 1px; height: 1px;\">$NVPG = Get-VMHost $ESXHOST | Get-VirtualSwitch -Name &#8220;vSwitch0&#8221; | New-VirtualPortGroup -Name &#8220;VLAN100&#8221; -VLanId &#8220;100&#8221;;<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Working from home yesterday, I saw a tweet, and linked blog post, by Ivo Beerens, about configuring ESX via PowerCLI after the initial installation. Ivo &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[65,111],"class_list":["post-571","post","type-post","status-publish","format-standard","hentry","category-virtualization","tag-powercli","tag-vsphere"],"_links":{"self":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/comments?post=571"}],"version-history":[{"count":0,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/571\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/media?parent=571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/categories?post=571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/tags?post=571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}