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

Create a PowerCLI script to create a local User account on each Host in vCenter

$
0
0

Hi Guys,

 

I know this has been posted several times on here but I can't find the correct script for my application.

 

I am setting up Solarwinds in my environment and it requires a local account with Read-Only access on each of the ESXi hosts. I am currently running ESXi 6.0U3a on all of my hosts.

 

What I need is for the script to pull all of the hosts out of vCenter and add local account SOLSNMP and place it in the Read-only "Role"

 

Thanks for any help

 

BobK


在使用powercli创建虚拟机制定“-DiskStorageFormat Thin” 提示一下错误,我的esxi和vcenter都是5.5版本

$
0
0

New-VM : 2017/9/20 9:16:15 New-VM

Required property datastore is missing from data object of type VirtualMachineRelocateSpecDiskLocator

while parsing serialized DataObject of type vim.vm.RelocateSpec.DiskLocator

at line 1, column 1082

while parsing property "disk" of static type ArrayOfVirtualMachineRelocateSpecDiskLocator

while parsing serialized DataObject of type vim.vm.RelocateSpec

at line 1, column 1025

while parsing property "location" of static type VirtualMachineRelocateSpec

while parsing serialized DataObject of type vim.vm.CloneSpec

at line 1, column 1014

while parsing property "cloneSpec" of static type VirtualMachineCloneSpec

while parsing serialized DataObject of type vim.storageDrs.StoragePlacementSpec

at line 1, column 324

while parsing call information for method RecommendDatastores

at line 1, column 218

while parsing SOAP body

at line 1, column 207

while parsing SOAP envelope

at line 1, column 38

while parsing HTTP request for method recommendDatastores

on object of type vim.StorageResourceManager

at line 1, column 0

所在位置 行:17 字符: 12

+            New-VM -Name $vm.name -OSCustomizationSpec $custSysprep  - ...

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

    + CategoryInfo          : NotSpecified: (:) [New-VM], InvalidRequest

    + FullyQualifiedErrorId : Client20_VmServiceImpl_ApplySdrsRecommendation_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Creating a Scheduled Task for a VM

$
0
0

Currently I know how to create a task for a VM for a scheduled  recurring nightly task through the Web client, but I can't seem to figure out a way to create a task via PowerCLI.  Hopefully I'm just missing something really obvious.

 

Ultimately what I'd like to do is be able to something like search for a VM using Get-VM -VM $vmname and pipe that to return any scheduled tasks that vm has and if it currently doesn't have one then I'd love to be able to set a new task. In the context of my current use case, just simply scheduling a nightly reboot.

 

Sorry if I'm just missing something obvious, I'm just starting to dive into PowerCLI and loving what I can do so far.

 

Thanks!

GET-DesktopVM command does not work throws no object found in vmware.view.broker

$
0
0

Hello,

 

get-desktopvm cmdlet does not work and throws the error as no object found.

Other cmdlets work except get-desktopvm.

I have checked the other cmdlets they are working except the get-desktopvm, please help me.

IS there any possibility that we can unregister and re-register the vmware.view.broker snappin.

 

 

Get-DesktopVM

Get-DesktopVM : No output object

At line:1 char:1

+ Get-DesktopVM

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

    + CategoryInfo          : ObjectNotFound: (vmware.view.pow...ts.GetDesktopVM:GetDesktopVM) [Get-DesktopVM], Exception

    + FullyQualifiedErrorId : No object,vmware.view.powershell.cmdlets.GetDesktopVM

 

Thanks in advance.

 

Regards,

Naveen. S

Bug in PowerCLI 6.5 R1: Could not load file or assembly log4net

$
0
0

Description

 

I don't know where to report PowerCLI bugs ... btw Get-ErrorReport won't work for this bug.

 

There is a problem with PowerCLI 6.5 R1. When starting the x64 PowerCLI all PowerCLI modules cannot be loaded because this error: "Could not load file or assembly ‘log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304’ or one of its dependencies. The system cannot find the file specified." The x86 PowerCLI starts without any problems.

 

Cause

 

We've analyzed the problem. The problem is caused by a log4net assembly in the GAC (Global Assembly Cache).

 

PowerCLI ships a log4net assembly in the "Modules\VMware.VimAutomation.Sdk" folder. The log4net assembly is explicitly loaded by the PowerShell because it is in the RequiredAssemblies list of the VMware.VimAutomation.Sdk.psd1 module manifest (see VMware.VimAutomation.Sdk.psd1).

 

