Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all 16717 articles
Browse latest View live

Can't access vSphere objects via .NET

$
0
0

Greetings experts,

 

 

I am writing a .NET 4.5 application to access and manage vSphere objects. As a first step, I'm creating a simple prototype to make a list of all the VMs that are powered on.

 

I downloaded vSphere PowerCLI, set a reference to VMWare.Vim and wrote this code:

 


Imports VMware.Vim

...

        Dim client As New VimClientImpl

        client.Connect(serviceURL)

        client.Login(userName, password)

        Dim filter As NameValueCollection = New NameValueCollection

        filter.Add("Runtime.PowerState", "PoweredOn")

        Dim VMsList As IList = client.FindEntityViews(GetType(VirtualMachine), Nothing, filter, Nothing)

        Dim losVMs As New List(Of String)

        For Each VM As VirtualMachine In VMsList

            losVMs.Add(VM.Name)

        Next


 

I'm getting this exception on the client.Connect line:

 

An exception of type 'System.IO.FileNotFoundException' occurred in VMware.Vim.dll but was not handled in user code

Additional information: Could not load file or assembly 'VimService55, Version=5.5.0.0, Culture=neutral, PublicKeyToken=10980b081e887e9f' or one of its dependencies. The system cannot find the file specified


 

It seems to be missing VimService55.dll but for the life of me I cannot find this DLL anywhere online or in the VMWare SDK for .NET Developers download package (VMware-vSphere-SDK-5.5.0-1284541). Can anyone please help?

 

TIA,

Rob


Issues with Command Execution never completing

$
0
0

Hello!

 

Since moving to vCenter 6.5 U1 from vCenter 5.5 and updating PowerCLI from 5.1 to 6.5.3 (and 6.5.4) I'm noticing some commands either taking forever to execute or never completing an execution.

 

We are a smaller enviornment vCSA Appliance is set to Medium build, we have 6 hosts w/ only 200 VM's.

 

I've only noticed this execution issue with Tag commands either trying to assign or even get tags from any type of object (VM or Datastore)

 

Has anyone experienced this or know how I can go about getting the execution to run better?

 

To keep it simple I would load the datastore into a variable and apply that variable to the get-tagassignment cmdlet.

 

Any help would be great as I have a project to manage Tag assignments but do not wish for it to take forever Thanks!

 

 

UPDATE: So I used a MSI version of PowerCLI 6.5.1 on a different server, and the command completes but I get this for any TAG cmdlet...

 

Same error for get-tag or new-tagassignment gets this error.... Anyone know why?

 

Get-SpbmStoragepolicy and vCenter 6.5

$
0
0

We have migrated a couple of our vCenters to VCSA 6.5.

I can't seem to retrieve the storage policies with Get-SpbmStoragePolicy from these vCenters. The cmdlet takes *forever*. After 15 minutes with no output I have just closed the window.. The same command against a vCenter 6.0 U2 works like it should.

 

Here's my PowerCLI version:

 

PS C:\> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
   VMware Cis Core PowerCLI Component 6.5 build 5374323
   VMware VimAutomation Core PowerCLI Component 6.5 build 5374329
   VMware Storage PowerCLI Component 6.5 build 5374001

 

 

Has anyone seen the same?

Query Multiple vCenters for (vCenter name, Datacenter name, Cluster Name, No. of Cluster Hosts, No. of VMs)

POWERCLI and Storage Polices ( SPBM ) Issues .

$
0
0

Afternoon Communities .

 

I am having problems with querying TAGS and Storage Polices and it appears I am not the only one on communities .

VCSA6.02

PowerCLI 6.5.1 and 6.03 and .6.31.

 

 

When I run the following from PowerCli 6.5.1 :

 

Get-SpbmStoragePolicy -Namespace "Bronze Datastore Policy"

Or Just Get-SpbmStoragePolicy

 

I get Object reference not set to an instance of an object

 

I tried community solutions like setting date format to US English and accepting invalid certs .

https://www.rudimartinsen.com/2017/07/14/issues-with-get-spbm-powercli-cmdlets-and-vcenter-6-5/

No luck . Then I found

VMware PowerCLI Forum - VMware {code}

I did  Get-Tag | Where {$_.Category -eq $null}

It returned quite a few uncategorized SRM-CG and SRM-PG ones .

I am however pretty sure I cannot delete or edit those , from names , they were clearly created by system : EG

 

 

Name                           Category                       Description                                              

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

SRM-CG-341213cf07293d273f81...                                Site Recovery Manager Consistency Group Tag for Replica...

SRM-PG-939d00673c75ea9c7a47...                                Site Recovery Manager Protection Group Tag for Protecte...

 

So I tried two other Windows Management server with PowerCLI 6.03 and 6.3.1 as some communities suggest its a but in PowerCLI 6.5.1

Now I cannot even do get-tag :

Index was outside the bounds of the array

 

Where to now ?

Any help would be greatly appreciated .

Ultimate goal is to get Storage Policies set to ensure Storage Tier and SRM protection are automatically dealt with during VM provisioning

PowerCLI License agreement

$
0
0

Hello,

 

Where can I find the PowerCLI License agreement? I need a link for reasons.

 

Thank you,

Tsygaa

Problem with Get-Tag and Get-TagAssignment

$
0
0

All of a sudden I get errors in my existing scripts which use Get-Tag or Get-TagAssignment.

 

This is the error:

get-tag : 19/10/2017 15:15:20 Get-Tag vSphere single sign-on failed for connection '/VIServer=domain\admin@vcenter.domain.local:443/'. Future operations which require single sign-on on this connection will fail. The underlying cause was: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

At line:1 char:1

+ get-tag -Name *SQL*

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

    + CategoryInfo          : NotSpecified: (:) [Get-Tag], CisException

    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Impl.V1.Service.Tagging.Cis.TaggingServiceCisImpl.GetTag.Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTag

Whenever I search for the error, I only see resolutions for WCF applications/services...

How to trace a VM disk to a guest disk.

$
0
0

How to trace a VM disk to a guest disk

 

No voodoo involved.  If you’re a Linux person then the mechanics of this process should work for you also.  For Windows people I'll include some PowerShell code that should work in Server 2008 and later (requires PowerCLI, and uses WMI).

 

How to trace a disk:

  • IF THE DISK IS NOT a physical mode RDM then simply match the ddb.uuid (virtual disk uuid) of the vmdk to the disk serial number seen in the guest OS.  To get the virtual disk uuid in PowerShell you can call the queryvirtualdiskuuid method of the VirtualDiskManager managed object (example in code).  If you’re not an administrator in VMware then you’ll need System.View privilege, and on every datastore with a disk you want to inspect you’ll need the Datastore.FileManagement privilege.

 

  • IF THE DISK IS a physical mode RDM then it’s a little trickier but not bad.  In this case the disk serial reported in the guest should display the LUN serial number from the array - NOT the virtual disk uuid of the RDM vmdk.  For these you need to try to match the disk serial of the guest with the last 24 characters of the ScsiCanonicalName of the VM hard disk.  This may or may not be a 1-step process.  The environment where I do things is hosted on NetApp storage, and the LUN serial number from NetApp arrays is in ASCII, so in order to match to the ScsiCanonicalName the LUN serial number first needs to be converted to HEX.  Not sure how other storage vendors are formatting their LUN serial numbers so you may need to tweak.  I’ve coded the script below to hopefully work if you’re on some other array vendor and they either A) use a 12-character ASCII LUN serial number, or B) present a 24-chracter HEX LUN serial number.

 

Works great in my environment but certainly not claiming it will work everywhere.  What I know for sure:

  1. Works on Windows VMs with between 1 and 4 SCSI adapters.  (Based on the methodology # SCSI adapters should not matter, nor should their model.)
  2. Works with physical mode RDM disks presented from NetApp storage.  (Never tried with virtual mode but don't they should work, possibly minor adjustments required.)
  3. 2003 servers don’t work because the Win32_DiskDrive class of WMI didn't provide a SerialNumber property in that version (probably solvable if you must).
  4. If anything exists in the guest that masks the disk serial number then this will not work.
  5. This won't work somewhere and probably lots of places.  Interested to hear your stories either way.

 

This code is just hacked together.  No error handling - if it bombs it bombs.  Just connect to your VI server (script does NOT do this) and edit $vmName to match the server you want to check.

 

Enjoy

 

 

$vmName = "cheezburger"
## modification below here not necessary to run ##


#get windows disks via wmi
$cred = if ($cred){$cred}else{Get-Credential}
$win32DiskDrive  = Get-WmiObject -Class Win32_DiskDrive -ComputerName $vmName -Credential $cred

#get vm hard disks and vm datacenter and virtual disk manager via PowerCLI
#does not connect to a vi server for you!  you should already be connected to the appropraite vi server.
$vmHardDisks = Get-VM -Name $vmName | Get-HardDisk
$vmDatacenterView = Get-VM -Name $vmName | Get-Datacenter | Get-View
$virtualDiskManager = Get-View -Id VirtualDiskManager-virtualDiskManager

#iterates through each windows disk and assign an alternate disk serial number value if not a vmware disk model
#required to handle physical mode RDMs, otherwise this should not be needed
foreach ($disk in $win32DiskDrive)
{
  #add a AltSerialNumber NoteProperty and grab the disk serial number  $disk | Add-Member -MemberType NoteProperty -Name AltSerialNumber -Value $null  $diskSerialNumber = $disk.SerialNumber   #if disk is not a VMware disk set the AltSerialNumber property  if ($disk.Model -notmatch 'VMware Virtual disk SCSI Disk Device')  {    #if disk serial number is 12 characters convert it to hex    if ($diskSerialNumber -match '^\S{12}$')    {      $diskSerialNumber = ($diskSerialNumber | foreach {[byte[]]$bytes = $_.ToCharArray(); $bytes | foreach {$_.ToString('x2')} }  ) -join ''    }    $disk.AltSerialNumber = $diskSerialNumber  }
}

#iterate through each vm hard disk and try to correlate it to a windows disk
#and generate some results!
$results = @()
foreach ($vmHardDisk in $vmHardDisks)
{
  #get uuid of vm hard disk / and remove spaces and dashes  $vmHardDiskUuid = $virtualDiskManager.queryvirtualdiskuuid($vmHardDisk.Filename, $vmDatacenterView.MoRef) | foreach {$_.replace(' ','').replace('-','')}   #match vm hard disk uuid to windows disk serial number  $windowsDisk = $win32DiskDrive | where {$_.SerialNumber -eq $vmHardDiskUuid}   #if windowsDisk not found then try to match the vm hard disk ScsiCanonicalName to the AltSerialNumber set previously  if (-not $windowsDisk)  {    $windowsDisk = $win32DiskDrive | where {$_.AltSerialNumber -eq $vmHardDisk.ScsiCanonicalName.substring(12,24)}  }   #generate a result  $result = "" | select vmName,vmHardDiskDatastore,vmHardDiskVmdk,vmHardDiskName,windowsDiskIndex,windowsDiskSerialNumber,vmHardDiskUuid,windowsDiskAltSerialNumber,vmHardDiskScsiCanonicalName  $result.vmName = $vmName.toupper()  $result.vmHardDiskDatastore = $vmHardDisk.filename.split(']')[0].split('[')[1]  $result.vmHardDiskVmdk = $vmHardDisk.filename.split(']')[1].trim()  $result.vmHardDiskName = $vmHardDisk.Name  $result.windowsDiskIndex = if ($windowsDisk){$windowsDisk.Index}else{"FAILED TO MATCH"}  $result.windowsDiskSerialNumber = if ($windowsDisk){$windowsDisk.SerialNumber}else{"FAILED TO MATCH"}  $result.vmHardDiskUuid = $vmHardDiskUuid  $result.windowsDiskAltSerialNumber = if ($windowsDisk){$windowsDisk.AltSerialNumber}else{"FAILED TO MATCH"}  $result.vmHardDiskScsiCanonicalName = $vmHardDisk.ScsiCanonicalName  $results += $result
}

#sort and then output the results
$results = $results | sort {[int]$_.vmHardDiskName.split(' ')[2]}
$results | ft -AutoSize

chnaging network name of network adapter_powercli

$
0
0

Hello Luc,

 

I am trying to change networkname of  the network adapter (network adapter of vcenter)using powercli.

this adapter is currently configured to DPG on cisco1k and i want to change to standard port group in order to fix the requirement of vcenter upgrade as DPG is configured as static port binding.

 

 

get-vm "vmname"|Get-NetworkAdapter|Set-NetworkAdapter -NetworkName "Management Network"

 

i got following error :

 

 

could you suggest anything related to this error.

getting version and build of esxi and comapring to ref host_powercli

$
0
0

Hello Luc, 

 

this is to get build and version and then compare with reference host.

 

can you please check the code inside foreach loop .i want to comapre build and version to reference host and print output accordingly .for some reasons output is not what expected.

 

 

get-vmhost -location $cluster|select name,version,build

 

$refhost=read-host "provide the ref host"

foreach($esxi in (get-vmhost -location $cluster))

{

 

 

if($esxi.verison -eq "$ref.version" -and $esxi.build -eq "$esxi.build")

{

write-host "$($esxi) matches reference build " -ForegroundColor DarkGreen

}

else

{

write-host "$($esxi) needs to be remediated " -ForegroundColor DarkRed

}}

Get access to work-in-progress objects

$
0
0

Hi,

I'm wondering if is possible to get my hand on any object from the "work in progress" tab. I'd like to schedule/execute a pre-set task.

Cheers,

Manuel

VMSA-2017-0012 / CVE-2017-4919 Export VIPermission Items Script (free 2 optimization)

$
0
0

Hi,

 

maybe someone has suggestions to optimize my code for summarizing information relating a special VIPrivilege regarding VMSA-2017-0012 / CVE-2017-4919.

 

#

#Title: VMSA-2017-0012-export.ps1

#

#Description: This scripts exports VIPermission items related to its role and entity. It #shows all VIPermissions including the "VirtualMachine.Interact.GuestControl“-VIPrivilege #which needs to be managed in accordance to the VMSA-2017-0012 / CVE-2012-4919 issue.

#

#Date: 07/27/2017

#

#Creator: Mathias Raab

#

#Instructions: This script needs to be run AFTER establishing a connection to the vCenter #server. The file path for the export document needs to be specified while running the #script.

#

#Caution: This script has been tested. But I give no guarantee it is working for your #environment. Have a test first and if needed edit it for your own best.

#

 

#Removing variables first

Remove-Variable a,ergebnis

 

 

$ergebnis = @()

foreach ($role in (Get-VIRole))

{

    foreach ($priv in ($role | Get-VIPrivilege | where {$_.ExtensionData.PrivId -eq "VirtualMachine.Interact.GuestControl"}))

    {

        foreach ($viuser in (Get-VIPermission | where {$_.Role -eq $role.Name}))

        {

            $a = New-Object -TypeName PSObject

            $a | Add-Member -MemberType NoteProperty -Name Role -Value $role.Name.tostring()

            $a | Add-Member -MemberType NoteProperty -Name Privilege -Value $priv.Name.tostring()

            $a | Add-Member -MemberType NoteProperty -Name Principal -Value $viuser.Principal.tostring()

            $a | Add-Member -MemberType NoteProperty -Name Entity -Value $viuser.Entity

            $ergebnis += $a

        }

    }

}

$ergebnis | Export-CSV -Path (Read-Host -Prompt „Enter full file path for the export:“) -NoTypeInformation -Delimiter ";"

Script for ESXi Host AD Join

$
0
0

Hi All,

I have frequently few esxi hosts goes out of domain or my AD group permissions will go away in my infrastructure..sometime its count will be more around 50+.

 

To login each host add them in domain and add my AD group is lengthy process.

 

Is there a script which can do it in single shot, for below requirement.

 

Script should

 

1. Connect all my vCenters

2. Pick the host from Get-Content ( which will have my hosts which are out of domain)

3. Should ask the default ESXi root password

4. Should take host in Maintenance Mode

5. Then it should join the esxi host in domain

6. Then it should add my AD group

7. Finally Exit from maintenance mode

8. Export the output report in CSV which all host it could able to join domain and add AD group and exited it from Maintenance Mode.

 

 

 

Thanks a Ton in Advance.

Invoke-VMScript and many Bash commands

$
0
0

Hi!

I have multiple bash commands.

In real time i type command, then enter, then enother command and enter again. etc

How i can use all command in 1 $script?

 

This dos'nt work:

$script = "

/sbin/pvresize

/sbin/lvresize

"

Invoke-VMScript -VM MyVM -ScriptType bash -ScriptText $script -GuestUser root -GuestPassword P@ssw0rd

 

Thanks!

Cannot Create Account with esxcli

$
0
0

Having a strange issue. I need to create a RO account on every ESXi servers deployed via Powercli however using EsxCLI won't accept my password. But when using New-VMhostAccount connected directly to the host it works fine. I'm wanting to set this account during the build of the host which is automated via powercli so doing a connect-visever direct to the host in the middle my build script breaks my connection to the vcenter i'm building in, any ideas?

 

    $Args = $esxcli.system.account.set.CreateArgs()

    $Args.id = 'a_guard'

    $Args.password = '@`[tNI\xUh7#&by\'

    $Args.passwordconfirmation = '@`[tNI\xUh7#&by\'

    $esxcli.system.account.set.invoke($Args)

 

Message: A specified parameter was not correct: argument[1];

InnerText: argument[1]

At line:5 char:5

+     $result = $esxcli.system.account.set.invoke($Args)

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

    + CategoryInfo          : OperationStopped: (:) [], InvalidArgument

    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument


Cannot Enable vSphereReplicationNFC

$
0
0

Hi All,

 

I was able to create a vmk and enable vSphereReplication but I'm unable to enable vSphereReplicationNFC

 

New-VMHostNetworkAdapter -VMHost $esxiserver -PortGroup $NfcPG.Name -VirtualSwitch $dvSwitch -IP $IpAddress -SubnetMask $SubnetMask

        $vnicMgr = Get-View -Id $esxiserver.ExtensionData.ConfigManager.VirtualNicManager

        $vnicMgr.SelectVnicForNicType('vSphereReplicationNFC',$vmk6.Name)

 

Exception calling "SelectVnicForNicType" with "2" argument(s): "A specified parameter was not correct: "

At line:3 char:9

+         $vnicMgr.SelectVnicForNicType('vSphereReplicationNFC',$vmk6.N ...

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

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

    + FullyQualifiedErrorId : VimException

Get-SecurityPolicy and distributed switch

$
0
0

Somehow Get-SecurityPolicy doesn't seem to like my distributed switches:

 

(Get-VirtualSwitch -standard) | Get-SecurityPolicy

 

works.

 

(Get-VirtualSwitch -distributed) | Get-SecurityPolicy

 

doesn't.

 

Is this intended ?

 

There are other ways to do what I want like

     Get-VDSecurityPolicy -VDSwitch

     (Get-VirtualSwitch -name dvswitch).ExtensionData.Config.DefaultPortConfig.SecurityPolicy

 

but shouldn't Get-SecurityPolicy also work ?

 

Using PowerCLI 6.5.4

 

Name                                Version

----                                -------

VMware.DeployAutomation             6.5.1.6997673

VMware.ImageBuilder                 6.5.1.6997673

VMware.PowerCLI                     6.5.4.7155375

VMware.VimAutomation.Cis.Core       6.5.4.6983166

VMware.VimAutomation.Cloud          6.5.1.5375799

VMware.VimAutomation.Common         6.5.4.6979861

VMware.VimAutomation.Core           6.5.2.6234650

VMware.VimAutomation.HA             6.5.4.7147627

VMware.VimAutomation.HorizonView    7.1.0.5307191

VMware.VimAutomation.License        6.5.1.5375648

VMware.VimAutomation.Nsxt           2.0.0.6870461

VMware.VimAutomation.PCloud         6.5.1.5376282

VMware.VimAutomation.Sdk            1.0.0.5334677

VMware.VimAutomation.Srm            6.5.1.5374694

VMware.VimAutomation.Storage        6.5.4.7154886

VMware.VimAutomation.StorageUtility 1.1

VMware.VimAutomation.Vds            6.5.1.5374428

VMware.VimAutomation.Vmc            6.5.4.7086404

VMware.VimAutomation.vROps          6.5.1.5375723

VMware.VumAutomation                6.5.1.5301639

Get logon history

$
0
0

Hello,

I need a script to get a csv with logon history in the last 6 months,

 

Username

Login date

Logout date

Ip source (from where user login)

 

 

Thanks

Report CIVM VMCpuCoreMHz Value

$
0
0

Hallo,

 

I have changed the VMCpuCoreMHz Value for all PayAsYouGo OrgVD´s. Now I need to check where the new Value is not yet applied (vApp PowerOff and On).

 

Any hints where to find that?

 

The other option is to check that in vSphere...

Protect Custom Attributes from deletion but allow modification or deletion of value ?

$
0
0

Is it possible configure a role that has no right to delete an Custom Attribute, but are able to delete the value of an Custom Attribute ?

 

I would like to limit deletion rights becase a user by accident deleted an important Custom Attributes :-(

Viewing all 16717 articles
Browse latest View live


Latest Images

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