Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

Merge VMware and NetApp VM information

$
0
0

I have a report that lists information for virtual machines in vCenter:

 

get-vm | select name, numcpu, memorygb, provisionedspacegb

 

However, each VM is also connecting to an iSCSI LUN on NetApp at the OS level using an iSCSI initiator

 

I need to figure out the size of the iSCSI LUN that this VM connects to at the OS level, then merge that with my existing columns.

 

When I'm done I need to have a report like this:

 

NameNUMCPUMemoryGB
ProvisionedSpaceGB
iSCSI LUN Size

 

 

I've got the Netapp PowerShell toolkit installed

 

NetApp PowerShell Toolkit 4.7 released! - NetApp Community

 

 

Has anyone successfully done something like this - taken VM data from vCenter and data from NetApp, and combined them into a single report that pulls data both from vCenter and from NetApp?


vSphere automation based on VM custom attribute values

$
0
0

Hi LucD and Co. I'm about to take on an interesting pet project surrounding automation of vSphere "things" based on custom attribute values found on VMs and I'm posting an open question for ideas as to how to go about doing this. To be very clear, I'm not asking for people to hand over code to me--only a methodology for those who have worked with custom attributes in PowerCLI before. I know it's not difficult, per se, but since there are always multiple ways to skin a cat I'm wondering what the shortest, cleanest, most efficient path may be here.

 

Background

 

VMware PKS deploys K8s clusters as virtual machines. These clusters can be of various sizes and contain one or more masters and one or more workers. Each node is represented by a single VM. Every VM belonging to the same cluster has a custom attribute written into a field called "deployment". An example value of this "deployment" field is "service-instance_9c854520-8e43-4566-845e-111e6a1e8425". Additionally, a second field is present called "job" which specifies the role type for each VM, values of which are either "master" or "worker". All VMs in the same deployment are also connected to the same NSX-T logical switch which appears in vSphere's inventory as a custom switch type. For example, all VMs in the same deployment that have "service-instance_9c854520-8e43-4566-845e-111e6a1e8425" written into that custom attribute would exist on a logical switch named "pks-9c854520-8e43-4566-845e-111e6a1e8425". There are other logical switches created that also begin with this name but end with different suffixes.

 

Problem Statement

 

While this system is all well and good, there are some problems created and therefore gaps I wish to close:

  1. When a cluster is created containing multiple masters, if those masters land on the same vSphere cluster there are no anti-affinity DRS rules automatically created. This obviously creates the possibility that a single ESXi host failure takes out more than half of the masters effectively rendering a K8s cluster down.
  2. All VMs from a deployment/K8s cluster have names created in the format of "vm-{GUID}" and are dumped into the same vSphere inventory location. This makes it difficult for administrators to quickly pinpoint VMs associated with the same deployment/K8s cluster.

 

Goals

 

Based on the above problems/gaps, I wish to

  1. Automate the creation of anti-afinity DRS rules. In order to do this, a few different pieces of logic have to be implemented.
    1. VMs have to be scanned for the "deployment" custom attribute value. Alternatively, the logical switch can be scanned, but this object is not reported by the "Get-VDportgroup" or "Get-VirtualPortgroup" cmdlets.
    2. VMs need to be matched up based this "deployment" value. Alternatively, the logical switch can be scanned.
    3. The "job" value needs to be read on those sharing the same "deployment" value and, if there are more than 1 master found, the names of all masters need to be stored in memory.
    4. If all masters reside in the same vSphere cluster, an anti-affinity rule should be created with all masters as members forcing them to run on separate hosts.
  2. Automate the creation and organization of all VMs in a given deployment into a vSphere folder. Some slightly separate logic is needed here.
    1. VMs have to be scanned for the "deployment" custom attribute value.
    2. VMs need to be matched up based on this "deployment" value.
    3. A new folder should be created in a given inventory location with the name matching "deployment" value.
    4. All VMs sharing the same "deployment" value should be moved into the newly-created vSphere folder.

 

Now that you have all the information, how would you tackle this from a high-level perspective? I think the emphasis needs to be on speed and as much reduced impact on the vCenter API as possible because these PKS VMs could exist in a sea of thousands, and recursing through the entire vCenter inventory would probably not go well. Interested in ideas, commentary, and questions.

 

Message was edited by: Chip Zoller Added note about these NSX-T logical switches are not returned by PowerCLI available cmdlets in modules VMware.VimAutomation.Core or .Vds.

