Created
February 20, 2018 16:29
-
-
Save PFortin93/7495a976c2700affb2af4d7a9fe2de7d to your computer and use it in GitHub Desktop.
A powershell script to leverage VMware PowerCLI to connect to vSphere/ ESXi and bulk add a standardized hard drive configuration to a set of VMs loaded from a text file.
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
| #Loads a plain text list of VMs, Bulk adds disks based on specs below. | |
| #If you do not have a credential.xml run the following to generate: | |
| #$credpath = "c:\scripts\MyCredential.xml" ##Path to store credentials | |
| #New-Object System.Management.Automation.PSCredential("VSPHERE.LOCAL\Administrator", (ConvertTo-SecureString -AsPlainText -Force "Plaintext password")) | Export-CliXml $credpath | |
| $vmlist = Get-Content -Patch "c:\scripts\vms.txt" #Location of VMList | |
| $size = "40" #Disk Size in GB | |
| $format = "thick" #Disk Format | |
| $datastore = "VMFS07_PURE04" #Datastore name | |
| $credpath = "c:\scripts\MyCredential.xml" #Set the location of the credentials created in step 1 | |
| $cred = import-clixml -path $credpath #Import the credentials as a Powershell credentials object | |
| Get-Module -ListAvailable VMware* | Import-Module #Load all VMware Powershell Modules | |
| Connect-VIServer -Server 10.10.6.40 -credential $cred #connect to vcenter using the powershell credentials object imported above | |
| #Iterate through list of VMs adding disks | |
| foreach ($vmname in $vmlist) { | |
| $vm = get-vm $vmname | |
| write-host "Adding new $size disk to $vm on $datastore" | |
| New-HardDisk -vm $vm -CapacityGB $size -Datastore $datastore -StorageFormat $format | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment