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

get-taskplus failed against standalone host?

$
0
0

Dear LucD,

 

thanks for your great get-taskplus, it works well against virtual center,

 

but failed repeatedly against standalone host vSphere 6.5,

PowerCLI C:\> $si = Get-View ServiceInstance

PowerCLI C:\> $tskMgr = Get-View $si.Content.TaskManager

PowerCLI C:\> $filter = New-Object VMware.Vim.TaskFilterSpec

PowerCLI C:\> $tCollector = Get-View ($tskMgr.CreateCollectorForTasks($filter))

Exception calling "CreateCollectorForTasks" with "1" argument(s): "The operation is not supported on the object."

At line:1 char:1

+ $tCollector = Get-View ($tskMgr.CreateCollectorForTasks($filter))

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

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

    + FullyQualifiedErrorId : VimException

PowerCLI C:\>

 

looks like $filter not correct? do you know how to fix it? thanks


Get template by tag

$
0
0

Greetings,

 

Is there any way of grabbing templates by tags? get-template does not include a -tag argument like get-vm does. If I tag a vm, convert it to a template, the webclient shows tagging information but the template object shows tag as empty.

List vcenter InstanceUUIDs

$
0
0

I want to read in a textfile containing a list of vCenter 6.0 servers then output said vCenter server's InstanceUuid's.

 

My code so far is:

 

$vCenterList = Get-Content C:\vcenterList.txt
Foreach ($vCenter in $vCenterList) {
Connect-viserver $vCenter
Write-Host $vcenter.InstanceUuid
}

 

I see the out of vCenter connections, but the "Write-Host $vcenter.InstanceUuid" outputs a blank line for each vCenter.

 

Any ideas what I'm doing wrong, or suggestions for alternative code options?

get dns server settings

$
0
0

trying to get the DNs server settings for guestos (all windows 2008/2012) servers

 

get-content serverx.txt | % { invoke-vmscript -VM $_ -guestuser "domain\user" -guestpassword "xxxxx" -scripttext "ipconfig /all"}

 

this is only working for one or two servers

 

any idea?

 

vmware tools is all installed

 

 

Error I get is

 

The guest operations agent could not be contacted

ILO information by Script

$
0
0

I would like to ask if someone can try this script to check ILO information's I just need to know if is valid, I got these info when I run:

 

Header 1

   

iLOFirmwareHPSmartArraySystemBIOS
Hewlett-Packard BMC Firmware (node 0) 46:10000 2.20HP Smart Array Controller HPSA1 Firmware 6.64HP System BIOS I31 2015-04-01 00:00:00.000
Hewlett-Packard BMC Firmware (node 0) 46:10000 2.40HP Smart Array Controller HPSA1 Firmware 3.56HP System BIOS I36 2015-12-28 00:00:00.000
Hewlett-Packard BMC Firmware (node 0) 46:10000 2.40HP Smart Array Controller HPSA1 Firmware 4.02HP System BIOS I36 2015-12-28 00:00:00.000
Hewlett-Packard BMC Firmware (node 0) 46:10000 2.40HP Smart Array Controller HPSA1 Firmware 3.56HP System BIOS I36 2015-12-28 00:00:00.000
Hewlett-Packard BMC Firmware (node 0) 46:10000 2.40HP Smart Array Controller HPSA1 Firmware 3.56HP System BIOS I36 2015-12-28 00:00:00.000

 

So, I suppose 2.20, 2.40 are ILO version...thanks

 

