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

Limitations of Invoke-VMScript and Certain Powershell Cmdlets - Any Ideas on a Workaround?

$
0
0

I am hoping someone else has already developed a workaround for this particular issue.  This is the last hurdle in an otherwise useful script to assist in our CoB (or DR) plan.  Replicated VMs are spun up at the DR site in a specific folder in vCenter and once online I'd intended to use this script to modify NIC settings and reconnect them to the VM Network, leaving staff available to handle the SQL box that everyone depends on and other manual tasks.  The same goes for failback, and of course proper error handling is a must as well as checks to ensure that VMs native to the DR site do not have their settings modified.  Several days ago I'd found a script online that tackled a portion of what I intended and as such it was a great starting point.  Now I have a script that meets all of my needs, with exception of replacement of the default gateway.  Actually without this piece, the rest is basically a waste of time

 

I've tried both of these methods and while I can utilize remove-ipaddress to remove only the current IP address and use set-netipaddress to add a new IP and gateway, I still end up with the orphan gateway.  viewing the output of the remove-netipaddress and remove-netroute and you see why they fail: Powershell is in non-interactive mode and as such prompting is not supported, nor apparently can you override prompts.

 

$scripttmp = 'remove-netipaddress -InterfaceAlias "' + $intAlias + '" -IPAddress ' + $currentIP + ' -PrefixLength 24 -DefaultGateway ' + $curGateway + ' -Confirm:$false -ErrorAction SilentlyContinue'

$remnetout = invoke-vmscript -ScriptText $scripttmp -ScriptType PowerShell -VM $vm -GuestUser $GuestUserName -GuestPassword $GuestPassword

 

OR

 

$scripttmp='remove-netroute -interfaceindex ' + $intIndex + ' -NextHop ' + $curGateway + ' -DestinationPrefix ' + $DestPrefix'

$rnetout=invoke=vmscript -ScriptText $scripttmp -ScriptType Powershell -VM $vm -GuestUser $GuestUserName -GuestPassword $GuestPassword

 

Any assistance is of course much appreciated.


PowerCLI License Manager-UpdateAssignedLicense

$
0
0

I tried running the following commands to try and add a VSAN license to a cluster but it keeps failing at the UpdateAssignedLicense

$LicenseManager= Get-View $server.ExtensionData.Content.LicenseManager

$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

$cluster = Get-Cluster -Server $server -Name $clusterName

 

foreach($license in $LicenseManager.Licenses){

>>     if($license.Name -contains "VMware vSAN Standard for Retail and Branch Offices"){

>>         if($license.Total -gt $license.Used){

>>             $vsanLicenseKey = $license.LicenseKey;

>>             break;

>>         }

>>     }

>> }

 

$LicenseAssignmentManager.UpdateAssignedLicense($cluster.id,$vsanLicenseKey,"VMware vSAN Standard for Retail and Branch Offices")

 

I keep getting the following errors:

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

At line:1 char:1