Exporting RVtools report in CSV from Power Cli automation script

$
0
0

Hi all,

Can we Export the RV tools Report through Power Cli script.

I could get the details from RV tools per VC , but i want to get details of RVtools report of multiple VCs in sheet

from Power Cli script.

 

E.g.

 

RVTools.exe -passthroughAuth -s VM01.ze.zk.com -c ExportAll2xls -d %EXPORTDESTINATION% -f VM01_%RUNDATETIME%.xls

 

START /WAIT RVToolsSendMail.bat smtpek.us.zk.com 25 VMwareMEmailNotifications@ZK.comVMSV49_RVTooolsExport@ZK.com %LOG_FILE_ARCHIVE% >> %LOG_FILE_2% 2>&1

 

Thanks in advance.

 

vmk2014

Exporting VM Tags in readable format

$
0
0

So I have been working on a script to import Tags from a CSV into vCenter so we can do batch imports of our vCenter tags (its much easier to edit 1000 rows of a spreadsheet than it is to do it directly in vCenter.)

See: Re: Working with Batch Tags in PowerCLI for the script itself.

 

The problem I have run into is I now have the import script running properly, but now I require a way to export the updated data to a readable CSV file so I can ensure the data being input is up to date. The issue with the export from powerCLI is how vCenter stores tags. within vCenter, tags are stored as TagCategory/TagName together as an object called $Tag and each $Tag is stored in a different element of the array Get-tagassignment. The problem is the input CSV is split out with each Line consisting of the VMName and which Tags it contains under each category with each category being a column.

 

so The CSV is as follows:

VMName     |     Category 1     |     Category 2     |      Category 3     |      Category 4      |

VM1            |                         |       Tag Value     |                           |     Tag Value         |

VM2            |     Tag Value      |      Tag Value      |     Tag Value        |                            |

 

Where the tags in VMWare are stored as follows:

 

VMName     |     Category/Tag        |

VM1            |     Category 2/Tag     |

VM1            |     Category 4/Tag     |

VM2           |     Category 1/Tag      |

VM2           |     Category 2/Tag      |

VM2           |     Category 3/Tag      |

 

So I am looking for a way to get the current output into the format I need, so I can basically create a cyclic loop so the updated tags can be exported back to the CSV so when the CSV is updated it already reflects any changes (such as additional VMs or Removed VMs)

UnableToFindDependencyPackage when installing VMware.PowerCLI in Windows

$
0
0

Hi all,

 

I'm getting the following error when trying to install VMware.PowerCLI on both Windows 2012 R2 and Windows 2016 using Install-Module (Powershell version 5.1):

 

PS C:\Windows\system32> Install-Module -Name VMware.PowerCLI

PackageManagement\Install-Package : Unable to find dependent module(s) (VMware.VimAutomation.Cis.Core)

At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21

+ ...          $null = PackageManagement\Install-Package @PSBoundParameters

+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutomation.Cis.Core:String) [Install-Package], Exception

    + FullyQualifiedErrorId : UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPack

   age

 

I have tried installing VMware.VimAutomation.Cis.Core directly using Install-Module, and I can do that, but when I then try to install VMware.PowerCLI, I get the same error message.  Importing Cis.Core doesn't help either: always the same error message above.

 

Here is a verbose run of the command:

 

PS C:\Windows\system32> Install-Module -Name VMware.PowerCLI -Verbose

VERBOSE: Using the provider 'PowerShellGet' for searching packages.

VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.

VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.

VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.

VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='VMware.PowerCLI'' for

''.

VERBOSE: Total package yield:'1' for the specified package 'VMware.PowerCLI'.

VERBOSE: Performing the operation "Install-Module" on target "Version '11.1.0.11289667' of module 'VMware.PowerCLI'".

 

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change its

InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from

'PSGallery'?

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

VERBOSE: The installation scope is specified to be 'AllUsers'.

VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'.

VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.

VERBOSE: Downloading module 'VMware.PowerCLI' with version '11.1.0.11289667' from the repository

'https://www.powershellgallery.com/api/v2'.

VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='VMware.PowerCLI'' for

''.

VERBOSE: Package 'VMware.VimAutomation.Sdk' is already installed.

VERBOSE: Package 'VMware.VimAutomation.Common' is already installed.

VERBOSE: Package 'VMware.Vim' is already installed.

VERBOSE: Searching repository

'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='VMware.VimAutomation.Core'' for ''.

VERBOSE: Searching repository