Get-View -ViewType HostSystem -Property Name, Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo -SearchRoot (Get-View -ViewType ClusterComputeResource -Property Name -Filter @{"Name" = "^$([RegEx]::escape($strHostsClusterName))$"}).MoRef | %{    $arrNumericSensorInfo = @($_.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo)    # HostNumericSensorInfo for BIOS, iLO, array controller    $nsiBIOS = $arrNumericSensorInfo | ? {$_.Name -like "*System BIOS*"}    $nsiArrayCtrlr = $arrNumericSensorInfo | ? {$_.Name -like "HP Smart Array Controller*"}    $nsiILO = $arrNumericSensorInfo | ? {$_.Name -like "Hewlett-Packard BMC Firmware*"}    New-Object PSObject -Property @{        VMHost = $_.Name        "SystemBIOS" = $nsiBIOS.name        "HPSmartArray" = $nsiArrayCtrlr.Name        "iLOFirmware" = $nsiILO.Name        }} | Export-Csv -Path C:\Users\gemela\ILO_info.csv -NoTypeInformation -UseCulture

Invoke-VMScript 500 Internal Server Error

$
0
0

No matter what I do, or what command or scripttext is run, the command returns the following;

Invoke-VMScript : 7/7/2017 1:21:23 PM    Invoke-VMScript        The remote server returned an error: (500) Internal Server Error.   

 

The last thing I tried was a simple dir. Logins removed on purpose;

 

Invoke-VMScript -VM "TestVM" -ScriptText "dir C:\" -HostUser "xx" -HostPassword "xx" -GuestUser "xxx" -GuestPassword "xxx"

 

I can get around this by setting up Powershell remoting, but it creates some dependencies I'd like to avoid. Any help or insight is appreciated.

 

How to make changes to rhttpproxy config file on multiple servers?

$
0
0

I need to change the log level from 'verbose' to 'warning' in  "/etc/vmware/rhttpproxy/config.xml" on 100s of ESXi hosts and restart rhttpproxy . Is there any way to automate this? LucD

PowerCLI to list all Powered Off VMs and Date of Event

$
0
0

I am trying to get this script to work but it doesn't even seem close at this point.  I am looking to run a report on Powered Off VMs and information about them.  I need to be able to clean the environment and have to wait 60 days before I permanently delete anything.  Any help would be great.

 

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password XXXXXXXXXXXX

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password XXXXXXXXXXXX

 

$Report = @()

$VMs = get-vm |Where-object {$_.powerstate -eq "poweredoff"}

$Datastores = Get-Datastore | select Name, Id

$VMHosts = Get-VMHost | select Name, Parent

 

foreach ($vm in Get-VM){

$view = Get-View $VMs

Get-VIEvent -Entity $VMs -MaxSamples ([int]::MaxValue) |

where {$_ -is [VMware.Vim.VmPoweredOffEvent]}

Group-Object -Property {$_.Vm.Name} | %{

  $lastPO = $_.Group | Sort-Object -Property CreatedTime -Descending | Select -First 1

  $row = '' | select VMName,Powerstate,OS,Host,Cluster,Datastore,NumCPU,MemMb,DiskGb,PowerOFF

    $row.VMName = $VMs.Name

    $row.Powerstate = $VMs.Powerstate

    $row.OS = $VMs.Guest.OSFullName

    $row.Host = $VMs.host.name

    $row.Cluster = $VMs.host.Parent.Name

    $row.Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name

    $row.NumCPU = $VMs.NumCPU

    $row.MemMb = (($VMs.MemoryMB),2)

    $row.DiskGb = ((($VMs.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)

    $row.PowerOFF = $lastPO.CreatedTime

  $report += $row

}}

$report | Sort Name | Export-Csv -Path "C:\XXXXX\Powered_Off_VMs.csv"

disconnect-viserver * -confirm:$false

 

I don't get an export to CSV and a display on screen of the following:

 

Template             : False

Key                  : 165369

ChainId              : 165369

CreatedTime          : 6/28/2016 10:19:35 AM

UserName             :

Datacenter           : VMware.Vim.DatacenterEventArgument

ComputeResource      : VMware.Vim.ComputeResourceEventArgument

Host                 : VMware.Vim.HostEventArgument

Vm                   : VMware.Vim.VmEventArgument

Ds                   :

Net                  :

Dvs                  :

FullFormattedMessage : ServerName on  XXX-prodesxi-10.xxxxx.com in ClusterName is powered off

ChangeTag            :


Query List of vCenters and output vCenter Server Name and Unique ID

$
0
0

Hi,

 

I'm looking to query a textfile list of vCenters and output each vCenter server's Name and vcenter Unique ID to CSV: | vCenter Name |  vCenter Unique ID |

 

$vCenterServerList = Connect-viserver -Server (Get-Content C:\Scripts\vCenterList.txt)
Foreach ($vCenter in $vCenterServerList)
{
$si = Get-View ServiceInstance
$setting = Get-View $si.Content.Setting
$vCenterUniqueID = $setting.QueryOptions("instance.id") | Select -ExpandProperty Value
select $.vCenter.Name,$vCenterUniqueID | Export-Csv C:\Scripts\vCenter-UniqueID-List.csv
}

 

Currently I'm getting the following error:

 

At line:1 char:43

+ ... ew $si.Content.Setting | $setting.QueryOptions("instance.id") | Selec ...

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

Expressions are only allowed as the first element of a pipeline.

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

    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

 

Any suggestions on how I can fix this?

 

Thanks,

Fin

vms deploy from template

$
0
0

Hello

 

I had requirement to deploy vms from a template where vms details are pulled from template as the node count is given in csv based on the node count in a row that many vms should create in series.

as i am new I can able to deploy single vm at once but i am faling to deploy multiple vms at once.

Can someone please write a script for my requirement

the csv file contains like this

 

For example if the node count is 2 it show create vms with names SERVM1,SERVM2 (the number count will increase if i increase the node count  in the csv like SERVM1,SERVM2,SERVM3,SERVM4)

 

Same for all the vms

       

NodesVmnamesTemplate nameDatastoreNumberOfCoresMemoryInMBOSStorageESXI
2SERVM1,SERVM2RHEL_6_New_TemplateSER_56_LUN_2013584RHEL 6.820Host1
1SERVM6RHEL_6_New_TemplateSER_56_LUN_2127168RHEL 6.820Host2
3SEZVM1,SEZVM2,SEZVM3Win2k12_STD_TemplateSEZ_45_LUN_4414336Win 12150Host3
4SEMVM46,SEMVM47,SEMVM48,SEMVM48Win2k12_ENT_TemplateSEM_55_LUN_10828672Win 121000

Host4

Customization spec created with powercli does not exist.

$
0
0

I can see it in the vsphere client and cannot remove or edit it. If I choose edit I get a pop-up that says "Specification <nameofspec> does not exist."  If I try to remove and choose yes to the prompt nothing happens.

 

Additionally the Get-OSCustomizationSpec cmdlet is now broken.

 

Get-OSCustomizationSpec : 7/10/2017 10:38:57 AM Get-OSCustomizationSpec         The object or item referred to could not be found.

At line:1 char:1

+ Get-OSCustomizationSpec

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

    + CategoryInfo          : NotSpecified: (:) [Get-OSCustomizationSpec], NotFound

    + FullyQualifiedErrorId : Client20_VmHostServiceImpl_GetCUstomizationSpecItem_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetOSCustomizationSpec

 

 

Dan

Creating a ESXi ISO with the latest updates included

$
0
0

I apologize in advance if this has been answered elsewhere, but I am new here and my search yielded no results.

 

I am attempting to make an  ISO with the latest updates included, but I am running into problems. In the instructions I am using (which can be found here - Create an ESXi ISO that contains all Patches | Virten.net ) says:

 

In the PowerCLI console Add the Software Depot

PowerCLI C:\> cd c:\tmp

PowerCLI C:\tmp> Add-EsxSoftwareDepot <update_File_Name.zip>

 

It should give the following output:

 

Depot Url

---------

zip:C:\tmp\ESXi550-201412001.zip?index.xml

 

However it appears I do not have that command available and have been unable to determine how to get it. When I run the command I get the following output:

 

PS C:\> Add-EsxSoftwareDepot ESXi650-201704001.zip

Add-EsxSoftwareDepot : The term 'Add-EsxSoftwareDepot' is not recognized as the name of a cmdlet, function, script

file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct

and try again.

At line:1 char:1

+ Add-EsxSoftwareDepot ESXi650-201704001.zip

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

    + CategoryInfo          : ObjectNotFound: (Add-EsxSoftwareDepot:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

 

 

 

 

Can anyone point me in the right direction to get past this issue? Thanks in advance!

Get-stat each esx physcial CPU usage

$
0
0

Hi,

 

I have esxi server with 32 processor (logical, HT enabled) and how do I get per processor usage average using powercli (same as displayed in vcenter CPU realtime usage stats)

add vCheck script to task scheduler

$
0
0

Hello,

the goal is to add vcheck.ps1 to a scheduled task on a server, I need to do the following:

 

I am using PoweCLi 6.5

 

1- run the PoweCLi.

2- connect to the vcenter server (I have a PS1 script that has the connect-viserver along with the credentials)

3- run vCheck.ps1 script.

 

I've read many articles but not working for my scenario, so what's the least-administrative-effort approach to accomplish this please?

 

I can load PowerCLi but couldn't add more scripts to the sequence.

 

Thanks.

Move-VM The request channel timed out while waiting for a reply after 00:05:00

$
0
0

I'm running a Move-VM command to move a VM from an NFS mount to a VSAN datastore and I'm getting this error.

 

Move-VM        The request channel timed out while waiting for a reply after

00:05:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding.

The time allotted to this operation may have been a portion of a longer timeout.

 

The task still continues and completes fine in vCenter, just PowerCLI times out.  Environment is PowerCLI 6.5 and PowerShell 5.0.  ESXi 6.5 GA. 

 

Anyone know how to increase this timeout?

 

BTW, Previously when I've ran this migration it worked fine with PowerCLI 5.5 and PowerShell 4.0.  Also, in that scenario I was migrating from an NFS mount to a regular VMFS datastore.

 

 

Here's the actual syntax of the command.

 

$DestDS =  get-vmhost "vmhostname" | Get-Datastore -Name "*vsan*"

$vmobj = get-vm "vmname"

$vmobj | Move-VM -Datastore $DestDS -ErrorAction:Stop


Extracting SSL Thumbprint from initial Connect-VIServer

$
0
0

Sorry if this has already been asked before, but I've not been able to find this by searching online or in the forums.

 

When you initially make a connection to either a VC/ESXi host, there's some information displayed about x509 Certificate as seen below.

 

* The X509 chain could not be built up to the root certificate.

 

Certificate: [Subject]

  C=US, CN=vcenter60-4.primp-industries.com

 

[Issuer]

  O=vcenter60-4.primp-industries.com, C=US, DC=local, DC=vghetto, CN=CA

 

[Serial Number]

  00D9B9AE28CFD6CF4D

 

[Not Before]

  2/8/2015 9:19:14 AM

 

[Not After]

  2/2/2025 9:19:13 AM

 

[Thumbprint]

  B846B9F36C1D978CEDA0199294E61B4515656396

 

I would like to capture the SSL Thumbprint "B846B9F36C1D978CEDA0199294E61B4515656396"? I've looked online and even asked some folks but never been able to retrieve this property using PowerShell/PowerCLI. I can easily do this on a non-Windows system with openssl (http://www.virtuallyghetto.com/2012/04/extracting-ssl-thumbprint-from-esxi.html) but wanted to see if there's a way without having to relay on external packages and since it's available as part of the Connect-VIServer, I figured it must be possible but my PowerCLI-Fu is not quite up to par as others, so figure I ask. If this is indeed extractable, which I assume it is then a bonus would be to format it so I have a variable that looks like: B8:46:B9:F3:6C:1D:97:8C:ED:A0:19:92:94:E6:1B:45:15:65:63:96


Thanks Luc in advance

test cluster in powercli

$
0
0

Can the test cluster command in powercli adversely affect a VMware environment ?  Does it make changes to Hosts/Configuration ? I want to run Test cluster in VMware environment where it test configurations / parameters of VMware cluster but does not make changes to environment. Which test cluster commands are most commonly used?

PowerCLI to reset network settings like done in DCUI

$
0
0

I am going through our entire environment making a change where the mac address of the management nic changes.  Long story short, on each host I am having to manually login to the console and do a network restore.  I'd like to try to program this as you can login through powershell to a host directly.  I happened upon a page http://searchvmware.techtarget.com/tip/PowersHell-Factory-Reset-of-ESXi  which shows doing a complete factory reset through powershell.  I just want to restore the network settings to default.

 

The code in the webpage is:

 

$vmhost = "esx4.vi4book.com"

$vcname = "virtualcenter4.vi4book.com"

 

#Connect to vCenter & Enter Maintenance Mode

Connect-VIServer $vcname -username administrator -password vmware

 

$esxhost = Get-VMHost $vmhost

$hostview = $esxhost | Get-View

 

Set-VMHost $esxhost -State maintenance

 

# Remove ESX host from vCenter...

Remove-VMHost $vmhost -Confirm:$false

 

# Carry out factory reset...

Connect-VIServer $vmhost -username root -password password

$esxhost = Get-VMHost $vmhost

$hostview = $esxhost | Get-View

$ns = Get-View -Id $hostview.ConfigManager.firmwareSystem

$ns.ResetFirmwareToFactoryDefaults()

 

I've looked around a bit in the API but haven't found anything yet.

Create New ORG VDC with specific storage profile

$
0
0

Environment: vCloud Director 5.6.4.  PowerCLI 6.0 R1

 

I have been working on a script for a little while now to create an Org, with an Org VDC and deploy an edge gateway in that org vdc.

 

I can manage to get the Org deployed without much issue, despite the New-Org command not including all options possible.  I can use $org.ExtensionData to set any of those options after I create my Org.  Not ideal, but it works.

 

However, the challenge I am having is creating a new OrgVDC (using the New-OrgVDC command) with the storage profiles we have in place.  The New-OrgVDC requires the -StorageAllocationGB parameter, but it doesn't allow me to select which storage policy to use.  When I attempt to just provide any value (aka, 100), the command fails "New-OrgVdc : 20/08/2015 4:25:09 PM    New-OrgVdc        The provider vdc does not contain the any storage policy." See screenshot of storage policies:

StorageProfiles.PNG

I found this post: Re: vCloud Director Storage Profiles where this value can be set *after* the Org VDC has been created, but not during the initial creation. Not to mention the inability of doing something wild and crazy like adding storage for both those storage profiles.

 

I am running this command (The ORG and ProviderVDC are correct):

 

New-OrgVdc -AllocationModelAllocationPool -CpuAllocationGHz 2 -MemoryAllocationGB 4 -Name "VDC-01-ON" -Org Tyler -ProviderVdc Reservation

 

When I run that I get prompted for StorageAllocationGB.

 

Interestingly enough, the userguide: https://www.vmware.com/support/developer/PowerCLI/PowerCLI60R1/doc/vsp_powercli_60r1_usg.pdf does not show this parameter is required.

 

Now, I am ok with setting it after the fact if I could create the ORG VDC initially, but I keep getting stuck on that initial storage profile issue.  Has this command simply not been updated for newer versions of vCD?  Is there anyway I can work around this situation and get my OrgVDC created using PowerCLI?

Esx host service tag

$
0
0

I am trying to run a script to display certain info but cannot get the host service tag to display. I am getting all other info EXCEPT for service tag. Please see the below for what I have so far. Any help would be appreciated.

 

#make an entry in the array for each one

   foreach ($line in $list){

    $row = "" | select id, vmname , dnsname, model, manufacturer, servicetag, ipaddr, vmhostid, vmguestos, ostype, vmvcpu, vmpowerstate,vmgueststate, vmhostname, vmhostcpu, vmhostcore, vmhostthread, version, build, vc, dc, cluster, date

    $row.id = $line.id

    $row.vmname = $line.name

    $row.dnsname = $line.guest.hostname

    $row.model = $line.vmhost.model

    $row.manufacturer = $line.VMhost.Manufacturer

    $row.servicetag = $line.vmhost.ServiceTag

    $row.ipaddr = $line.guest.ipaddress[0]

    $row.vmhostid = $line.vmhostid

    $row.vmhostname = $line.vmhost

    $row.vmguestos = $line.guest.osfullname

Viewing all 14549 articles
Browse latest View live


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