What's Popular

Meh, Whatever is Featured

Linking Active Directory to Palo Alto

 ###First you need to create a server profile under the LDAP section. DEVICE>Server Profiles>LDAP then click on the Add down at the bo...

Showing posts with label PowerCLI. Show all posts
Showing posts with label PowerCLI. Show all posts

Friday, October 12, 2018

PowerCLI Mass VM Port Group Change

1.    First off, you will have to declare your variables once you are logged into the vCenter server. You do this by the following:
    a.    You can declare your cluster variable with: $Cluster = “TestCluster”
    b.    You can then you can declare your old network with: $OldNetwork = “TestPG”
    c.    Finally, set the variable for the new network with: $NewNetwork = “NewTestPG”

2.    Now your variables are set and you can now pull them in the following script:
    a.    Get-Cluster $Cluster |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName –eq $OldNetwork} |Set-NetworkAdapter –NetworkName $NewNetwork –Confirm:$false

3.    That is for clusters, if you just want to do all your VMs, you can do the following:
    a.    Declare your variables:
        i.    Set your variable for the old PortGroup: $OldNetwork = “TestPG”
        ii.    Set the variable for the new PortGroup: $NewNetwork = “NewTestPG”

4.    Now you set your variables for your port groups, you can go ahead and execute your script with the declared variables:
    a.    Get-VM |Get-NetworkAdapter |Where {$_.NetworkName –eq $OldNetwork} |Set-NetworkAdapter –NetworkName $NewNEtwork –Confirm:$false

5.    You should see the process go through in the PowerCLI area and also you should see it in vCenter.

Thursday, September 13, 2018

How to Login to vCenter or ESXi with PowerCLI


·         Open PowerShell ISE or the PowerCLI command line.
o   If you open through PowerShell or PowerShell ISE, you need to load the PowerCLI environment variables.
o   Open the "Initialize-PowerCLIEnvironment.ps1 script located at C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts.
§  (This will be here after you installed PowerCLI)
·         In order to get the PowerCLI to connect to servers on the network, you have to bypass the certificate error by putting in the following:
o   “Set-PowerCLIConfiguration –InvalidCertificateAction Ignore”
·         Then you can connect to your vCenter/ESXi server with the following command:
o   “Connect-VISever –Server “yourIPaddress/FQDN” –User “yourDomain\UserName” – Password “YourPassword”.
o   Example: Connect-VIServer –Server 1.1.1.1 –User vsphere.local\JohnDoe –Password 12345678
·         You should get a confirmation you have logged into the server and you can now start executing PowerCLI commands.

Wednesday, May 16, 2018

Simple PowerCLI for Deleting Orphaned VMs


  • First, you can try these steps from the official VMware KB. I tried this and it failed on several occasions, so I pursued another avenue.
  • So if the above did not work, there are other ways to do this (I found a few in Google), but this PowerCLI was the easiest and simplest way to delete these VMs.
  • Open PowerShell ISE in Administrator Mode
  • Open the "Initialize-PowerCLIEnvironment.ps1 script located at C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts
    • This will be here after you installed PowerCLI
  • In order to get the Power CLI to connect to servers on the network, you might have to bypass the certificate error by putting in the following code:
    • Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
  • Then you can connect to your server with the following command:
    • Connect-VIServer -Server x.x.x.x -User vsphere.local\example - Password XXXXXXX
  • Once this is done, you can now start deleting the orphaned VMs in vSphere by executing the following:
    • Remove-VM –VM (VM Name) –DeletePermanently –Confirm:0
  • Be WARNED! This will remove the VM from vSphere and you need to make sure this is the exact one you need to delete.

Friday, May 11, 2018

Simple PowerCLI Backup for OVA/OVF

  • Before performing this process, make sure you have your VM CD-Rom not pointing to a datastore and pointed to the “Client Device” and have the CD Rom disconnected. Having the CD-Rom pointed to a datastore can cause problems.
  • Open PowerShell ISE in Administrator Mode
  •  Open the "Initialize-PowerCLIEnvironment.ps1 script located at C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts
    •  This will be here after you installed PowerCLI
  • In order to get the Power CLI to connect to servers on the network, you have to bypass the certificate error by putting in the following code:
    •  Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
  •  Then you can connect to your server with the following command:
    •   Connect-VIServer -Server x.x.x.x -User vsphere.local\example - Password XXXXXXX
  • Once this is done, you can now start your exporting of your OVA/OVF with the next steps.
  •  Make sure you know your destination folder and the name of your VM from vCenter. Once you have this, perform the following command:
    •  Get-VM –Name ExampleTest | Export-VApp –Destination C:\Users\Example\Desktop –Format Ovf or ova