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

PowerCLI Error

$
0
0

Hi All,

 

We are using vCenter & ESXi with 6.7 version.

 

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
   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891
   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891
   VMware Vds PowerCLI Component 6.5 build 4624695
   VMware Cloud PowerCLI Component 6.5 build 4624821
   VMware HA PowerCLI Component 6.0 build 4525225
   VMware HorizonView PowerCLI Component 7.0.2 build 4596620
   VMware Licensing PowerCLI Component 6.5 build 4624822
   VMware PCloud PowerCLI Component 6.5 build 4624825
   VMware Storage PowerCLI Component 6.5 build 4624820
   VMware vROps PowerCLI Component 6.5 build 4624824
   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

 

Data is incorporated in a CSV file.

While trying to change the portgroup for a VM. I am getting below error.

Even manually specifying the VM name & the port group also possess same error.

 

command executed:

Get-VM $c.name | Get-NetworkAdapter | ?{$_.Name -eq "Network adapter 1"} | Set-NetworkAdapter -NetworkName $c.portgroup  -Connected:$true -Confirm:$false

 

Error:

Set-NetworkAdapter : 2/6/2019 9:28:42 AM        Set-NetworkAdapter

Could not obtain

the result of task

'/VIServer=domain\adminaccount@vCenter:443/Task=Task-task-1457/'. Task

name is 'ReconfigVM_Task'. The following error occured: Exception has been

thrown by the target of an invocation.

At line:1 char:76

+ ... apter 1"} | Set-NetworkAdapter -NetworkName $c.portgroup  -Connected: ...

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

    + CategoryInfo          : NotSpecified: (:) [Set-NetworkAdapter], VimExcep

   tion

    + FullyQualifiedErrorId : ViCore_TaskCoreService_ConvertTaskResult_Failed,

   VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapt

  er


Can we enable Hot CPU Add in a VM through Power cli without Re-boot ?

$
0
0

Hi All,

 

Can we enable Hot CPU Add in a VM through Power cli without Re-boot? We want to enable for bulk VM's.

 

 

 

Thanks

vmk

Create a DRScluster group for vm with no vm

$
0
0

As we deploy virtual centers we create  standard groups and a rule for specific app servers. Is it possible to create a vm group with no virtual machines and assign a rule. The hosts exist but the vm come later. Nice to have the groups and rule in place when we start to build out the clusters

 

thanks

Need help with a PowerCLI script that won't fully execute to Remove Snapshots

$
0
0

I'm hoping someone can tell me why my script won't complete.  I'm trying to display and delete snapshots that are leftover by Commvault.  I have it written so I can search by Name or Description by removing the marking or un-marking your preference.  Everything works except for the section in "blue" below.  My variable, $snaps, shows the desired output but the code below it won't delete the snapshots.  It doesn't have any errors or give me a reason why it's not working.

 

* Parts of the script below came from other sources.

 

Hoping someone can assist me.

 

Thanks,

Charles

 

*********************************************************************************

## Loads VMWare PowerCLI ##

$ErrorActionPreference = "SilentlyContinue";

$ProgressPreference = "SilentlyContinue";

Add-PSSnapin VMWare* -ea SilentlyContinue

Import-Module VMWare* -ea SilentlyContinue

 

# Connects to the desired vCenter

Connect-VIServer fetsvmvc01.ftbco.ftn.com

 

# Sets the maximum number of taks that can run in vCenter (don't want to overload the storage with too many IOPs)

$maxtasks = 4

 

#Clear Screen!

CLS

 

# Lists all snapshots based on the Name or Description and deletes them. 

$snaps = get-vm | get-snapshot  | where {$_.Name -match "__GX_BACKUP__"}| Format-Table -Property VM,Name,Created,Description, SizeMB

# $snaps = get-vm | get-snapshot  | where {$_.Description -match "Snapshot created by Commvault"}| Format-Table -Property VM,Name,Created,Description, SizeMB

 

#Show the contents of the variable

$snaps

 

$i = 0

while($i -lt $snaps.Count){

Remove-Snapshot -Snapshot $snaps[$i] -RunAsync -Confirm:$false

$tasks = Get-Task -Status “Running” | where {$_.Name -eq “RemoveSnapshot_Task”}

while($tasks.Count -gt ($maxtasks-1)) {

sleep 30

$tasks = Get-Task -Status “Running” | where {$_.Name -eq “RemoveSnapshot_Task”}

}

$i++

}

scaling or clone with powercli

$
0
0

hello

 