+ $LicenseAssignmentManager.UpdateAssignedLicense($datacenterMoRef.valu ...

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

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

    + FullyQualifiedErrorId : VimException

 

I tried the following: $cluster.id, $cluster.ExtensionData.MoRef, and even $datacenterMoRef = (Get-Cluster -Server $server -Name $clusterName | get-view).MoRef.value

They all throw the same error. What is the entityId that I should be using with respect to cluster?

 

PowerCLI 6.5 Release 1 build 4624819

vCenter 6.5

set MulticastFilteringMode with PowerCLI

$
0
0

Hi,

 

I tried this, get no error, but it's also not working:

 

(Get-VDSwitch testvDS | get-view).config.MulticastFilteringMode
legacyFiltering

 

(Get-VDSwitch testvDS | get-view).config.MulticastFilteringMode="snopping"

 

(Get-VDSwitch testvDS | get-view).config.MulticastFilteringMode
legacyFiltering

 

Ciao

 

Gregor

PS C:\Users\matrix> (Get-VDSwitch DEZULORACLU03 | get-view).config.MulticastFilteringMode

 

legacyFiltering

 

PS C:\Users\matrix> (Get-VDSwitch DEZULORACLU03 | get-view).config.MulticastFilteringMode="snopping"

 

PS C:\Users\matrix> (Get-VDSwitch DEZULORACLU03 | get-view).config.MulticastFilteringMode

 

legacyFiltering

Need to pull VM data but where vSAN Storage Policy doesnt doubling disk. I also need to pull the TAG into the report

$
0
0

Hello,

 

I am looking for a way to pull simple VM stats (vCPU, Memory Allocated, Disk Allocated), I have the following which works partly:

 

Get-VM |

Select Name,@{N='VMHost';E={$_.VMHost.Name}},

    NumCpu,MemoryGB,UsedSpaceGB |

Export-Csv report.csv -NoTypeInformation -UseCulture

 

This pulls the UsedSpaceGB and for this report I am only concerned with allocatedGB for the disks as my storage policy is N+1, so it is doubling the disks sizes and I think also adding the memory pagefile back to the ammount?  So I would really just like to see the sum of the disks assigned to the VMs instead.  Is this doable?

 

Finally I need to also pull the TAG from the category "CN" on each machine into this report.  There should only be 1 TAG assigned in this category on each VM (if at all, it could also not have one which is fine to be returned NULL).  How would I do this in the same report?

 

ED7

PowerCLI script to list VMFS datastore with NAA ID and the latency ?

$
0
0

Hi All,

 

Can anyone here please share some script or assist me in modifying the PowerCLI to display the VMFS datastore name, capacity and NAA.ID and the latency in the past 24 hrs ?

 

So far I can only use the below script by WHowe :

 

$esxName = "PRODESXi10"

 

Connect-VIServer -Server "PRODVCENTER01-VM"

New-VIProperty -Name lunDatastoreName -ObjectType ScsiLun -Value {

  param($lun)

 

  $ds = $lun.VMHost.ExtensionData.Datastore | %{Get-View $_} | `

  where {$_.Summary.Type -eq "VMFS" -and

  ($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName})}

  if($ds){

  $ds.Name

  }

} -Force | Out-Null

 

Get-VMHost -Name $esxName | Get-ScsiLun | Select CanonicalName, CapacityMB, lunDatastoreName

 

Thanks in advance,

get-esxtop_powercli

$
0
0

hi Luc,

 

i have been reading yur notes on get-esxtop and trying to understand as there is lot of stuff there.

i also downloaded yur module from github but just thought of asking has anything being changed with new release of powercli .

also  are we going to run this with stats level 1 only  ??changing to stats level 3 will need changing the size of DB vmdk .

also what number system is 1E6.

server Certificate with HTTP.SYS error while connect-viserver on powercli

$
0
0

I'm getting below error while connecting to the server from powercli. It was working till yesterday and getting this error while no changes been performed on vCenter server.

Could someone please help to resolve this issue.

 

Connect-VIServer : 2/13/2018 6:18:27 AM    Connect-VIServer        An error occurred while making the HTTP request to https://vCenterServer-FQDN/sdk.

This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch

of the security binding between the client and the server.

At line:1 char:1

+ Connect-VIServer vCenterServer-FQDN

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

    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], ViError

    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

Folder structure import from a csv file not working as expected

$
0
0

Hello,

 

I am using a script to import the blue folder structure from a csv file to a vcsa 6.5 and apparently the folder names that are present in multiple paths in the csv are imported in the correct path and also in other paths that should not contain it.

 

The csv file is in the form:

 

Name          Path

 

Folder1       vm\Folder1

Folder2       vm\Folder2

Folder3       vm\Folder1\Folder3

Folder3       vm\Folder2\Folder3

Folder4       vm\Folder1\Folder4 etc

 

The script is the following:

 

Get-Module -Name VMware* -ListAvailable | Import-Module

If ($globale:DefaultVIServers) {

Disconnect-VIServer -Server $global:DefaultVIServers -Force

}

 

 

$destVI = Read-Host "Please enter name or IP address of the destination Server"

$creds = get-credential

connect-viserver -server $destVI -Credential $creds

function Import-Folders {

param(

[String]$FolderType,

[String]$DC,

[String]$Filename

)

process{

$vmfolder = Import-Csv $filename | `

Sort-Object -Property Path

If ($FolderType -eq "Yellow") {

$type = "host"

} Else {

$type = "vm"

}

foreach($folder in $VMfolder){

$key = @()

$key = ($folder.Path -split "\\")[-2]

if ($key -eq "vm") {

Get-Datacenter $dc | Get-Folder $type | `

New-Folder -Name $folder.Name

} else {

Get-Datacenter $dc | Get-Folder $type | `

Get-Folder $key | `

New-Folder -Name $folder.Name

}

}

}

}

Import-Folders -FolderType "blue" -DC "datacentername" `

-Filename "C:\BlueFolders.csv"

 

and the result i am getting in the new vcenter is:

 

vm\Folder1

vm\Folder2

vm\Folder1\Folder3

vm\Folder1\Folder4

vm\Folder2\Folder3

vm\Folder2\Folder4 etc

 

meaning that all the child folders are duplicated in all the parent folders that contains just one or some of them.

 

Can anyone help me in figuring out what the problem may be?


Script to get Orphaned VM files across vCenter

$
0
0

Hi All,

 

Is there a script around, which can give us Orphaned VM file across vCenter, along with its Datastore names , orphaned VM file size, in Excel or CSV output file.

set-harddisk_resizeguestpartition_powercli

$
0
0

Hi luc,

 

there is one parameter in set-harddisk command as below which is deprecated in powercli version 6.5

has it been reintroduced in powercli 10 as it will avoid login to os and extend partition manully.

 

 

 

also as per above description it can be extended by using below .what should be the correct code using below expression if we need to increase d drive from 100gb to 120GB.

assuming hard disk has alredy been increased.

 

Invoke-Command -ComputerName $vm -ScriptBlock {

$size = Get-PartitionSupportedSize -DriveLetter D

Resize-Partition -DriveLetter D -Size $size.SizeMax

}

Capturing VM Host name

$
0
0

I have the following line

$v.VMGuestHostName = $VM.ExtensionData.Guest.HostName

but I was expecting it to match the data captured by this line

$h.HostName = $VMHost.ExtensionData.name

Is there an alternative field in the VM Extension data I can use instead of Guest.HostName to match ExtensionData.name in the host?

Issue with declaring variable

$
0
0

Hi,

 

I am trying to shrink the windows drives and I have issues with variable

 

If I use the below command, it works

 

Resize-Partition -DriveLetter E -Size ((Get-Partition -DriveLetter E).Size - 10GB)

 

But I want to use a variable in defining the size using variable, how can I do it ?

 

Please help

Move-VM or Move-Inventory won't move VM to another folder - "The request refers to an unexpected or unknown type."

$
0
0

Move-VM with -destination produces generic error

Move-VM with -inventorylocation appears to work but VM stays in the same location

Move-Inventory produces generic error

 

Really frustrating this one and no idea of how to troubleshoot this error further.  Tried many variations of both commands piping and not piping and nothing works.  Anyone seen this before?

 

Get-VM & Get-Folder work fine on those variables.

Folder is top level.

VM is powered off but same results on a powered on VM.

 

movevmfail.JPG

 

Can anyone reproduce this?  PowerCLI version on screeny.  VC version 6.5.0, build 5973321.


Thx
Guy

How can find the pools of over 100 users? all are in different pools and I don't want to manually look them up

$
0
0

How can find the pools of over 100 users? all are in different pools and I don't want to manually look them up

Remove unused DVuplinks for DVswitch

$
0
0

i recently had a few network changes within my lab environment and i have to decrease my amount of uplink ports on my dvswitch from 7 to 4. i removed the physical nics from the dvswitch but now im left with 3 unused dvUplinks. when i try to reduce the amount of uplinks from the edit settings window on the dvswitch i get a "resource 1707 is in use on host x.x.x.x"

 

does anyone know how else i can remove the unused dvuplinks from my dvswitch.

 

6.0 vcsa, dvswitch 5.5 (didnt notice until now, will upgrade to 6.0)


Is there a better faster way to get guest OS counts by datacenter?

$
0
0

This is what I am doing now...figured there has to be a faster way...any ideas?

 

 

$datacenters = get-datacenter | Sort-Object | select name

 

 

foreach($datacenter in $datacenters){

 

 

$datacentername = get-datacenter -name $datacenter.name | sort-object

$allvms = get-datacenter $datacentername | get-vm

 

 

Write-host "Os Full Name Counts: $datacentername"

Write-host ""

 

 

$allvms  | Get-View | Select @{Name="OS";Expression={ $_.Summary.Config.GuestFullName }} | Group OS | Sort Name | Select Name,@{Name="Total VMs";Expression={ $_.Count }}

}

Open-VMConsoleWindow Authorize Exception

$
0
0

Just noticed that Open-VMConsoleWindow no longer works ? Or did something change that I'm not aware of ? I can run VMRC from vSphere Web Client; also from PowerShell using this approach.

 

PS C:\PowerCLI\_> get-vm xxxx | Open-VMConsoleWindow

Open-VMConsoleWindow : A general system error occurred: Authorize Exception

In Zeile:1 Zeichen:23

+ get-vm xxxx | Open-VMConsoleWindow

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

    + CategoryInfo          : NotSpecified: (:) [Open-VMConsoleWindow], VimException

    + FullyQualifiedErrorId : VMware.Vim.VimException,VMware.VimAutomation.ViCore.Cmdlets.Commands.OpenVMConsoleWindow

 

Some info:

Windows 10 1803

 

PS C:\PowerCLI\_> $PSVersionTable.PSVersion

 

Major  Minor  Build  Revision

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

5      1      17134  228

 

PS C:\PowerCLI\_> Get-PowerCLIModules

 

Name                                Version

----                                -------

VMware.DeployAutomation             6.7.0.8250345

VMware.ImageBuilder                 6.7.0.8250345

VMware.PowerCLI                     11.0.0.10380590

VMware.Vim                          6.7.0.10334489

VMware.VimAutomation.Cis.Core       11.0.0.10335701

VMware.VimAutomation.Cloud          11.0.0.10379994

VMware.VimAutomation.Common         11.0.0.10334497

VMware.VimAutomation.Core           11.0.0.10336080

VMware.VimAutomation.HA             6.5.4.7567193

VMware.VimAutomation.HorizonView    7.6.0.10230451

VMware.VimAutomation.License        10.0.0.7893904

VMware.VimAutomation.Nsxt           11.0.0.10364044

VMware.VimAutomation.PCloud         10.0.0.7893924

VMware.VimAutomation.Sdk            11.0.0.10334495

VMware.VimAutomation.Security       11.0.0.10380515

VMware.VimAutomation.Srm            10.0.0.7893900

VMware.VimAutomation.Storage        11.0.0.10380343

VMware.VimAutomation.StorageUtility 1.3.0.0

VMware.VimAutomation.Vds            11.0.0.10336077

VMware.VimAutomation.Vmc            11.0.0.10336076

VMware.VimAutomation.vROps          10.0.0.7893921

VMware.VumAutomation                6.5.1.7862888

Listing all snapshots per vm using get-view

$
0
0

Hi everyone

 

I am in the process of developing a script to cleanup after our backup software.

 

One of the tasks will be to find snapshots of a certain name and remove them. This is pretty straight forward.

 

However, since we have several vCenters linked and since, when a backup job dies, there can be quite a number of of snapshots to work through AND people sometimes don't notice for a few days that something was amiss, I would like to optimise this in a few key aspects:

 

When a vm has nothing but backup snaps to be deleted, I would like to tell it to delete them all at once, which should be way easier than doing one at a time.

 

To do that, I need to check all snapshots per vm and group the vms and or their snapshots into either the "delete all" category or the "delete individually" category.

 

I would like to use views to drill down the data and only work with objects when it is clear what has to be done where. For this I need a way to find all snapshots of a certain vm. I have no trouble finding all vms with snapshots but I have so far only found a way to find the active snapshot and the root snapshot.

 

I can of course traverse the snapshot chains in code but I find this rather inelegant...

 

 

So in short: Is there a quick way in get-view to find all snapshots belonging to a vm? Or is there a much easier way to do what I want in the first place?

 

Regards,

 

Marco

Adding existing hard disk via New-HardDisk gives "Incompatible device backing specified for device '1'"

$
0
0

I've taken an existing vmdk file,from a snapshot, modified its contents as I'm renaming the disk file and changing the parent disk to create a linked clone, but when I call New-HardDisk with -DiskPath set to something like "[SSD] Scripted Clone/Scripted Clone.disk1.vmdk" , where that file exists in that folder in the datastore, and -VM set to a new VM the PowerShell script has just successfully created, the cmdlet fails with the error "Incompatible device backing specified for device '1'". The disk file exists and seems to be fine because if I add it from the web console then it adds just fine and the VM boots ok so presumably I'm either missing some parameters to New-HardDisk or there's potentially a bug.

disk_info_function_powercli

$
0
0

hi Luc,

 

could you suggest about below scenerio.

 

 

following is the function to get disk info of virtual machine.it works fine but finally i thought of converting it to module and saved as module1.psm1

i am not sure how to run this .do i need to import this ??

 

also functions are not persistent but modules are .is this correct?

 

 

function disk_info

{

[cmdletbinding()]

param (

 

 

[parameter(mandatory = $true,

           valuefrompipeline = $true,

           valuefrompipelinebypropertyname = $true)]

 

           [string[]]$vmname

)

 

 

$vm = get-vm $vmname

$disksinfo=$vm.Guest.Disks

$disksinfo

}

Viewing all 14549 articles
Browse latest View live


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