'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='VMware.VimAutomation.Cis.Core'' for ''.

PackageManagement\Install-Package : Unable to find dependent module(s) (VMware.VimAutomation.Cis.Core)

At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21

+ ...          $null = PackageManagement\Install-Package @PSBoundParameters

+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutomation.Cis.Core:String) [Install-Package], Exception

    + FullyQualifiedErrorId : UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

 

Anyone experience this?  Any insight into this error?

Select only one result out of many - Get-VIEvent

$
0
0

Hi,

 

I have a query that looks like this:

 

$cls = Get-Cluster "clusterName" | Get-VM | Get-VIEvent -Type "Info" | Where "UserName" -eq "username" | Select @{Name='Name';E={$_.vm.name}}, CreatedTime

 

I'm wondering how to have it only return one event per VM that is created by the user "UserName". If I run the command above it returns several events per VM.

 

Another question, any idea on how to clear all variables in the ISE? Sometimes i have to close and reopen the ISE to clear some variables as it hangs on to them in memory.

enable ssh from vSphere Client cli

$
0
0

Is there any way to enable ssh (Start and stop with host) from command line remotely.

 

ie: snmp - can use vicfg-snmp.pl, how about ssh service ?

 

GUI way:

vSphere Client > Security Profile > Services section > SSH > Start and stop with host

migrate vm network from one vds to another

$
0
0

I need to migrate about 700 VMs from one VDS to another in the sane vCenter.

 

Any help will be highly appreciated


PowerCLI script for vSphere capacity planning

$
0
0

Hello everyone!

 

After recent discussion on vSphere Capacity planning, I thought I would share one of the tools I use for this purpose. This is a side project I've been working on for few months.

 

I present to you, my very own "VMware Capacity & Performance Report PowerCLI script (v2.1 Community edition)"

 

http://1drv.ms/1J00vkq

(Click here then click on "Download")

 

This is a complex PowerCLI script I wrote, that generates an e-mail report that gives you insight into the current state of your VMware vSphere environment's capacity. It generates tables, pie charts and line charts with information about CPU, Memory & Storage capacity, VM Provisioning Potential, Cluster Resilience and more. Check the script's #INFORMATION block for more information about prerequisites, script input and output.

 

Have a look at the report it generates and let me know what you think of it!

Please share your thoughts and comments!

 

Marc Davoli

http://ca.linkedin.com/in/marcvincentdavoli/

 

Edited on May 25 : Changed OneDrive link to updated script v2.1 with bugfix (for cluster names with a space in it)

Power CLI script to get VMhost count per cluster

$
0
0

I am trying to get 2 reports one is VM host count per cluster an another one is all the host name and cluster name as excel output. As like below format

Report 1

Cluster Name        vHost Count

Cluster01                     35

Cluster02                     08

 

Report 2

 

HostDatacenterCluster

 

I tried as below but does not worked as expected.

 

foreach ($vCenter in $vCenters)

{

        Connect-VIServer $vCenter -Username $vcUser -Password $vcPassword

}

 

 

$report = foreach ($vc in $global:DefaultVIServers) {

  Get-Cluster | Select Name, @{N="Host Count"; E={($_ | Get-VMHost).Count}},  @{N="VM Count"; E={($_ | Get-VM).Count}} | export-csv

}

 

 

Can anyone help on this.

 

Thanks

Move-VM

$
0
0

I was attempting to vMotion VM Win-9 from sa-esxi-03,vclass.local to sa-esxi-01.vclass.local.  I tried to use Move-VM and specified the VM and the Destination in the following way:

 

Move-VM -VM Win-9 -Destination sa-esxi-01.vclass.local

 

If you look at the attached graphic, you will see the error indication I received.  I cannot find what I did wrong.  I had previously done a Connect-VIServer to add my vCenter Server.  I then executed a Get-VMHost and all the hosts were listed as expected.  I executed a Get-VM and a list of all the VMs was shown as expected.

 

Oh, I had also previously vMotion'd the same VM from sa-esxi-03,vclass.local to sa-esxi-01.vclass.local through the vSphere Client without incident.  So I know it works just fine.

 

vCetner Server Appliance 6.70 Build 8170161

ESXi 6.7.0 Build 8169922

PowerCLI 6.5 Release 1 Build 4624819

 

Can someone please point me in the right direction?

New Folder

$
0
0

Hi ,

 

I am trying to create lots of folders of type 'Datacenter' and their corresponding permissions under a newly built vCenter.

All the inputs are fed from csv.

I want to know the working syntax of New-Folder and New-VIPermission for the same-

 

#Values like $folder,$vCenter,$fRole, $Principal  and are fed from csv through a loop

#loop begins

#create folders of type datacenter under vCenter

New-Folder -Name $folder -Server $vCenter  ( How could I create a folder of type datacenter, get-folder has a type parameter but i saw new-folder doesnt have one )

 

#create permissions for those folders

New-VIPermission -Role $fRole -Principal $Principal -Entity $folder

 

#loop ends

Modify PortGroup Nic Teaming Policy

$
0
0

Version Info:
vSphere 6.7U1
PowerCLI 6.5.1
Standalone Host (no vCenter yet)

 

Created a Standard Virtual Switch on my Host. Wanting to create 2 PortGroups used for iSCSI connection. Created a script that works... have created the PortGroups, then able to create the VMkernel Ports & assign them to the proper PortGroup. All seems fine when I run the script.. i.e. no errors. But, when I log into the Host UI and verify my configs 'took', I see the Nic Teaming Policy for each of my PortGroups did not get changed. If you recall, for iSCSI, you have to have ONLY ONE vmnic assigned per PG as 'active', and all others as 'unused'. In my script, I state to use 1 of my vmnic's as active and 1 as unused, but the PowerCLI configuration doesn't take affect on the Host. Just trying to figure out why. Below is the script I created for this configuration:

 

#Create vSwitch1 PortGroups and VMkernel PortGroups

$vmk1 = 'ISCSI-1','ISCSI-2'

 

$i = 0

if($i -lt 2) {

    foreach ($vmk in $vmk1) {

    #Get the vmnics for setting Active & Unused for each Portgroup

    $vmkAct = Read-Host "

    Enter Active Nic for $vmk teaming policy (vmnic#) "

    $vmkUnused = Read-Host "

    Enter Unused Nic for $vmk teamng policy (vmnic#) "

    #Create the Portgroups, then set the Nic Teaming Policy

    New-VirtualPortGroup -VirtualSwitch $vs1 -Name $vmk | Out-Null

    Get-VirtualPortgroup -Name $vmk | Get-NicTeamingPolicy | Set-NicTeamingPolicy -InheritFailoverOrder $false -MakeNicActive $vmkAct -MakeNicUnused $vmkUnused | Out-Null

    $i++

    }

 

#Create vSwitch1 VMkernel PortGroups

$n = 1

    foreach ($vmk in $vmk0) {

    $vs1vmkIP = Read-Host "Enter vmk$n IP "

    New-VMHostNetworkAdapter -VirtualSwitch $vs1 -PortGroup $vmk -IP $vs1vmkIP -SubnetMask $vmkSubnet -Mtu 9000 -Confirm:$false | Out-Null

    $n++

    }

}

 

 

 

Thanks for any assistance provided.

 

~coolsport00

(Shane)

#vExpert , #VeeamVanguard
Sr. Systems Engineer

Unable to get the file name

$
0
0

Hi,

 

Please help to get the filename using variable as I am unable to get.

 

Please help

 

$fold = test

$date = Get-Date -format dd-MMM-yyyy-hh-mm-tt

$reportlocation = "D:\reports\("POC_" + "$fold" + "_VM_Reporting_$date").xlsx

 

I am getting the below error

 

+ $reportlocation = "D:\reports\("POC_" + "$fold" + "_VM_Reporting_$date").xlsx

+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Unexpected token 'POC_" + "$fold" + "_VM_Reporting_$date").xlsx

#$fold = "Client' in expression or statement.

At D:\Jenkins\Scripts\test.ps1:180 char:67

+                                                                   ~~~~~~~~~~~~~~

The string is missing the terminator: ".

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : UnexpectedToken

command for additional data disks always be Thin Provisioned

$
0
0

Hello Team,

 

I need command or script for creating additional (thin provisioned) data disk via command.


Host firmware, hba driver, NIC version etc,

$
0
0

Hi All,

 

Can we pull the ESXi Build version, Host firmware, HBA driver version, HBA firmware version and Host NIC version from power cli at the cluster level?

 

 

Thanks

vmk

Report datastore

$
0
0

Hello,

I have this script where I usually extract disk usage, I would like to add also host name and device id (naa.60050733018d8318380000000000d)

 

Thanks for support

 

Function Percentcal {

    param(

    [parameter(Mandatory = $true)]

    [int]$InputNum1,

    [parameter(Mandatory = $true)]

    [int]$InputNum2)

    $InputNum1 / $InputNum2*100

}

 

 

$datastores = Get-Datastore | Sort Name

ForEach ($ds in $datastores)

{

    if (($ds.Name -match “Shared”) -or ($ds.Name -match “”))

    {

        $PercentFree = Percentcal $ds.FreeSpaceMB $ds.CapacityMB

        $PercentFree = “{0:N2}” -f $PercentFree

        $ds | Add-Member -type NoteProperty -name PercentFree -value $PercentFree

    }

}

$datastores | Select Name,@{N=”UsedSpaceGB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity – $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N=”TotalSpaceGB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}} ,PercentFree | Export-Csv C:\Users\gemela\Desktop\VM_CLuster_Host_Datastore.csv -NoTypeInformation

#It can be use also gridview

#|Out-GridView

PowerCLI very slow to load on a Windows 2012R2 Server

$
0
0

Hi all,

PowerCLI 5.5 is very slow to load on my Windows 2012R2 Server, I have done some tests

 

test 1 - load PS Snapin on my worstation (Windows 8.1 64bit - SATA Hard Disk)

PS C:\Users\MyUser>  Measure-Command {Add-PSSnapin vmware.vimautomation.core}

 

Days              : 0

Hours            : 0

Minutes          : 0

Seconds          : 1

Milliseconds      : 871

Ticks            : 18717065

TotalDays        : 2.16632696759259E-05

TotalHours        : 0.000519918472222222

TotalMinutes      : 0.0311951083333333

TotalSeconds      : 1.8717065

TotalMilliseconds : 1871.7065

 

test 2 - Load PS Snapin on a Windows 2012R2 Server not connected to the internet, CRL check enabled

 

PS C:\Users\MyUser>  Measure-Command {Add-PSSnapin vmware.vimautomation.core}

 

Days              : 0

Hours            : 0

Minutes          : 0

Seconds          : 51

Milliseconds      : 603

Ticks            : 516030768

TotalDays        : 0.000597257833333333

TotalHours        : 0.014334188

TotalMinutes      : 0.86005128

TotalSeconds      : 51.6030768

TotalMilliseconds : 51603.0768



Test 3 - Load PS Snapin on a Windows 2012R2 Server not connected to the internet, CRL check disabled

 

PS C:\Windows\system32>  Measure-Command {Add-PSSnapin vmware.vimautomation.core}

 

Days              : 0

Hours             : 0

Minutes           : 0

Seconds           : 16

Milliseconds      : 323

Ticks             : 163238507

TotalDays         : 0.000188933457175926

TotalHours        : 0.00453440297222222

TotalMinutes      : 0.272064178333333

TotalSeconds      : 16.3238507

TotalMilliseconds : 16323.8507

 

As you can see there is an improvement when I disable the CRL check according to this article: http://blogs.vmware.com/PowerCLI/2010/01/troubleshooting-slow-startup-with-powercli-40-u1.html

But I still have 16 seconds to load the Snapin against 1 second only on my workstation (that has far less computational resources!)

 

Any help is appreciated.

ESXI 6.0 Certificate Update

$
0
0

Can anyone Suggest Is there anyway to Update the Certificate of ESXI 6.0 Or Higher Version Using Powercli.
So far I do not see any Command by VMware Powercli for that.

SSO issue with in power cli in C#

$
0
0

Hello every one !

 

I am currently working on a tool written in C# using the Powershell C# instance to communicate with our vcenter

 

vsphere version is 6.5.0.20000 Build 9451637

 

PowerCLI Version

----------------

VMware PowerCLI 6.5 Release 1 build 4624819

---------------

Component Versions

---------------

VMware Cis Core PowerCLI Component 6.5 build 4624453

VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

 

tool running on .Net Framework 4.7.1

 

My issue is:

When i try to run this command:

 

$myTag = Get-Tag BKP_OTVCSA_CL3_J05_01

 

i get the following error:

 

vSphere single sign-on failed for connection '/VIServer=username@vcenterURI:443/'. Future operations which require single sign-on on this connection will fail. The underlying cause was: Specified algorithm is not valid.

 

Any other command is working fine. but all Tag related commands are failing.

 

This was working before we updated the vcenter and power cli (previous version 6.0 R2)

 

Any help is welcomed.

 

Simon

Viewing all 14549 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>