My topic and find a way to redirected the traffic in case of overload (use more than 80% of the use of RAM) of a machine Vm in (private cloud - vmware) to another machine vm this time in (public cloud - openstack)

 

 

The first step C to create an alarm in vmware Decliding a script powerCLI or processing to  Declanche an instance in openstack

Is this a good track?

If not, are there any other interesting tracks?

Thank you for sharing with me your ideas or documents that you see useful.

 

 

cordially

I'm in need of a PowerCLI script to upgrade the VM tools version to execute Setup file from a folder on ESXi 6.5 environment

$
0
0

I'm in need of a PowerCLI script to upgrade the VM tools version to execute Setup file from a folder on ESXi 6.5 environment.

Planning to upgrade the vmware tools version 10.3.2. This setup is copied to C:\ drive in all the servers. From there, script should select the the suitable version of OS file and execute the respective Windows OS version x32 or x64 bit file version.

 

Thanks in advance.

PowerCli Move Folder with full path or folderID

$
0
0

Hi,

 

I'm looking for a way to register a VM with a specific folder.

"New-VM  -Location $folder"

But it's working only if one folder existing with that name. I did a function to get the full path but it doesn't seem to accept it.

So i tried with "Move-VM" after the registration but it doesn't work neither.

 

New-vm or Move-Vm can accept fullpath folder or idfolder ?

 

Kind Regards

Network Details

$
0
0

Hi,
I am writing a script to fetch

1. Physical adapter details like device name , Actual link speed, Configurable speed for hosts present in every Datacenter location.

I am trying to do something like this -

 

$datacenters = Get-Datacenter -Server vCenterServer

&{foreach($dc in $datacenters)

    {              

            foreach($vmhost in Get-VMHost -Location $dc)

            {

             

             }

    }

}

 

csv as well I am trying to have columns like

Datacenter, Host, adapter, Actual Link speed , Configurable Speed.

 

Can someone please guide me


Script to get vMotion event scheduled

$
0
0

Hi All,

We are getting failed and success vMotion event in our vCenter. the failed ones VMs are facing performance issues.

 

would like to see if any one have created script of vMotion events including failed one , succeeded ones. it need to be scheduled and send as email report in html or csv format.

 

Thanks in Advance.

Mass Change PortGroups

$
0
0

Hey all,

 

I am trying to find a way to migrate my VMs from a vDS to vSS, but can't seem to find a way to do so without shutting down the VMs and then changing the portgroup attached.  To speed up the method I would like to use powercli to target a vHost and then find any portgroups named "XXX-VDS" and migrate them to the equivilant vSS name (ie XXX-VSS).

 

Thank you!

Exception calling "UpdateAssignedLicense" with "3" argument(s): "A specified parameter was not correct: entityId"

$
0
0

Hi all,

 

I'm trying to get some lab autodeployment scripts setup, but am running into a licensing issue with the vCenter license. What we're doing is a fully automated deployment of the lab using PowerShell Core on Linux and everything works, except for one small piece of code:

 

    #Add key to inventory

    $labvc = Connect-VIServer $labvCenter -User $labUser -Password $labPassword -WarningAction SilentlyContinue

    $lm = get-view $labvc

    $lmAdd = get-view $lm.Content.LicenseManager

    $lmAdd.AddLicense($vCenterKey,$null)

    sleep(10)

    #Assign key

    $lm = get-view $labvc.ExtensionData.content.LicenseManager

    $lmAM = get-view $lm.licenseAssignmentManager

    $lmAM.UpdateAssignedLicense($labvc.InstanceUuid,$vCenterKey,$null)  

The key is being added to the license inventory just fine, but when executing the UpdateAssignedLicence at the bottom, I get the following error:

 

Exception calling "UpdateAssignedLicense" with "3" argument(s): "A specified parameter was not correct: entityId"

+     $lmAM.UpdateAssignedLicense($labvc.InstanceUuid,$vCenterKey,$null ...

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

+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : VimException

I've already checked that $labvc.InstanceUuid does return the proper value and that $vCenterKey is set correctly but most of the times this error keeps popping up. However, if I keep retrying the exact same code, at some point it will suddenly succeed (and I can't figure out why). It's truly just a copy-paste that I keep doing and at some point it's suddenly licensed.

 

Does anyone have any idea on how I can either improve the above code so it always works, or how I can resolve the issue (I realise the answer to both questions might be the same...).

 

Some additional information:

- vCenter version is 6.7

- PowerCLI version is 10.2

 

MrBoogiee

PowerCLI to extract all vSwitch network info to CSV

$
0
0

Hi People,

 

 

 

 

Can anyone please assist me with the PowerCLi script to be executed against one VCenter server to gather each VMHost (ESX & ESXi) Networking configuration as in Configuration tab | Networking | View: vSphere Standard Switch

 

 

 

For Example here as follows:

 

 

 

ESX01

  vSwitch0, vmnic3, vmnic4

  Service Console 2

  vmk2: 10.1.1.4 | VLAN 1

 

 

  Management Network

  vmk1: 10.1.2.1 | VLAN 2

 

 

  VMotion

  vmk2: 10.1.3.1 | VLAN 3

 

  vSwitch1, vmnic2, vmnic1 vmnic0

  VLAN 45

  VLAN 12

  MS Cluster Heart Beat Network

  VLAN 8

 

 

 

ESX02

  vSwitch0, vmnic3, vmnic4

  Service Console 2

  vmk2: 10.2.1.4 | VLAN 1

 

 

  Management Network

  vmk1: 10.2.2.1 | VLAN 2

 

 

  VMotion

  vmk2: 10.2.3.1 | VLAN 3

 

  vSwitch1, vmnic2, vmnic1 vmnic0

  VLAN 45

  VLAN 12

  MS Cluster Heart Beat Network

  VLAN 8

 

 

...

 

 

 

Any type of format will do in CSV as long as the information can be used to create the vSwitch manually on each ESX host.

 

This is just in case I need to rebuild one of the ESX / ESXi host in the event of the ESX to ESXi upgrade went wrong which requires me to rebuild the server from scratch.

 

 

 

Cheers,

 

 

Al

Script to collect from all VM adapters - portgroup (network), VLAN ID, subnet mask, gateway address

$
0
0

This info is not all in one place, which adds to the complexity. I need to gather from all VM's info on all adapters portgroup and I need the VLAN ID, the gateway address, and the subnet mask. The reason for this is we want to gather portgroup info about both VLAN and network (subnet and gateway).

Get fiber channel path io stats

$
0
0

We are migrating fiber switches and I'm trying to find a way to verify io is going over the paths we are moving. Using this

 

Get-VMHost $host | Get-ScsiLun | Get-ScsiLunPath

 

I only see active or standby, but comparing this against the gui there isn't an Active(io) state, or a way to tell which one has active io.   I made this based  and it works, but I'm hoping to improve it to tie the paths back to actual datastores if possible, but I can't see a way yet. Is it possible and is this the best way to test this?

 

 

$esxcli= Get-EsxCli -VMHost $esx -V2

$paths=$esxcli.storage.core.path.stats.get.Invoke()

foreach($path in $paths)

{

    $measure1 = $esxcli.storage.core.path.stats.get.Invoke(@{path=$path.RuntimeName})

    sleep 5

    $measure2 = $esxcli.storage.core.path.stats.get.Invoke(@{path=$path.RuntimeName})

 

 

    $pathSuccessCommands=$measure2.SuccessfulCommands - $measure1.SuccessfulCommands

 

 

    Write-Host $path.RuntimeName +" " + $pathSuccessCommands

}

Get Template name and folder name

$
0
0

Hi,

 

Please help, how to get the Template Name and its folder name where is located.

 

I tried below command but it is not showing folder name

 

get-Folder | Get-Template Template-Windows2008R264bit


Get SQL Server and Database information before migrating MSSQL 2008 to MSSQL 2016

$
0
0

Trying to build powercli tool, to collect Database Server information before making migration plan.

I need a MSSQL Server and Database overview, By VLANs.

 

I made an attempt, but it's very slow and bulky. Can it be made quicker/Less bulky? Can't figure out how to speed things up with get-view/parallel/async please help!

 

#Get PoweredOn Windows VMs in selected VLAN --> Result 47 VMs in 38 sec

$SelectedVLAN = "2033_dmz1"

$VMGuestInfo = Get-Cluster *-windows | Get-VM | where {$_.PowerState -match "PoweredOn"} | where { ($_ | Get-VirtualPortGroup | where {$_.name -match $SelectedVLAN})}

$VMGuest = $VMGuestInfo.name

$VMGuest

 

 

#Get MSSQL servers from above list --> Result 7 VMs out of 47 with SQL in 5 min (can this be run in parallel/async)

$svcName = "mssqlserver"

$scriptoutput = @()

$VMSWithMSSQL = @()

$guestScript = "(get-service $svcName | ConvertTo-CSV -NoTypeInformation)"

foreach ($VM in $VMGuest)

    {

    #$scriptoutput += $VM

    $scriptoutput = (Invoke-VMScript -vm $VM -scriptText $guestScript  -GuestUser 'XXXXXXX' -GuestPassword 'XXXXXXX' -WarningAction SilentlyContinue | ConvertFrom-CSV).name

    $VMSWithMSSQL += if($scriptoutput -eq "$svcName"){$VM}

    }

$VMSWithMSSQL

 

 

#Get SQL information --> Result 3 Database servers returning databases 4 with

$result = @()

$Report = @()

$result = $VMSWithMSSQL | ForEach-Object `

{

    $Server = $_

    $Item = (Invoke-VMScript -VM $Server -ScriptText {Invoke-Sqlcmd -ServerInstance $Server -Database master -query "(SELECT name FROM [master].[sys].[databases] WHERE name NOT IN ('master', 'model', 'tempdb', 'msdb', 'Resource'))"} -GuestUser 'XXXX' -GuestPassword 'XXXXXXX' –WarningAction SilentlyContinue).ScriptOutput

    $Item1 = $item.Split('',[System.StringSplitOptions]::RemoveEmptyEntries)

    $Item2 = $Item1

    $Item3 = $Item2[2..$Item2.count]

 

 

    New-Object PSObject -Property @{

        Server = $Server

        Databases = $Item3

    }

 

 

}

$result

 

Resulting report on single VLAN: 2033_dmz1

Server    : DBServer01

Databases : {DB1, DB2, DB3, DB4}

 

Server    : DBServer02

Databases : {'Invoke-Sqlcmd', is, not, recognized...}

 

It looks like User/Password isn't correct for Server showing "Databases : {'Invoke-Sqlcmd', is, not, recognized...}"

 

What would be the best way to make credentials check/Pick another from list, before proceeding with the SQL query?

How can I get the following information into my report: Database server version, Database collation, Database collation and Containment type?

Create 2 log files for a powercli script

$
0
0

Hi LucD,

I was wondering if there is any why to generate 2 logs out of a script.

The idea is to generate a single log if everything is OK, and to generate a second one only in case of ERROR.

Is that feasible?

thank you

 

 

V.

powercli script help

$
0
0

I need to pull data for each of my esx hosts with the following information and output it to a .csv file. Below is what I have so far. Any help would be greatly appreciated.

For Each host

CPU Socket

CPU Cores per socket

Logical processors

Hyperthreading status

memory

 

 

 

 

foreach ($esxi in $vmhost) {

    $HostCPU = $esxi.ExtensionData.Summary.Hardware.NumCpuPkgs

    $HostCPUcore = $esxi.ExtensionData.Summary.Hardware.NumCpuCores/$HostCPU

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $esxi.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $HostCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $HostCPUcore

    $result += $obj

}

$result

Connect-VIServer fails to connect with passed credentials inside scripts but connects when manually typed

$
0
0

I have 4 vCenters.  The first 3 are all Windows vCenter installations.  I am able to connect to them via scripts with this method.

Connect-VIServer IP/DNS_Name -User administrator@vsphere.local -Password P@ssw0rd -Force

 

The 4th vCenter instance is a VCSA deployment and it will not accept this method in a script.  I've also tried the credential store method.

Two of the Windows vCenter instances are behind firewalls as is the VCSA instance I'm having issues with.  I've worked with our Cisco guru to insure that communication is not the issue.

I can consistently pass the above command manually via the cli and it connects to the VCSA every time, but when ran via a script, it consistently fails to connect to the VCSA.

 

VCSA Version

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

6.0.0 Update 3b build 5318203

 

 

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

   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891

   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891

   VMware Vds PowerCLI Component 6.5 build 4624695

   VMware Cloud PowerCLI Component 6.5 build 4624821

   VMware HA PowerCLI Component 6.0 build 4525225

   VMware HorizonView PowerCLI Component 7.0.2 build 4596620

   VMware Licensing PowerCLI Component 6.5 build 4624822

   VMware PCloud PowerCLI Component 6.5 build 4624825

   VMware Storage PowerCLI Component 6.5 build 4624820

   VMware vROps PowerCLI Component 6.5 build 4624824

   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

fnic max queue depth

$
0
0

Simple question I am struggling to pull max fnic queue depth via powercli

 

I have so far attempted using

esxcli.system.module.get("fnic"), fnic_max_qdepth

Viewing all 14549 articles
Browse latest View live


Latest Images

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