ESXi 5.0 / ESXi 5.1 Host Backup & Restore GUI Utility (PowerCLI based)

 

This is a little bit of  a fun project I have been working on in bits of spare time I find. It is all written in PowerCLI 5.0 / 5.1 / PowerShell and the GUI was laid out using Primal Forms Community Edition.

 

Updates (17-02-2013) – version 1.3:

  • Hosts are retrieved using a new method (for both backup and restore options)

Updates (29-12-2012) – version 1.2:

  • Added ESX/ESXi host validation into utility – will now test that the host is valid and either connected or in maintenance mode before attempting backup or restore (See the script’s new “Check-VMHost” function for those interested)
  • Minor UI improvements

Updates (29-10-2012) – version 1.1:

  • This utility has been tested on ESXi 5.1 Hosts and confirmed to be able to successfully create a backup archive file of these.
  • Be sure your DNS is working correctly on the system you run the Backup utility on – it relies on DNS to find your ESXi hosts as they are named in the dropdown when you select the host to backup. (See comments for troubleshooting)
  • Restore to new hardware (force restore) option added
  • Fixed labels and connection box label description

 

What it is essentially, is a GUI that allows you to Backup ESXi 5.0 or ESXi 5.1 hosts to a destination of your choice on a local drive. It also allows you to restore ESXi Host configuration bundle backups taken, to other Hosts. I had other plans to integrate cloud storage options in (Amazon S3) as a backup target, but I thought that this doesn’t really offer anything valuable and I would just keep it relatively simple for now – therefore I have disabled this functionality. The PowerCLI script is fairly long – and I know there are plenty improvements I could make to better it and shorten the code, but for now it does the job. I have added various catches for exceptions / errors so you should get visual feedback if you have entered an invalid path, or username for example.

 

Anyway, hopefully this proves useful to some! As always, take care using the backup / restore functionality of this utility. The restore functionality works by first putting the ESXi host into Maintenance mode (if it isn’t already in this mode) and then applying a backup bundle to the host (Restore). The Host will reboot immediately following this. The Backup and Restore is implemented using Get-VMHostFirmware and Set-VMHostFirmware cmdlets so you can read the help descriptions for an idea on how exactly these work. The Host Backup Bundles are stored in a path of your choice and when restoring from a path the cmdlet works by looking for a bundle filename that matches the name of your ESXi host selected to restore to. Note that the file browser module I have implemented here (used to select paths) is a modification of the work done by Ravikanth Chaganti on his PowerShell Help Browser GUI. I simply adapted his code to list the contents of local drives in a tree view instead of PowerShell Help cmdlets. The only limitation here is that I have not implemented code to browse further than one level into the root of each drive. If you can provide this modification yourself, please feel free to contribute in the comments! I have just not spent the extra time to do this myself yet.

 

Here are a couple of quick screenshots of the Utility / GUI:

 

 

ESXi 5.0 Host Backup & Restore GUI Utility & Path Browser

 

Current version (1.3):

(Version 1.3) [download id=”25″]

 

Previous versions:

(Version 1.2) [download id=”21″]

(Version 1.1) [download id=”20″]

(Version 1.0) [download id=”9″]

 

Enjoy!

 

