This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $strNewVPG = "newVirtualPortGroup" | |
| $strNewVlanTag = "123" | |
| $ObjAllHosts = Get-VMHost | Sort-Object -Property Name | |
| ForEach($objHost in $ObjAllHosts){ | |
| $strVSwitch = Get-Virtualswitch -VMHost (Get-VMHost $objHost) | Where-Object { $_.Name -like "VMswitch" } | |
| Write-Host "Adding Virtual Port Group $strNewVPG with VLAN Tag $strNewVlanTag to $objHost" | |
| New-VirtualPortGroup -Name $strNewVPG -VirtualSwitch $strVSwitch -VLanId $strNewVlanTag | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $strOldVPG = "OldVPGName" | |
| $strNewVPG = "NewVPGName" | |
| $ObjAllHosts = (Get-VMHost | Sort-Object -Property Name) | |
| ForEach($objHost in $ObjAllHosts){ | |
| Write-Host "Changing Virtual Port Group Settings on" $objHost | |
| $strVSwitch = Get-Virtualswitch -VMHost (Get-VMHost -Name $objHost) | Where-Object { $_.Name -match "VMswitch" } | |
| $objOldVPG = Get-VirtualPortGroup (Get-VMHost -Name $objHost) | Where-Object { $_.Name -match $strOldVPG } | |
| Write-Host "Removing Virtual Port Group" $objOldVPG | |
| Remove-VirtualPortGroup -VirtualPortGroup $objOldVPG -Confirm:$false -WhatIf | |
| Write-Host "Adding Virtual Port Group" $strNewVPG "with VLAN Tag" $objOldVPG.VLanID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $VCServerName = "MYVCSERVER" | |
| $VC = Connect-VIServer -Server $VCServerName | |
| $SI = Get-View ServiceInstance | |
| $CFM = Get-View $SI.Content.CustomFieldsManager | |
| # Variables | |
| $CustomFieldName = "HD Size (GB)" | |
| $ManagedObjectType = "VirtualMachine" | |
| # Check if the custom field already exists |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $VCServerName = "MyVCServer" | |
| $VC = Connect-VIServer $VCServerName | |
| $SI = Get-View ServiceInstance | |
| $CFM = Get-View $SI.Content.CustomFieldsManager | |
| # Variables | |
| $CustomFieldName = "HD Persistence" | |
| $ManagedObjectType = "VirtualMachine" | |
| # Check if the custom field already exists |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Check if Servers on Text List exist on VMware | |
| # Assumes that the VM object name matches the server's DNS name | |
| # Set this to the text file containing the list of servers, one per line | |
| $strServerList = "C:\path\to\textFile.txt" | |
| # Create empty array for servers which are found | |
| $arrFoundServers = @() | |
| # Assign all of the VM objects to a variable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get all templates | |
| $objTemplates = Get-Template | |
| # Loop through the templates | |
| ForEach ($objTemplate in $objTemplates){ | |
| # Set the $StrInterimTemplateName variable to the template name, replacing the string "Tmpl" with an empty string | |
| $StrInterimTemplateName = ($objTemplate.Name -replace("Tmpl","")) | |
| # As the string we've just removed might be anywhere in the name, we need to replace double spaces with single | |
| $StrInterimTemplateName = ($StrInterimTemplateName -replace(" "," ")) | |
| # And also remove trailing spaces from the start, or the end of the string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sets up virtual port groups on all hosts connected to a specific vCenter Server | |
| # Name of vCenter Server | |
| $strVCenterServer = "your.vCenter.Server" | |
| # VLANs and associated VPGs | |
| $ArrVLANs = @{ | |
| "123" = "vlanA"; | |
| "456" = "vlanB"; | |
| "789" = "vlanC"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Script to connect to a list of vCenter Servers, and get their version numbers, as well as the version numbers of their hosts | |
| # Ben Neise | |
| # 02/10/09 | |
| # Array of vCenter Servers | |
| $arrVCenterServers = @("server1","server2","server3") | |
| # Create empty arrays for the results | |
| $arrTableVCs = @() | |
| $arrTableHosts = @() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Script to deploy linked clones | |
| # List of custom attributes which you're wanting to copy from the template or parent to the newly created machine | |
| # (Machines deployed from templates no longer inherit CAs in vSphere 4.0) | |
| # These help us track provenance, and provide information to the user | |
| $arrStrAttributesToCopy = @( | |
| "AD Object Location", | |
| "Customisation", | |
| "Infrastructure Consultant", | |
| "Logon Administrator Name", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function Invoke-SubversionScript { | |
| <# | |
| .Synopsis | |
| Runs a script directly from Subversion. | |
| .Description | |
| Given a valid Subversion URL and credentials (Basic authentication) invokes the script on the local machine. | |
| .Parameter Url | |
| The URL of the script. Should be a valid URL, and end in PS1 |