Sample Exchange

 View Only

Create Or Reset VMs 

May 20, 2021 08:31 AM

Helps with creating new VMs or resetting existing VMs. This is intended to be used with Microsoft Deployment Toolkit (MDT) to automate the creation of VMs that then PXE boot and follow the give MDT task sequence. MDT can then use the OS Optimization Tool and the MDT plugin to automate the installation of the agents and the optimization of Windows.

  • New VMs - Created using the given specification.
  • Existing VMs  - Any snapshots are deleted, the existing hard disk is deleted and a new hard disk is added to the VM.
  • MDT Database - Optionally add new VMs to the MDT database specifying a task sequence for MDT to use.
  • Power On - Optionally power on the VM after created or reset.
  • Remote Console - Open a vSphere remote console to the VM.
  • GUI that allows selection of VMs from a list in a comma separated file that contains the VM names and specifications.

    USAGE
  • .\createresetvm.ps1 [vmlist.csv] [vCenterUser] [vCenterPassword] [MDTUser] [MDTPassword]
    \
    WHERE
  • vmlist.csv                = Comma delimited file with a VM per row. Fields are: Name,TaskSeq,Datastore,Network,Folder,Disk,Mem,vCPU,Displays,VideoMem,HWVersion,GuestId,vGPU
  • vCenterUser           = Username for vCenter Server.
  • vCenterPassword   = Password for vCenter Server user.
  • MDTUser                 = Username with rights to the MDT SQL database.
  • MDTPassword        = Password for MDT database user

    EXAMPLES
  • .\createresetvm.ps1
  • .\createresetvm.ps1 mylist.csv
  • .\createresetvm.ps1 mylist.csv administrator@vsphere.local VMware1!
  • .\createresetvm.ps1 mylist.csv administrator@vsphere.local VMware1! mdtuser sqlpassword

    REQUIREMENTS
  • Requires PowerCLI.
  • Change variables for vCenter and the MDT SQL database.
  • List of VMs in comma separated file.

    SETUP
  • Edit the settings.ini file - Change the vSphere values, the MDT SQL information, and tune the default behaviour of the script.
  • Edit the vmlist.csv file to define your VMs

  • #Horizon
    #vSphere
    #MIT
    #PowerShell

    Statistics
    0 Favorited
    1 Views
    1 Files
    0 Shares
    0 Downloads
    Attachment(s)
    zip file
    Create-or-Reset-VMs-main.zip   8 KB   1 version
    Uploaded - Apr 09, 2024

    Tags and Keywords

    Comments

    Sep 12, 2023 01:35 PM

    Download link broken - throws a 400 Bad Request. I was able to 'Browse Code' on this page and copy the code to a .ps1 file. GiHub version works but appears to be older, perhaps?
    Also had to correct syntax on line 47 by replacing the invalid characters with apostrophes around the 'vmlist.csv'

    Aug 23, 2023 04:04 PM

    Script is having issues when specifying MDT database, location, etc.

    Aug 23, 2023 04:04 PM

    Script is having issues when specifying MDT database, location, etc.

    May 25, 2022 02:37 PM

    The task does not pause to add apps even though the option is checked.

    Sep 24, 2021 06:46 PM

    It keeps skipping applications, and I don't have the "Demo" checked

    Related Entries and Links

    No Related Resource entered.