The already installed log4net assembly in the GAC and the log4net assembly shiped by PowerCli:

  • both have the same Version: 1.2.10.0
  • both have the same Culture: neutral
  • both have the same PublicKeyToken: 692fbea5521e1304
  • but differ in the processorArchitecture
    • log4net in GAC: x86
    • log4net in PowerCLI: MSIL

 

The PowerShell seems to raise an error when:

  • it should load an assembly because it is in the RequiredAssemblies list
  • there is an assembly with the same (strong?) name in the GAC
  • the processorArchitecture of the assembly in the GAC does not match the architecture of the PowerShell (x64 for PowerShell x64/x86 for PowerShell x86) and is not MSIL

 

Regular "Any CPU" .NET applications behave differently. Assemblies in the GAC with a different processorArchitecture are ignored and not loaded.

 

BTW: Removing the assembly from the GAC isn't an option because this will break the software that installes log4net in the GAC: SAP Crystal Reports runtime engine for .NET Framework (32-bit), Version 13.0.8.1216

 

Steps to Reproduce

 

We can repoduce this problem:

  • Create an assembly MyLibrary.dll
  • Build the with AnyCPU and x86
  • Sign both assemblies
  • Install the x86 Assembly in the GAC
  • Create a PowerShell module MyModule
  • Add MyLibrary.dll to the RequiredAssemblies list of the module
  • Open x64 PowerShell
  • Import-Module MyModule fails with this error: "Could not load file or assembly ‘MyLibrary, Version=1.0.0.0, Culture=neutral, ...’ or one of its dependencies. The system cannot find the file specified."

 

see also comment of Waytraveler: https://blogs.vmware.com/PowerCLI/2016/11/new-release-powercli-6-5-r1.html

 

Temporary Workarounds

 

  1. Use PowerCLI x86
  2. Remote log4net from the RequiredAssemblies list of the VMware.VimAutomation.Sdk
    1. You may need to sign the module with you own code signing certificate

Import list of VM's, export required data

$
0
0

Hi All,

 

I'm trying to do something and need some help.  I have a .txt file and or a .csv with a list of VM's..  I'm trying
to import those list of VM's and export the following data from that listing.

 

Number of vCPU's per server

Configured/allocated memory per server

VMDK storage total (allocated) per server

 

Looking for some help.

 

Thanks..

Get HBA firmware and driver version for all ESXi hosts

$
0
0

Hello, as you probably know the only way to find out about HBA firmware and driver versions these days is by running:

 

/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -d     to see which are the HBA devices, then

/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -l -i vmhba1/qlogic     to actually retrieve the needed  info for a hba. In this particular case I get this precious data below:

 

value:

QLogic PCI to Fibre Channel Host Adapter for QMH2562:

        FC Firmware version 8.02.00 (90d5), Driver version 2.1.50.0

 

which I need to retrieve from all my ESXi and save to a file. I enjoy writing simple powercli scripts but I'm puzzled about this one. I know that esxcli commands can be scripted too but what about this? I could script something with plink

 

 

$plink = plink path

$plinkAuth=" -v -pw $Pswd"

$remoteCommand='/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -l -i vmhba1/qlogic'

$command="Echo Yes| "+$plink+" "+$plinkAuth+" "+$User+"@"+$hostName+" "+$remoteCommand

$result=Invoke-Expression-command$command

$result

 

but as the command above throws quite some stuff I don´t know how to grab only the data output I need and save it. Obviously this is to compare with vmware compatibility matrix later. Anyone did this? I already checked Re: Host Hardware info with HBA and nic driver information but the following values are returned blank, and not sure those match the  ones above that I need. I already added  the -V2 switch to the script of that post.

 

 

Fnicvendor   :

fnicdriver   :

enicdriver   :

Enicvendor   :

Powercli to migrate VM's in a cluster with Partial DRS

$
0
0

I use a for loop in Powercli  to:

- step though each VM-Host in a cluster

- migrate the VM"s off it and then put VM-Host into  Maintenance mode.

 

Before going into Maintenance mode, the VM's need to be migrated off the VM-Host.

 

Since the cluster uses "Partial DRS" , I've been going to the cluster's DRS tab (  in the Vsphere GUI )  and choosing "Apply Recommedations" . Then