155 Comments

  1. hi,

    i have used it to backup esxi 4.1 and backup saved in the format of tgz file with the ip/hostname. I haven’t get any servers to test it as servers were in production. So, I would like to know will it work form ESXi4.1 as well?

  2. Hi,

    Do you mean “will it work if you restore a host using this backup file you have generated with this utility?” If so, then yes, it should definitely work. I am almost 100% sure I tested the tool using ESXi 4.1 as well as ESXi 5.0. As soon as I get a chance I’ll spin up an older ESXi 4.1 host and try it out.

    Sean

  3. gr8 sean, hats off to you. I am a new bee in IT industry 🙂
    Its really good script. I am keen to learn this sort of scripting could you please guide me with some good stuffs to start with.

    Also, I have tested with network changes and restored and its perfectly working for ESXi4.1 for me, what all other things will it help in restoring. Can you help me with some free/script solution for backing up /var/logs coz there is no log rotate in esxi4.1, i was wondering can be have something which would take care of my houseful logs on hosts…

  4. I think we can get the same done using this command for backup and restore,
    vicfg-cfgbackup -s C:\bckup.txt

    Just curious to know the difference doing this and using the script please.

  5. Hi there,

    You are correct – it does essentially the same thing. This PowerCLI script just throws a bit of a GUI over the top so you can choose which hosts to backup and which to restore to etc…

    Sean

  6. Good Afternoon. First off, great script!!! If I can get this to work it will be an addtion to my other SysAdmin utils. After running the script, the gui comes up fine. But when I go to do a backup, I get an Exception Error window:

    Exception caught Get-VMHostFirmware Value cannot be found for the mandatory parameter VMHost.

    I have not tried the restore function yet as I don’t have a good backup. Thanks in advance..

    ESXi 4.1.0

  7. Hi Scott,

    With the drop down selector for your Hosts what options appear there? Do you see the ESXi hosts you would expect to see normally? If you drop down to a cmd prompt can you ping the specific ESXi host you are selecting to take a backup of? That exception appears to be saying that it cannot find the ESXi host you selected in the drop down list.

    Sean

  8. I am having the same problem as Scott

    Exception caught Get-VMHostFirmware Value cannot be found for the mandatory parameter VMHost.

    I am running ESXi 5

    and yes in the drop down menu I do see my my VMWare box listed I want to backup. Any ideas?

  9. Hi Mike,

    Could you give me the build version or update level of your ESXi 5 system? I want to try and reproduce the error you are seeing. Do you have PowerCLI installed anywhere at all? If I gave you the equivalent cmdlet that the GUI utility is using to perform the backup operation would you be happy running it in PowerCLI to check to see if you get the same error?

    Finally, are you authenticating as root or a vsphere admin user against this host?

    Sean

  10. @Sean
    Sean,

    ESXi – 5.0.0 Build 504890

    No this is the only system I have PowerCLI loaded (also I am 5.0.1 of PowerCLI). Yes I have no problems with running the direct command just shoot it over in e-mail if you can (e-mail stripped out)

    I am authenticating as Root

    – Mike

  11. Sorry for being a VMWare noob…I can’t seem to get the GUI to launch properly. If I choose “Run with PowerShell” I get the popup asking for my vCenter Server, but after entering the IP address, I get the error “Exception caught: The term ‘Connect-VIServer’ is not recognized…’. I’m sure it’s something simple, but I have no experience using PowerCLI or PowerShell… Thanks!

  12. Hi Michael,

    It would seem to me at first glance that you don’t have PowerCLI (or the right version of PowerCLI) installed. Have you got PowerCLI installed on the machine you are running this on? Once installed, you should open PowerCLI as an admin user, then do Set-ExecutionPolicy RemoteSigned to ensure the execution policy for your machine is set to a good level to run the script. Download the utility, right-click the zip file, properties, select “Unblock”, then extract it. From within your PowerCLI prompt, run the utility by navigating to the folder you extracted it to, and typing .\NameofScript.ps1 and pressing Enter.

    That should do the trick. I think it is just your PowerCLI requirement. Let me know what you find!

    Cheers,
    Sean

  13. Hi Sean,

    Thanks for your script, very usefull in order to backup ESX Server without doing some disk image.

    I have a problem when i try to backup my ESX4.1, an Exception is caught :
    No parameter for name “BackupConfiguration”

    Could you please help me?

  14. Hi Julien,

    Sorry for the late reply – let me load the script up and see if I can get an old ESXi 4.1 host up to test and try to reproduce your problem. I’ll drop you a message once I have tested!

    Sean

  15. The script seems to be corrupted, could you please for send me working copy to my email id please

  16. Hey Julien,

    Got an ESXi 4.1 host up and running in my cluster to test against. I was using ESXi 4.1, Build 502767. It all worked perfectly for me. Can you check the following items please:

    1. Make sure the directory you are using to save the backup to, you have full permissions on. Try specify a local directory like C:\Temp for example.
    2. Make sure you are entering a valid path name – like example above, c:\temp
    3. Make sure you are using the latest version of PowerCLI – 5.0.1 (it could be that you are on an older version and the Get-VMHostFirmware cmdlet behaves differently to the 5.0.1 version.

    Its odd, because “BackupConfiguration” is a SwitchParameter – it shouldn’t need any parameters to be specified with it, which is why in this utility, it is used as follows:

    Get-VMHostFirmware -VMHost $HostToBackup -BackupConfiguration -DestinationPath $SaveLocation -ErrorAction:SilentlyContinue (that is without any parameters on the -BackupConfiguration part).

    Could you test/try the above 3 points? You can check what version of PowerCLI you have by doing Get-PowerCLIVersion in the PowerCLI prompt.

    Hope that helps! Let me know what the outcome of the above is 🙂

    Sean

  17. Hi Narender,

    It could be that your download was corrupted? Did you retry the download? I just tried it myself a few minutes ago and everything worked – I was able to run the utility with no problems. What is the exact error message you are getting?

    Sean

  18. Hi Sean,

    Thanks for your reply.

    I thought i needed a PowerCLI with the same version as my ESX, so i currently have 4.1 build 264274.

    I remove install the 5.1 test and give you results 🙂

  19. Hey batmac,

    More than likely, you are not launching the utility from a PowerCLI prompt? You are probably launching it from a normal PowerShell prompt I suspect. Make sure that you:

    A) Have the latest version of PowerCLI installed (5.0.1)
    B) Are executing the PowerCLI script from the PowerCLI prompt, not a normal PowerShell prompt.

    Does that help?

    Sean

  20. Hello Sean,

    Thank you for clearing that up. I was attempting to run it in PowerShell (not PowerCLI)
    I am now getting an error “Get-VMHostFirmware Value cannot be found for the mandatory parameter VMHost” I think I saw something here pointing to “why” this could heppen. I will read on as aI am a newby when it comes to PowerCLI

    Thanks!

  21. Batmac :
    Hello Sean,
    Thank you for clearing that up. I was attempting to run it in PowerShell (not PowerCLI)
    I am now getting an error “Get-VMHostFirmware Value cannot be found for the mandatory parameter VMHost” I think I saw something here pointing to “why” this could happen. I will read on as aI am a newby when it comes to PowerCLI
    Thanks!

  22. Hi Batmac,

    No problem! Well, I have seen somebody else get this error before and it turns out their DNS was not working correctly on the machine they were running the utility from. Open up a command prompt, and verify that you can ping the ESXi host by its host name as it is displayed in the Host to Backup dropdown list in the backup tool! If you cannot ping the host by its host name, and resolve an IP, then DNS is at fault – you’ll need to sort that out. Let me know if this helps 🙂

    Cheers,
    Sean

  23. Sorry for the double post! Wanted to correct a type and ended up quoting the whole thing…
    🙂
    I can ping the ESXi 5 box by IP and host name. Will try form another PC and let you know. I am on Mac and running Win7 via Parallels Desktop… Should not be an issue, but will test a few things and post results here.

    oh and by the way, I totally forgot to that you for the script! shame on me…
    🙂

  24. hello everyone,
    Since I “was” new to PowerCLI, (thus never had used it before), I decided to list in detail the steps I took to get a successful backup on my setup so here we go!
    – Note, in this example all “quotes” are not part of any command thus must be removed.
    – Download ESXi 5.0 Host Backup & Restore GUI Utility.
    – Download and install PowerCLI 5.0.1.
    – I decided to place the “ESXi5-Backup-Restore-Utility-1.0.ps1” inside the “scrips” folder, which, on my system was found in (C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts), so the below instructions will be in conjunction to this decision.
    – Launch the VMware vSphere PowerCLI (I was not obligated to “run as administrator”, but you may have to depending on your Windows policies.)
    – You may have to change the “ExecutionPolicy” to “RemoteSigned” Type : “Get-ExecutionPolicy” to find out the current state, and if not “RemoteSigned” then type : “Set-ExecutionPolicy RemoteSigned”
    – To connect to your host…
    – Type “Connect-VIServer”
    – Enter name or IP of server (seems as though name or IP does not matter in my case here.)
    – Enter user name (root) and password to authenticate against your ESXi host.
    – Accept certificate (only applies if you used FQDN in the above option.)
    – Change directory to go to the “scripts” directory (type “dir” to find out which directory you are currently in… you may have to simply type “cd Scripts” you may also chose to type the full path to the script, but once again, the below command may be different if you select this option.
    – Launch the backup script by typing : (since we changed to the “Scripts” directory, the command is…) “.\ESXi5-Backup-Restore-Utility-1.0.ps1”
    – Assuming your DNS is working properly, type the FQDN of server in the following pop up window…
    NOTE : I found that typing IP here caused “exception caught error” when you actually ran the backup in the next window… In other words, if I typed the IP of the server, I DID see the FQDN of my host in the next screen but got the “Get-VMHostFirmware Value cannot be found for the mandatory parameter VMHost” error… when I used the FQDN in all fields, the backup ran fine every time…
    – Enter user name (root) and password of the host in question.
    – “Browse” to select “Backup Target” or simply click the “Backup” button… (I created a folder prior to running the script)
    – You should see an information dialog box indicating that the Host “your esxi host” was Backed up to your Selected Target!

  25. So somehow I read everything (almost every Word). Got the PowerCLI. Got the Script. Did everything with Admin rights.

    The first thing that is then asked of me ist the name or ip of my vCenter Server.

    I do not have one.

  26. Great script to use worked a treat if any one has issues with the firmware error this is most likely due to dns, create the record and ensure it propergates round all your dns servers, once it has close and reopen the powercli and try again worked straight away after that.

  27. In response to the above post assuming they are talking about standalont host. I too only have one host no vCenter – Will this script not work for me?

    Best regards

  28. I have tested the bit of PowerCLI that does the actual backup part on its own using the shell and confirmed it does indeed work on single hosts. Just enter the host name when connecting instead of the “vCenter” IP. Use your root credentials and it should backup the configuration. Just remember your DNS needs to be working correctly to resolve the host name to it’s IP 🙂

  29. Hi Sean, Thanks for this great tool! The problem is that I don’t get it working.
    I am using PowerCLI 5.1 ( should this be a problem? )
    When I run this script I do get the error : The File c:\8Utility-1.0.ps1 cannot be loaded. The file is not digitally signed.

    What do you suggest me to do?

  30. Hi!

    Once downloaded, right-click the zip file, go to properties, and make sure you click “Unblock”, then click OK. Next, open up PowerCLI (5.1 is fine) and run “Get-ExecutionPolicy”. You’ll probably find that it returns “Restricted”. If it does, type “Set-ExecutionPolicy RemoteSigned” and then press enter. Confirm the prompt by pressing “Y”. Try run the utility again and it should be fine – hope that helps!

    Sean

  31. @Sean
    Hi Sean!

    I Thought I already did that, tried it again and now the tool is popping up!
    Do you know if we can use this tool to backup the ESX host configuration, and restore it on a (new) different server? ( with same name and IP address ) .
    We are replacing our hardware and that’s the reason why I like to use this tool.

    Thanks for the great job and effort while creating this tool, hope to save a lot of time with

  32. @Ascom IT

    So I have tried this out, and the utility needs a small change applied – I will do this in the evening and make a new version available (1.1) which will have a small check box to tick if restoring to new hardware. The problem is that the cmdlet (Set-VMHostFirmware) does a check on various bits and if there is a mismatch, it does not restore the config backup file. For new hardware, you will have new MAC addresses on NICs etc and therefore you get an error due to mismatches between the old hardware that the backup was made from, and the new hardware you restore to. So i’ll make a new version available that allows you to “force” the restore even if there are mismatches like this.

    As always, I would recommend you test the backup/restore functionality in a dev/lab environment before using on production! (Fine I guess if you plan downtime for the host migration/change though I guess). I tested the above myself using VMware workstation and some virtual ESXi 5.1 hosts and it worked fine using the force restore to a new ESXi 5.1 host. The only thing I needed to do was to rename the backup config file that was created with the old host’s name, and make sure it was the same as the new host’s name. (The restore functionality relies on the file being named exactly the same as the host it is being restored to).

  33. @Sean
    Hi Sean , Thanks again for your great help

    Since we are going to rename the new sever exactly the same as the old one, the renaming of the backup file should not be a problem for us then…

    As far as I can see we are planning the update by the end of this week, or beginning next week!
    I’ll keep you posted.

  34. I run the utility and it works fine except it does not backup any files to the directory I selected. I am running PowerCLI 5.1 agains an ESXi4.1 host, not sure if this is an issue.

    Also, when I try to run the Get-VMHostFirmware command PowerCLI comes back with an error stating “Retrieving the Host firmware information is only available on ESX 3i”, could that be the reason why the gui tool is not working?

    thanks,

  35. Hi Erick,

    Is there any error or exception message that appears after clicking “Backup”? Or does nothing appear? Also, what is the exact command you tried directly in PowerCLI? Did you try something to the effect of:

    Get-VMHostFirmware -VMHost myESXihost -BackupConfiguration -DestinationPath C:\temp

    ?

    Cheers!
    Sean

  36. Hi Sean,

    No error appears, I click backup and almost immediately I get the backup completed window, I just tried this on an ESXi5.1 host and it worked but not on an ESXi4.1 host.

    Yes, the command is exactly as you have it listed, the difference is that I am giving the full fqdn of the host.

    thank you,

  37. Hey Erick,

    Thanks for testing that – hmmm, looks like I’ll need to retest myself with an ESXi 4.1 host. Sure I had tested this before but maybe I was wrong!

    Cheers,
    Sean

  38. I’m trying to run this 1.1 version of your utility within PowerCLI 5.1 release 1, which I just installed (and I have the script “unblocked” and Execution Policy is set to RemoteSigned). I get the box that says “Please enter the IP or Name of your vCenter Server or standalone ESXi host:”, but no matter what I type in that box and then click OK, I get this error:

    Exception caught: The argument is null or empty. Suply an argument that is not null or empty and then try the command again.

    What do I do here to fix this?

  39. Hi Steve,

    I too am using PowerCLI 5.1 release 1 (build 793510) and have connected to a vCenter Server 5.1 with 3 x ESXi 5.1 hosts to test – all seems to be working fine for me.

    From the machine you are running this, did you try running the script from a “clean” PowerCLI session (i.e. not connected to any vCenter or ESX machines)? From the machine you are executing the backup utility script, are you able to connect to vCenter using the vSphere 5.1 Client by typing in the exact same server name or IP you are using to connect to when the “Please enter the IP or Name of your vCenter…” box appears when running the backup utility script? I assume you have tried both IP and DNS name of the vCenter server then?

    What build and version of vCenter Server are you trying to connect to?

    Cheers,
    Sean

  40. Hi Sean,

    Thank you though for this great tool you put together, it works fantastically great on ESXi5.1 hosts.

    appreciated your time.

    @Sean

  41. Hey Sean,

    first of all.. BIG THANKS! the tool that you have created is really great and such an awesome thing!

    but my question –> what about ESXi 3.5/4.0/4.1 – is there a chance to backup these one too? :/

    thx – best regards
    Raphael

  42. Hi Raphael,

    Thanks for your feedback – glad it has been useful. Regarding ESXi – earlier versions, I have tested this tool on 4.1 and above. 3.5 – no testing yet 🙂 I seem to recall there being a ESX Host Configuration Backup tool around the time that vSphere originally got released that could be used to backup host configurations. I think it is discontinued now as I can’t seem to find it.

    Sean

  43. Hello Sean!

    I am having the same problem that Steve Young has but I am not using vCenter Server and attempting to backup a 5.1 host. I have tried everything and still get the “caught a system exception” error. Using the PowerCLI 5.1 Release 1 and the ESXi host is Build 838463. Your script worked beautifully when I was on 5.0.

    Any thoughts?

    Richard

  44. Hey Richard

    I’ll re-test with a single ESXi 5.1 host myself and see if I can replicate your issue. I assume you checked the DNS by pinging the actual FQDN of the host as it appears in the list of hosts in the utility? Did that resolve to an IP address?

    Cheers,
    Sean

  45. Excuse my ignorence here please. So where is the “GUI” All that is contained in the Zip is a Powershell file and no GUI. How do I open it?

  46. I’m hoping this utility will do what I’m wanting and I am trying to confirm. We have some ESXi 5.0 hosts that we want to upgrade to the latest 5.1. I am told that the 5.1 has to be a fresh install. What I want to do is be able to backup the host configuration for things like all the networking, storage adapters, connections to our SAN and that sort of thing. I don’t need to backup anything from the host other than the config. What I want to do is backup the config, blow the host away, do a clean install of 5.1, then restore the config so we don’t have to do it all manually. Will this utility do that? Thanks.

  47. @JohnA
    Ignore my initial post. I spotted a mote in an earier post saying to

    ……….the utility, right-click the zip file, properties, select “Unblock”, then extract it. From within your PowerCLI prompt, run the utility by navigating to the folder you extracted it to, and typing .\NameofScript.ps1 and pressing Enter.

    I neglected to do the “Unblock”part……….. It works now that I did that. Thanks for that 🙂

  48. Glad you got it going 🙂 Ideally, I would like to compile this script into an executable. However that requires a paid-for version of PowerGUI (by Quest) and I don’t have the spare funds floating around to buy the professional version (Which supports compiling into executable).

    Cheers,
    Sean

  49. Dean,

    Yes it should do the trick provided you keep the hardware the same. I would however advise that you test in a test environment first – for example create a test 5.0 virtual ESXi server and another identical 5.1, then use the utility to backup/restore between them. Also, make sure you have a backup plan if you then plan to do this in production and things go wrong with the utility. I myself have not tested this on physical hardware before – only in my own lab on virtual ESXi hosts. So if you do have Enterprise plus licensing for example, you could fall back to host profiles, or if not, just make sure you have a planned re-build process if you need to re-create configuration from scratch in the worst case scenario.

    I don’t like putting people off using the utility I spent a lot of time creating, but just want to make sure people test in pre-production before using in production and cover all their bases!

    Cheers,
    Sean

  50. Hi Sean , I have this error when I clic on backup buttom (my c:\tmp)

    Exception caught Get-VMHostFirmware
    Value Cannot be found for the mandatory parameter VMHost

    I have Esx 5.1 (free) and the last powerCli too.
    What am I doing wrong?

  51. Marzo :
    Hi Sean , I have this error when I clic on backup buttom (my c:\tmp)
    Exception caught Get-VMHostFirmware
    Value Cannot be found for the mandatory parameter VMHost
    I have Esx 5.1 (free) and the last powerCli too.
    What am I doing wrong?

    More Info, maybe de FQND is the problem.

    Look this command from cmd PowerCli. I have registered in DNS my host and resolve right.

    PowerCLI C:\> Get-VMHostFirmware -VMHost esx01.tse.local -DestinationPath c:\tem
    p
    Get-VMHostFirmware : 10/12/2012 10:00:51 Get-VMHostFirmware Could not
    find VMHost with name ‘esx01.tse.local’.
    En línea: 1 Carácter: 19
    + Get-VMHostFirmware <<<< -VMHost esx01.tse.local -DestinationPath c:\tmp
    + CategoryInfo : ObjectNotFound: (esx01.tse.local:String) [Get-VM
    HostFirmware], VimException
    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNo
    tFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostFirmware

    Get-VMHostFirmware : 10/12/2012 10:00:51 Get-VMHostFirmware Value can
    not be found for the mandatory parameter VMHost
    En línea: 1 Carácter: 19
    + Get-VMHostFirmware <<< nslookup esx01
    Servidor: srv-tchdc01.tse.local
    Address: 172.16.1.12

    Nombre: esx01.TSE.local
    Address: 172.16.1.93

    PowerCLI C:\> nslookup esx01.tse.local
    Servidor: srv-tchdc01.tse.local
    Address: 172.16.1.12

    Nombre: esx01.tse.local
    Address: 172.16.1.93

    But, when I runs the cmd without domain name (only host name) this work fine.

    PowerCLI C:\> Get-VMHostFirmware -VMHost esx01 -DestinationPath c:\tmp

    Host Data
    —- —-
    esx01 c:\tmp\configBundle-esx01.tgz

  52. Hi Marzo,

    Looks like you have solved it – indeed the DNS is an issue and that message seems to be indicative of a the PowerCLI cmdlet not being able to resolve the host’s name.

    Cheers!
    Sean

  53. @Sean
    Not 100%, but I have a Question

    From the cmd (or powerCli) I can resolve the full (FQND) or shot name (DNS) with Nslookup without problem, but the Script can’t do that , Why?

  54. @Marzo

    That is an odd one – how about ping? Does that not resolve an IP to the FQDN? Are you calling the script from the same PowerCLI prompt, i.e. ./scripname.ps1 ?

  55. @Sean
    Yes, I am calling from PowerCli cmd line.
    Remember that Ping cant resolve , this dont use DNS service, it’s 1 layer more down (OSI model)

  56. same issue here I can use .

    PowerCLI C:\> Get-VMHostFirmware -VMHost IP address -DestinationPath c:\temp

    but not PowerCLI C:\> Get-VMHostFirmware -VMHost FQDN -DestinationPath c:\tem

    I can ping from Power CLI to FQDN and use nslookup no problem??
    it resolves to correct IP.??

  57. What happens if you do a “Get-VMHost “hostname”” in PowerCLI for this specific host? Does it return the host and info you would expect? For hostname, type the same name of the host you see in the “Hosts to backup” drop down list you see in the GUI tool.

  58. Pingback: Free tools VMware
  59. Sean,

    I’m new to PowerCLI, and I tried following the steps outlined by BatMac on 8/27/2012 at 15:50 (#28) and keep getting an Exception error: “Exception caught: The argument is null or empty. Supply an argument that is not null or empty and then try the command again.”

    I have connected to the vCenter 5.0 server and a stand-alone ESXi 5.0 host by both IP address and DNS name and can perform the get-vmhost “name” and get-vm commands successfully.

    Is there a step or process I’m leaving out? Your help would be greatly appreciated.

  60. Hi Carl,

    Any other info along with that exception? It should all be working as you have verified everything else. Are you using the 1.2 version?

    Cheers,
    Sean

  61. Sean,

    Yes, I’m using the 1.2 version. Unfortunately I don’t get any other messages.

    I open ‘VMware PowerLCI 5.1 Release 1′ on my Windows 7 64-bit computer, navigate to the directory where I have the software downloaded, and enter /.\ESXi5-Backup-Restore-Utility-1.2.ps1’. The system responds with a ‘vCenter IP or DNS Name’ window. I enter either the IP address or DNS name of either a ESXi 5.0 host (ex. 10.3.16.201 or GRYMETVM01) and hit enter. I can do the same thing with a vCenter as well. Is there something I could do to help provide you with additional information? Is there a way to create a log file I could send you?

    Thanks as always.

  62. Hi Carl,

    Thanks for additional info. That is the exact same version of PowerCLI and OS that I am using. No matter what I can’t seem to replicate this issue.

    There is a PowerCLI window that opens and displays a bit of logging info in the background when you use the GUI, can you try again, and then send me the output from that window? (Right-click -> Mark -> drag over the text, then press Enter to copy it to clipboard).

    If you see “$HostToBackup seems to be a valid host…” in green writing as you click the “Backup” button then all should be good. If you don’t see this and are getting an exception then it means PowerCLI is having trouble running the “Get-VMHostFirmware” cmdlet against your host. Let me know if you see this green text or not when clicking backup.

    If you don’t, then could you try run the following command (open a new instance of PowerCLI, and type this:)

    Get-VMHostFirmware -VMHost yourexamplehost.domain.local -BackupConfiguration -DestinationPath C:\temp -ErrorAction:SilentlyContinue

    Of course make sure that C:\temp exists and that you have write access. Also make sure you have initially connected to your VC with Connect-VIServer VCNAME too.

    Does running that Get-VMHostFirmware example above give a similiar error or does it work?

    Other things to check / make sure of:

    1. Make sure you have write access to folder you are targeting for the backup file.
    2. Make sure you have Admin role for vCenter or a role that allows you to backup host configuration (admin of course means you can do anything)
    3. Make sure you have right-clicked the downloaded file and selected properties, then Unblocked it (if the unblock button appears on the properties window).

    Cheers,
    Sean

  63. Hi Jeroen,

    Could you take a look at the reply I just sent to Carl – try out that troubleshooting and let me know what you get.

    Cheers,
    Sean

  64. Sean,

    Here is the output from the command line instructions you provided me. I tried it using the FQDN and just the server name since I am in the same domain. You can see that I was able to successfully attach and back up the config when I used just the server name. I did unblock the file as well and still can’t successfully execute the GUI. Strange…

    Carl.

    PowerCLI C:\emc> connect-viserver grymetvm01

    Name Port User
    —- —- —-
    grymetvm01 443 root

    PowerCLI C:\emc> Get-VMHostFirmware -VMHost grymetvm01.internal.graycompanyinc.c
    om -BackupConfiguration -DestinationPath c:\EMC -ErrorAction:SilentlyContinue
    Get-VMHostFirmware : 1/8/2013 3:05:20 PM Get-VMHostFirmware Value
    cannot be found for the mandatory parameter VMHost
    At line:1 char:1
    + Get-VMHostFirmware -VMHost grymetvm01.internal.graycompanyinc.com
    -BackupConfigu …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
    + CategoryInfo : NotSpecified: (:) [Get-VMHostFirmware], VimExcep
    tion
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
    n.ViCore.Cmdlets.Commands.Host.GetVMHostFirmware

    PowerCLI C:\emc> Get-VMHostFirmware -VMHost grymetvm01 -BackupConfiguration -Des
    tinationPath c:\EMC -ErrorAction:SilentlyContinue

    Host Data
    —- —-
    grymetvm01 c:\EMC\configBundle-grymetvm01.tgz

    PowerCLI C:\emc>

  65. At those having problems:

    Please make sure to enclose the server names in single or double quotes as the parsing engine of powershell could read the dots of the FQDN as special characters.

  66. Hey Sean,

    Great tool!

    I have this function laying around to browse all drives and folders on your computer. I picked it up in another form from the powershell.com forums and modified it for my own needs at the time.

    function Get-Folder()
    {

    $FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog
    $FolderBrowserDialog.Description = “Backup destination”
    $FolderBrowserDialog.RootFolder = “MyComputer”
    $FolderBrowserDialog.ShowDialog() | Out-Null
    $FolderBrowserDialog.SelectedPath
    }

    Get-Folder

    This should do the trick 🙂

    Ralf

  67. I was trying to add this function to your script myself when I realized you need to browse to the actual file when you want to restore. The Get-Folder function can’t do that, so you’ll need something like this as well I think:

    Function Get-FileName($initialDirectory)
    {
    [System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) |
    Out-Null

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $initialDirectory
    $OpenFileDialog.filter = “All files (*.*)| *.*”
    $OpenFileDialog.ShowHelp = $true
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.filename
    }

    Get-FileName -initialDirectory “C:\”

    I found this code originally on the Hey, Scripting Guy! blog.
    https://blogs.technet.com/b/heyscriptingguy/archive/2009/09/01/hey-scripting-guy-september-1.aspx?Redirected=true

    Ralf

  68. Hi, please, I have small quetion. We cannot use DNS of ESXi Hosts in our network and I would like to use this your tool for backup of VMWare settings. Is possible to use for backup or recovery only IP?

    My current error:
    Exception caught: Get-VMHost VMHost with name ‘xxx’ was not found using the specified filter(s).

    Thank you very much for help.

  69. Hi,

    I have made a newer version recently (1.3) which should fix this issue – it was for somebody else, and I haven’t had a chance to publish it yet. I’ll post it up later – give it a go and let me know if it works 🙂

    Cheers,
    Sean

  70. @Sean
    Hi Sean, thank you for new version. Backup with only HOST IP works well. Recovery I will testing little bit later. Thank you very much.

  71. Hi Sean,

    Thanks for creating this. It seems to back up nicely, though I haven’t tested a restore (not having a test machine to play with at the moment).

    However, there’s a bug (design decision?) in the file browser: I only get a choice of C: drive and its top-level folders. I can’t browse to sub-folders or network drives, though I can type them in and it works with them.

    Cheers,
    Pak

  72. @Pak
    Ah, follow-up on that; I hadn’t fully read your post! I’ll see if I can take a look at the drill-down bit (I’ve already implemented a change for the Network Drives bit) at some point.

    For the curious, the change to display Network Drives is at line 131, changing it to read:

    Line 131
    $LocalDrives = Get-WMIObject -ComputerName localhost Win32_LogicalDisk | Where-Object { (($_.DriveType -eq 3) -or ($_.DriveType -eq 4)) -and ($_.FreeSpace -gt 30000) } | Select DriveType, VolumeName, Name #Get all relevant drive types and list them

    I’ve added a FreeSpace check to make sure that there is enough space to save your configuration bundle, and to omit drives that aren’t actually connected properly at the moment.

  73. @Pak

    Hi Pak,

    Thanks for the comments! You could call it a design decision! Haha, yes, the file browser code is actually based off someone else’s code, and I didn’t spend much time modifying it to support children nodes.

    Excellent work adding the Network Drives and the disk space check – great little addition there I must say. I’ll try to remember to include that in the next update and attribute it to you 🙂

    If you do manage to figure out the sub-folder work, do let me know – would be interested in seeing that, although I suspect it’ll be a bit of work to add that in.

    Cheers,
    Sean

  74. Hi Sean,

    thank you for creating this tool! It is exactly what I was looking for.

    However, I get an error when I try to connect to any of my ESXi-Hosts:

    After I type in the IP-Adress of the Host (or type in ANYTHING) I get following error:

    caught a System exception

    Exception caught: The Argument is NULL or empty. Provide an Argument that is not NULL or empty and execute the command again.

    (Translated the error message from german so it might not be 100% correct)

    Am I doing something wrong? I’m rather new to PowerShell and PowerCLI so that might be the case. 😉

    My Environment:
    YourScript v1.3
    Windows 8
    PowerShell 2.0
    PowerCLI 5.1.0 R2

    Regards,
    Malte

  75. Thank you very much for these script. Am I the only one that doesn’t get it to run ?
    I get the prompt for entering the IP or Name, fill it with the ip of my vcenter. And I get :
    “Exception caught: The Argument is null or empty. Supply an argument that is not null or empty and then try the command again. . ”
    Cheers.

  76. I am getting an error when executing this in powershell under Windows 8 64-bit. Can someone assist with the problem.

  77. Hi Malte,

    Sorry for the delayed reply. Can you test this on a Windows 7 machine? I have not yet tested on Windows 8 with PowerCLI 5.1.0.

    Regards,
    Sean

  78. Everything seems to run smooth and I get a window saying that the host is backed up but no file is created.

  79. @Sean
    Same problem as Derek, get the host backed up message but no files. Running from vCenter server 2008 R2 with latest powercli.

    Tried first from Windows 8 client, but got the argument null or empty error.

  80. @Ole

    Could you try download and run an older version to see if that makes a difference? Unfortunately I am having trouble spending any time on this or my blog – busy with house renovations the last couple of months in the evenings/weekends 🙁

    Also, make sure you have done Set-ExecutionPolicy RemoteSigned (or Unrestricted) before running.

  81. It’s run only in local lan net? (internal) I can backup vmware servers from internet with the relative ports of vmware open? On My first run with 3 different servers, connect sucess, no errors, but the backup files… dont save on folder c:\tmp.. Sorry about my poor english. Tks

  82. I have tried versions 1.1, 1.2, and 1.3 — all appear to run properly, they say they create the backup, but no files appear.
    I don’t know if the PowerCLI on my Win7 x64 notebook matches anything…is it supposed to??
    If so, what is it supposed to be??
    ESXi hosts are all 5.0 U2.
    Thank you, Tom

  83. Hi Tom,

    I haven’t had much time recently to test the utility – unfortunately have been very busy. Are you connecting it direct to the hosts or via vCenter? I’ll have a quick try of the utility on my own environment this evening to double check it all still works for me…

    Sean

  84. @Tom

    Hi Tom,

    I tried this out again and it worked fine for me. Here’s what I did:

    Downloaded version 1.3. Unzipped, moved the .ps1 file to a convenient folder. Right-click -> Properties on the .ps1 file, select “Unblock”, then “Apply”.

    Load PowerCLI (VMware vSphere PowerCLI 5.1 Release 1 build 793510), run the script (.\ESXi5-Backup-Restore-Utility-1.3.ps1), specify IP address of my vCenter 5.1 server, enter my domainname\username and password. Selected a host from the drop down list of hosts to backup, typed in path to save to as: C:\sean (I made sure this folder already existed), then clicked “Backup”. A message appeared confirming completion, then I checked the folder and the file was there (configBundle-host02.homelab.local.tgz)

    Did you try those exact steps too?

    Cheers,
    Sean

  85. Sean,
    Thank you so much for your instruction.
    I am wondering shall I turn off the virtual machine first?

  86. Hi Robat,

    For initial testing, I would definitely use a host that is not in production use. See how the util works for you, test a backup and restore scenario, and see that it performs the expected actions! So yes, initial testing, ideally you want your VMs off, as the utility needs the host in maintenance mode to restore it.

    Sean

  87. Work very well in saving ESX5i configuration, not yet tested on restore configuration.
    Maybe be able to do it next week !

    As lots told you already, GOOOOOOOOOOODDDDDDDDDDD JOB !!!!
    Thx

  88. Having problems in that after entering the address of the vcenter server (5.1u1) I get a message “Exception caught: The arguement is null or empty” – is this likley to be caused by having the vcenter server on a standard port (444) and if so not clear where in script to make the change

    Thanks

  89. Hi Andrew,

    It could very well be. In the script file there will be a section where it connects to vCenter- search for the line “Connect-VIServer” where that is defined, add “-Port 444” on the end or somewhere just after where the username and password parameters are tagged on (of course without the quotes). Save the file, then re-run.

    Hopefully that’ll do the trick 🙂

  90. made no difference

    The old version (1.0) works ok with our old esxi 5.0 system, but neither want to play with the 5.1u1 systems

    Curious

    Andrew

  91. Hi Sean,
    at first thanks for this great tool and sharing it with the community.
    However I’ve got a question, does it work only in combination with a vCenter or is it possible to backup also a standalone host?

    I’ve just tried it and getting the same error message as Andrew, but in my case I’ve tried to connect to the ESXi 5.1 Host directly, since we don’t have a vCenter yet 🙁

    Thanks!
    Alex

  92. Hi Andrew,

    I’ll have to try it out on some 5.1 u1 systems I have in my lab. Have been so busy in the last 6 months that I have hardly had any time to devote to this little tool. I’ll let you know how it runs against my lab hosts.

    Sean

  93. Hi Alex,

    You should be able to direct it at single hosts (target their management network IP). Should work the same way, except it’ll just list the single host in the backup/restore combo boxes.

    Sean

  94. @Sean
    Hmm, then I have no idea why Im’ getting exact the same error message as Andrew, I’ve tried with 4 different ESXi 5.1. U 1 Hosts 🙁

    Error Message: “Exception caught: The argument is null or empty. Supply an argument that is not null or empty and then try the command again”

    Thanks
    Alex

  95. Very odd – I’ve tried in my own lab environment with ESXi 5.1 hosts – connecting via vCenter 5.1 server. All works! Can you try running this command directly in PowerCLI and see if it works? This is essentially what the utility is running in the background when you select a host and click “Backup” in the GUI:

    Get-VMHostFirmware -VMHost esxhost.domain.local -BackupConfiguration -DestinationPath c:\temp -ErrorAction:SilentlyContinue

    Try that – but replace the host name with an actual host name, make sure the temp folder exists on c:\. If that works, then there is an issue with the GUI I’ve made in your environment. If it doesn’t work, try replace the fqdn of your host, with it’s management network IP instead – see if that works. We’ll find out what is causing the problem 🙂

  96. @Sean
    Thanks for you reply, just tried it.
    If I would just run the command then it would fail since there is no connection to the ESXi host established yet at this point…

    I’ve connected to the ESXi Host from the PowerCLI using “Connect-VIServer” first, after that I was able to obtain the config file and it was downloaded successfully to the c:\temp directory using your command!

    Looks like we have a problem somewhere at the point where your ps script is trying to establish a connection.

    Thanks for your help Sean!
    Regards,
    Alex

  97. Sean I think it’s related to local vSphere PowerCLI configuration and its default behavior regarding the ESXi Server Certficate which is used during the https handshake.

    I’m going to find the correct syntax for “Set-PowerCLIConfiguration -InvalidCertificateAction BadCertificateAction” now will let you know once done. I’ll set it to “Accept Permanently”

    -Alex

  98. This looks like a really awesome utility. I have 2 questions for you, Sean.

    #1) I have a dell server that was built with the default version esxi5. I’d like to reformat it with the dell optimized release of esxi5. If I use this utility to backup the server now using your utility, then rebuild it with the dell optimized release of esxi5, then restore using your utility, will I invalidate any of the “optimizations” from the dell release of esxi5? I believe all Dell has done is embed some specific drivers.

    #2) Can I use this utility to backup and restore to dissimilar hardware?

    Thanks!

  99. Hi Chwrsn

    1. All the basic hypervisor configuration should be backed up to a file. I think everything should be fine to restore to a new installation using a slightly different build. However, I would recommend testing on non-production hardware (stuff that is fine to rebuild if needed!) first.

    2. Yes, the idea being that you use the force checkbox in the restore section, however I haven’t really tested this too much. If Physical NIC slots / numbers change then it may have trouble with Network settings though – so again as per point one, I would highly recommend testing on non-production/test equipment first.

  100. Hi Sean,

    I have been using this for a while now, however, wondered if you have tested with ESXi 5.5 with any success and if not do you have any plans to upgrade script to hande v5.5?

  101. Hi Brian,

    I have not tried, but it may indeed be compatible – its worth a try if you have a spare ESXi 5.5 host to test with. Otherwise I am pretty busy these days and don’t really have any planned updates to make on this at the moment. If I do, I’ll definitely post a blog update, so subscribe to the RSS in that regard anyway – thanks for the comment 🙂

    Cheers
    Sean

  102. Trying 1.3 version on 5.0U3 vCenter server and I get errors:
    PS C:\scripts> C:\scripts\ESXi5-Backup-Restore-Utility-1.3.ps1
    caught a system exception
    OK
    also I get
    ‘exception caught: connect-VIserver is not recognized as a cmdlet’ etc.
    Hosts are also all 5.0U3…
    Would you please help??
    Thank you, Tom

  103. P.S. I don’t know what version VMware PowerCLI I have installed — I ran the script inside Powershell ISE…

  104. Hi Tom,

    The error you are getting is because you ran the script inside the PowerShell ISE. This does not by default load up the PowerCLI snapins. You could do one of these two options to fix it:

    1. Add this line to the very top of the 1.3 version script and run it again from inside the PowerShell ISE: Add-PSSnapin VMware.VimAutomation.Core

    or

    2. Launch PowerCLI from your start menu, and use CD to change directory to where the script is saved, then run it by typing in ./scriptname.ps1 (where scriptname is the name of my script you downloaded, and where you are in the same directory as it is saved!)

    Hope that helps 🙂

    Sean

  105. Hi Team, I keep getting caught a system exception. I have tried all versions of the script, and running in powercli and powershell ise. Host versions are 5.0.0 and have tried running from varrios machines. Any hekp would be greatly appreciated.

  106. Hi there,

    Are you connecting using a vSphere admin’s credentials, or have you tried connecting directly to a host and using the root user to authenticate? Is your DNS setup correctly so that the name of the host’s in the dropdown list resolve properly to an IP address for the management network on hosts if you ping them?

    Cheers

  107. Hi,
    When entering either ip address or hostname of either vcentre server or hosts errors with caught a system exception. I don’t actually get a prompt for username or password. DNS is configured and resolves correctly.

  108. Has anyone tested this with:
    1) vSphere 5.5????
    2) actually restoring???
    What gets restored upon using this to restore — everything, what??
    I will re-read the whole page and comments etc.
    Thank you, Tom

  109. GUys

    What are the steps to do a test restore?
    Host Restore File Location, is this the location of the zip file created during the backup?
    I suspect, the zip file does not need to be extracted, is this correct?

  110. Correct – you just need to provide the location of the .zip file that was created when creating the backup configuration. Don’t forget to use maintenance mode, and after restore the ESXi host will reboot automatically if all goes well. Don’t do this on production hosts without having tried it out before hand on identical hardware 🙂

    Cheers

  111. Hi Sean,
    thank you for this great pice of Code.
    I am searching at the Moment a Tool to move my ESXi Host from a smal SSD to a bigger one.
    So I dont now is this the right Tool for me.
    Can I clone whit your Tool the ESXI to a new SSD or have you a Idea how I can so this.

    All the best Theo

  112. Hi Theo,

    In theory this could work. It won’t clone the drive though. You should make sure the only hardware that changes is the drive itself. Remove the existing drive from the ESXi host, put the SSD in, do a clean install of ESXi on the new SSD. Then you connect this tool to the new ESXi install and restore the backup you took of the old ESXi host configuration. In theory that should work. Don’t forget to backup the configuration of the ESXi host before of course, and keep the old drive safe in case it doesn’t work and you want to go back to booting off the old drive again.

    I assume you just have a standalone ESXi host then – of course if you are using vCenter and have the right licensing, host profiles would be a much easier route!

    Cheers
    Sean

  113. Hy Sean,

    thank you so much for your replay.
    I use HP Microserver Gen8 whit ESXi 5.5
    I your Tool supporting this Version to.
    I have also vcenter webclient apliance installed, whit a licences.
    What way will do the way much easyer?
    Found nothing about this.

    All the best Theo

  114. @Theodor Machnich

    Hi Theo,

    Yes, it should work fine with ESXi 5.5. Which license do you have for vCenter? You’ll need “Enterprise Plus” licensing in order to use vSphere Host Profiles, which will make your life a lot easier. This tool I made is mainly used for single ESXi hosts that are not managed by vCenter, and for cases where you do not have the host profiles feature available to use.

    You can use this tool I made to backup a host configuration, and restore it to another host (or the same host) as long as the hardware does not change. If it does change, you can run into issues like a network configuration applying to a different network card etc…

    Going back to host profiles – that way will be easiest for you – but of course it relies on you having Enterprise plus licensing and that your host is in a cluster in vCenter. You can then read up on host profiles here: http://www.vmware.com/uk/products/vsphere/features/host-profiles

    Cheers
    Sean

  115. Dear Sean,

    thank you for your replay, thats great.
    The last 3 days I was engaged and spend and wast my lifetime to clone my ESXi to a bigger SSD, but this works not really.
    Cloning and to boot the new SSD works perfekt, but I was not able to asume the new diskspace to the ESXi itself.
    So I found no solution to expand the free diskspace, think this can only work in a case to have a program like gparted which can handle vfms5 partition and filesystem.
    To find such a sollution will do the work to move a instalation to new disk verry easy.
    So when I hav much more fun, I will try your way….all the best Theo

  116. This may sound like a dumb question, but when trying a restore, do we just provide the host with a valid ip address and the script will take care of the rest in terms of network config, domain authentication etc?

  117. The process would be – take a backup of the host, then use the restore option after selecting the same host in the drop down for the restore section. Provided the hardware of the actual ESXi host is identical and hasn’t changed, it’ll restore the configuration file that you originally backed up back onto the host, and everything in terms of config should go back to what it was.

    Of course, this relies on the fact that you have the host up and running and the management interface is working with a valid network configuration for the utility to connect to the host on 🙂

    As I always say, I would test the process on a test environment first to ensure you are happy with the way it works first.

    The whole idea behind the host not changing hardware layout at all is because if you were to for example install a new physical NIC in your host, the IDs of hardware could shift around, and the old backup config file could reference a broadcom network card for ID 0 and an Intel for ID1 – the broadcom could be used for vMotion, and the Intel for Management and therefore the config restore would be wrong. That’s why I only recommend this is used if your host doesn’t change at all in terms of hardware layout between the backup and the restore 🙂

    Sean

  118. This may help someone else. I was getting “Exception caught: The argument is null or empty.” and the script would terminate. I removed the following block of code:

    ——————————————————————

    Try {
    [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
    [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)

    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = “vCenter IP or DNS Name”
    $objForm.Size = New-Object System.Drawing.Size(300,200)
    $objForm.StartPosition = “CenterScreen”

    $objForm.KeyPreview = $True
    $objForm.Add_KeyDown({if ($_.KeyCode -eq “Enter”)
    {$vCenter=$objTextBox.Text;$objForm.Close()}})
    $objForm.Add_KeyDown({if ($_.KeyCode -eq “Escape”)
    {$objForm.Close()}})

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(75,120)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = “OK”
    $OKButton.Add_Click({$vCenter=$objTextBox.Text;$objForm.Close()})
    $objForm.Controls.Add($OKButton)

    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Size(150,120)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = “Cancel”
    $CancelButton.Add_Click({$objForm.Close()})
    $objForm.Controls.Add($CancelButton)

    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,20)
    $objLabel.Size = New-Object System.Drawing.Size(280,45)
    $objLabel.Text = “Please enter the IP or Name of your vCenter Server or standalone ESXi host:”
    $objForm.Controls.Add($objLabel)

    $objTextBox = New-Object System.Windows.Forms.TextBox
    $objTextBox.Location = New-Object System.Drawing.Size(10,65)
    $objTextBox.Size = New-Object System.Drawing.Size(260,20)
    $objForm.Controls.Add($objTextBox)

    $objForm.Topmost = $True

    $objForm.Add_Shown({$objForm.Activate()})
    $handler = {$objTextbox.Select()}
    $objForm.Add_Load($handler)
    [void] $objForm.ShowDialog()

    if($defaultVIServers){
    Disconnect-VIServer -Server $defaultVIServers -Confirm:$false -ErrorAction SilentlyContinue
    }

    $vCenterConnection = Connect-VIServer $vCenter -ErrorAction Stop

    }

    Catch [SystemException] {
    “caught a system exception”
    [Windows.Forms.MessageBox]::Show(“Exception caught: $_.”, “Exception”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Exclamation)
    break
    }
    Finally {
    # DO NOTHING
    }

    ————————————————————————

    Then after saving the script from the CLI I connected manually:

    connect-VIserver -server 192.168.0.100

    then after about 30 seconds I was prompted to login and I did so. After loggin in I changed directory to the new modified script loction and ran:

    .\fixed_VSBackup.ps1

    The script ran and I was able to backup. The only thing that didnt work for me in the script was when I choose my destination directory it didn’t populate the text box. I had to type it in.

    Hope this helps!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.