the powered on VM's  are migrated to the available VM-Hosts. 

 

Is there a powercli way to migrate the VM's  when using "Partial DRS" ?

Thanks,

wbru


Passing local variable to remote script

$
0
0

Hi All,

 

I have created a script to rename the network adapter in windows virtual machine based its mac address. Below is my script.

 

$vmname = "w12-core"

$vmacaddress =  "00:50:56:9C:63:8A"

$script =

{

$wmi = Get-wmiobject -Class win32_Networkadapter | where { $_.Macaddress -eq  $vmacaddress }

$wmi.NetconnectionID = 'Newcard'

$wmi.put()

}

 

Invoke-Vmscript - VM $vmname -ScriptText = $script -Guestuser="Administrator" -GuestPassword = "VMware1!"

 

Am getting some error while passing macaddress via variable $vmacaddress. Script is getting executed If i mentioned the macaddress directly. ($wmi = Get-wmiobject -Class win32_Networkadapter | where { $_.Macaddress -eq "00:50:56:9C:63:8A" }

 

Need a help in passing local variable to remote.

Is there a working link to download the PowerCLI 6.5.2 User Guide?

get-esxtop

$
0
0

What settings / permissions are required to retrieve output from the Get-EsxTop cmdlet?

I don't receive an error, but I don't receive any data, either.

Thanks

PowerCLI 6.5 Error when running Connect-HVServer

$
0
0

Hello,

 

Looking for insight on the this error.  Trying to connect from the connection server (v7.1).  Please post a reply if you have encountered this scenario. 

 

Issue occurs for mutliple IDs from a desktop or directly on the connection server.

 

TIA

 

PowerCLI C:\> Connect-HVServer -Server xxxx.xxxx.xx

Connect-HVServer : ExceptionType : VMware.Hv.EntityNotFound

ErrorMessage : Could not find user or group in AD

Id : VMware.Hv.UserOrGroupId

At line:1 char:1

+ Connect-HVServer -Server xxxx.xxxx.xx

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

    + CategoryInfo          : NotSpecified: (:) [Connect-HVServer], Exception

    + FullyQualifiedErrorId : System.Exception,VMware.VimAutomation.HorizonVie

   w.Commands.Cmdlets.ConnectHVServer

Unable to get new PowerCLI 6.5 R1 to even try and connect to our vCenter

$
0
0

Greetings,

 

I'm trying out the new PowerCLI 6.5 release and have so far had 0 luck getting it to even try and connect to our vCenter 6.0u2 environment.

 

The only information I've been able to gather so far is the following error message:

 

VERBOSE: Attempting to connect using SSPI

VERBOSE: Could not establish secure channel for SSL/TLS with authority 'vcenter.domain.com'.

VERBOSE: Connect using SSPI was unsuccessful

VERBOSE: Could not establish secure channel for SSL/TLS with authority 'vcenter.domain.com'.

 

Even after passing the vCenter Administrator username and pasword in domain/username format, I'm left with the error message:

VERBOSE: Could not establish secure channel for SSL/TLS with authority 'vcenter.domain.com'.

 

The vCenter server has a cert signed by our Root CA that is trusted, and I've also gone so far as to import the vCenter cert manually and trusted it, but have had no further luck.

 

I am aware of the known issue mentioned in the 6.5R1 release notes regarding vCenter not being able to authenticate using Kerberos (VMware PowerCLI Release Notes), however that doesn't appear to be the issue here since I'm using the local administrator account.

 

I've seen 0 information on Google regarding this issue, and IRC has been of 0 help.

 

What's going on here!??!

Get VM's creation date

$
0
0

It's possible to get the exact creation time of a VM?

I'm seeing here in the tasks and events but ain't found. Maybe some PowerCli cmdlet exclusive for reports?

Guest.HostName on same Linux return only short Hostname

$
0
0

Good day.

Need help

 

Guest.HostName  on Win, RH, OEL guest OS return full hostname on SuSe and CentOS return only short hostname.

 

But i need full, how fix it?


Get WWN and WWP

$
0
0

Hello,

I check this discussion

 

I use this one:

 

$cluster = get-cluster

$hosti = get-Cluster $cluster | Get-VMHost

 

 

$report333 = @()

foreach ($esxi in $hosti) {

 

 

    $report333 +=Get-VMHosthba -VMHost $esxi -type FibreChannel |

    Select  @{N="Host";E={$esxi.Name}},

        @{N="HBA Node WWN";E={"{0:x}" -f $_.NodeWorldWideName}},

        @{N="HBA Port WWP";E={"{0:x}" -f $_.PortWorldWideName}}

    

 

 

}

 

 

$report333 | Export-csv  -Path C:\Users\gemela\Desktop\WWNTECO.csv –NoTypeInformation

 

 

And I get this format: "200024827aaf84f2","1000289et53f84f2"

 

Is possible to get format like: 20:00:28:22:4a:af:84:f3 10:10:28:02:4a:af:84:f2

 

Thanks

How to Store Credentials in script for vCenter and vCenter MOB

$
0
0

Hi Guys,

 

I've modified a great script written by William Lam and works perfectly however the script requires me to specify the credentials either in the script or pass as a param in plain text.

 

I usually use $Cred = Get-Credentials at the beginning of my scripts to authenticate against vCenter but this script requires to also authenticate against the MOB and I just can't figure out how to store the credentials for both.

 

vghetto-scripts/enable-disable-vsphere-api-method.ps1 at master · lamw/vghetto-scripts · GitHub

get-vievent

$
0
0

Hi

 

i am pulling events 5 month old but when I run below command it returns nothing

 

get-cluster -name xxxxx | Get-VIevent -Start 04/01/2017 -Finish 08/31/2017 -maxsamples 10000 | Where {$_.FullFormattedMessage -match "VMtools|VMware Tools"} | select @{Name='host';E={$_.Host.name}}, @{N='user';E={$_.UserName}},@{N='Createdtime'; E={$_.CreatedTime}}, @{N='Fullmessage';E={$_.FullFormattedMessage}} |export-csv report.csv

 

I also tried  -match  "Tools" but even then it returns nothings, I belive something wrong script where date is not picked up?

VMware.VimAutomation.Logging.SoapInterceptor not found

$
0
0

Hi,

 

I'm trying to reboot a VM with PowerCli and then wait until the vm is running. I user this command for this:

 

Get-CIVM -VApp $VCloudVappName -Name $VCloudVmName | Restart-CIVMGuest -Confirm:$false -WhatIf | Wait-Tools

 

This works at least the last command. Wait-Tools every time gets an error

 

Connect-VIServer : Die Datei oder Assembly "VMware.VimAutomation.Logging.SoapInterceptor, Version=1.0.0.646, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
In C:\tmp\reboot.ps1:13 Zeichen:1
+ Connect-VIServer -Server $VCloudHost -Credential $mycredsVCloud
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], FileNotFoundException    + FullyQualifiedErrorId : System.IO.FileNotFoundException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

Wait-Tools : Die Datei oder Assembly "VMware.VimAutomation.Logging.SoapInterceptor, Version=1.0.0.646, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
In C:\tmp\reboot.ps1:15 Zeichen:104
+ ... VCloudVmName | Restart-CIVMGuest -Confirm:$false -WhatIf | Wait-Tools
+                                                                ~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Wait-Tools], FileNotFoundException    + FullyQualifiedErrorId : System.IO.FileNotFoundException,VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTools

It's a german error message, but it says something like "File or assembly ... or a dependency not found. The system can not find the specified file.

 

I have PowerCli Version 6.5.1, the latest VIX Tools, and I already restarted my Computer

Can someone help me?

How do I retrieve a list of LACP LAG Uplinks from my Environment?

$
0
0

We have an environment where each vDS uses LACP and has a LAG uplink.  I'd like a way to list the different LAG names via PowerCLI.  This needs to be across multiple vDS switches. 

 

I know I can point ESXCLI to a specific host and get the information from: $esxcli.network.vswitch.dvs.vmware.lacp.config.get(), and I found if I do a Get-VDSwitch | Get-VDPortgroup | where {$_.Name -match "2"} | Get-VDUplinkTeamingPolicy, it's listed under "ActiveUplinkPort".  But I'd like to run a script that lists...

 

ProdLAG

StgLAG

DEVLAG

etc...

 

Can someone help? 

 

LUC?!  I'm sending up the LUC SIGNAL!

 

Luc_Signal.jpg

Viewing all 16717 articles
Browse latest View live


Latest Images

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