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

ESXCLI returning {VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliObjectImpl}

$
0
0

Hi Im trying to retrieve cache stats though powerCLI using Get-EsxCli, but its not returning all values.

Is this a known problem ?

 

 

PowerCLI version VMware-PowerCLI-6.5.0-4624819. ( 6.5.0.234 )
OS Windows 10
vCenter 6.5.0 Build 4602587

VMware ESXi 6.5.0 4564106

 

PowerCLI C:\> Connect-VIServer vCenter

 

 

Name                           Port  User

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

vCenter   443   sonny

 

PowerCLI C:\> $esxcli = Get-EsxCli -VMhost esx012 -V2

PowerCLI C:\> $esxcli.storage.vflash.cache.list.Invoke()

 

 

Name

----

vfc-2609293434-ly-cg-20_2

 

PowerCLI C:\> $esxcli.storage.vflash.cache.stats.get.Invoke(@{cachename = 'vfc-2609293434-ly-cg-20_2'; modulename = 'vfc'})

 

Cacheusagerateasapercentage  : 99

Evict                        : {VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliObjectImpl}

Meannumberofcacheblocksinuse : 214111

Read                         : {VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliObjectImpl}

TotalfailedSSDIOs            : 0

TotalfaileddiskIOs           : 0

 

 

 

 

 

 

PowerCLI C:\>


What is the Powercli command to find vsphere clients in powercli (is the a parameter that is specific to vsphere client?)

$
0
0

In Powercli I can find  esxi Hosts, I can find virtual machines,  Is there a powercli command to find vsphere client (only vsphere clients). one has to connect to viserver in order to access powercli.

get-host for esxi host

get-vm for virtual machines

get-??? for vsphere client ????

Force duplicate host name

$
0
0

There are occasion where the duplicate vms are created with the same host name. To prevent and avoid this, we need to create a duplicate vms. Is there any easy way to do this by PowerCli or vijava or vSphere-client?

 

Please let me know.

 

Thank You,

Senthil

Looking for a script to get vpxa agent version

$
0
0

I am working with a customer that has a large number of hosts in several vCenter environments. In troubleshooting some issues due to a recent upgrade to VCenter 6.0 U3, I have a need to verify the vCenter agent version on each of the hosts. I can certainly login manually to each one and do something like this:

 

rpm -qa | grep vpxa

 

But I would much rather be able to do it through a script. Just curious if this is feasible. I can connect to the hosts in a look and get the appropriate service:

 

Connect-VIServer -Server MyESXi -User myRootUser -Password myPassword
Get-VMHostService |    Where {$_.Key -eq "vpxa"}

 

However I do not see a way to grab the version info. Hoping I am missing something stupid-simple that someone could point out.

Finding a backing storage container in the vSphere MOB

$
0
0

I'm running into a bit of a pickle trying to automate creation of VVol datastores. The problem seems to be that when a storage container is created, its not immediately available for use. The following code works fine if you wait a minute before the foreach loop, but I'd like to be a bit more deterministic. What I think should happen is I should query the vSphere MOB for the $scid content which shows up as the "backing storage container" when you go through the process of creating the VVol datastore through the web client. However, I can't, for the life of me, find how to find it. The final use will be for vRO, but the IDE there is painful, so mocking up with PowerCLI first.

 

#Create Storage Container via SF API call
$SFMethodArgs = @{}
$SFMethodArgs.Add("name",$VVolSCName)
$SFAPIResult = Invoke-SFApi -Method "CreateStorageContainer" -Params $SFMethodArgs<#
The storageContainer ID is not in the format VMware wants it
SolidFire Return: a6af2b22-d468-4d89-b73a-3f53c7390da0
VMware wants: vvol:a6af2b22d4684d89-b73a3f53c7390da0
#>


$SFscid = $SFAPIResult.Values.storageContainerID
$t = $SFscid.Split("-")
$scid1 = -join ($t[0..2])
$scid2 = -join ($t[3..4])
$scid = "vvol:"+$scid1+"-"+$scid2


#Create the VVolDatastoreSpec
$spec = New-Object VMware.Vim.HostDatastoreSystemVvolDatastoreSpec
#Set the name and source ID for the VVol Datastore
$spec.name = $VVolDSName
$spec.scId = $scid


#Build the VMHost DatastoreSystem for all hosts so we can mount the VVol to each host
$VMhosts = Get-Cluster $vSphereCluster | Get-VMHost


#Create the VVol datastore on each host in the cluster
foreach ($VMhost in $VMHosts) {
    $vmhostDS = get-view $vmhost.ExtensionData.ConfigManager.DatastoreSystem    $vmhostHDS = $vmhostDS.MoRef.ToString()    $_this = Get-View -Id $vmhostHDS    Write-Host "Creating VVol datastore $($VVolDSName) on $($vmhost)..." -ForegroundColor DarkGray -NoNewline    $_this.CreateVvolDatastore($spec)
}

 

I can get the required data using get-datastore, but that only works if a datastore has already been created. Chicken and egg problem there ;-) The data I want is the URL field.

$ds = get-vmhost "ts-vh-07.ts.local" | get-datastore vrotest3
$ds.ExtensionData.info

VvolDS                 : VMware.Vim.HostVvolVolume
Name                   : vrotest3
Url                    : ds:///vmfs/volumes/vvol:d0acdc04835844b2-999c2511136ea43e/
FreeSpace              : 276546135785472
MaxFileSize            : 8000000491520
MaxVirtualDiskCapacity : 8000000491520
MaxMemoryFileSize      : 9223372036854775807
Timestamp              : 3/23/2017 4:10:28 PM
ContainerId            :

get-datastore will give me the data I need, but only works for storage containers that have already had a VVol datastore bound to them.

 

Any help would be appreciated.

Get-Log: The operation has timed out

$
0
0

So we have a script that takes an ESXi host and just does:

 

Connect-Viserver [ESXihostname] -Credential (Import-clixml [credfile])
Get-Log -Bundle -DestinationPath E:\Logs\

 

However, about exactly 5 min after the execution of Get-Log, the cmdlet consistently errors with:

 

Get-Log : 3/23/2017 12:05:02 PM    Get-Log        The operation has timed out At line:1 char:1 + Get-Log -Bundle -DestinationPath E:\Logs\ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo: NotSpecified: (:) [Get-Log], ViError     + FullyQualifiedErrorId : Client20_QueryServiceImpl_WaitForUpdates_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetLog

And for the life of me, I cannot find a timeout that extends this.

 

Set-PowerCliConfiguration -WebOperationTimeoutSeconds -1
$vmHost | Get-AdvancedSettings -Name 'UserVars.ESXiShellTimeOut'  (equals 0)

$vmHost | Get-AdvancedSettings -Name 'UserVars.ESXiShellInteractiveTimeOut'  (equals 900)

 

There's an old KB about modifying the timeout on the query service, but this applied to vCenter 4, and doesn't seem applicable now. So I'm struggling to find any setting to modify this timeout and allow a Get-Log execution to complete (vSphere client takes just over 15 min to run).

 

Any help would be appreciated.

Get-Log;operation timed out;weboperationtimeoutsecond

What does ProvisionedSpaceGB Include?

$
0
0

Can anyone tell me if provisionedSpaceGB in powerCLi includes space for all virtual machine files such as swap files and page files?

 

Thanks!

Script to change DNS and NTP needed

$
0
0

I am new to scripting. I am looking for a script that will change the two DNS server IPs as well as change the NTP server and restart the NTP servicen of an ESX host. Could it also make the change on an esx host as well as a datacenter level?

 

Thanks!


Mail the powercli output

$
0
0

I'm little new to powercli.

 

I have created a script to list all the ESXi hosts across our vCenters which are not in Connected state. I'm able to get the output as a text format and was able to schedule it in Windows Task scheduler. But I would like to automate further by mailing the output to my mail ID. How can I achieve that?

How to get report of unused VMDKs?

$
0
0

Guys, is there a way we can get report of unused VMDKs using any free tool or PowerCLI?

I am suspecting some of the virtual machines were removed from inventory a long back instead of deleting them from disk but not sure.

 

Thanks

How to enable and disable SSH on Multiple Esxi in vCenter

$
0
0

Hi All,

Recently our security team asked for enabling ssh services on all esxi running in vcenter in different datacenter and cluster to scan authentication VA on each esxi.

This is bit of pain to go to every esxi and manually enable/disable ssh.We need help and solution from script we can achieve in single click.:-)

If we can get the script which will help us to enable & start ssh services on all esxi server & Once scanning is over, same service can be disable/stopped.

If someone has answer or script which is tested will be grateful him/her.

Thanks in advance.

Script to migrate cluster from one vCenter to another vCenter

$
0
0

Attached is a script I use to migrate an ESXi cluster from one vCenter to another.  I'll be updating the script (will add VM folder locations and attributes, more qa, root credential storage - PASSWORD IS STORED IN TRANSCRIPT FILE - so, adjust this in script or cleanse transcript after run), but for now it handles HA settings, DRS settings, EVC, DRS vm rules (affinity/anti), folder import/export, permissions (datacenter, cluster, host, folder and vm) and maybe some other things I left out.  Does not deal with dvs as we use local vswitches.

 

You'll need two VCs and a cluster you want to migrate.  The script does not create the datacenter in the destination VC, but it will create the cluster, disconnect, remove an add the hosts.

 

I hope it can help someone as I've mainly been on the receiving end with regards to help from this forum .  Special note to Luc for a lot of the items in the script (folder functions, splat etc ).

 

Just unzip to a directory and run with powercli (requested credentials must have VC privs to disconnect hosts etc.).

 

As always with offerings, use at your own risk!

 

*Using to go from 5.0 to 5.5.

vcheck - Hardware status warnings

$
0
0

I keep getting this error from vcheck on a host but from the hardware side, we see no errors. It HP server and there are no errors. hardware monitoring service is not working in vcenter so I cannot see if there is an error. But from the ilo, there is no error. Even the drive has been replaced.

 

any idea how to reset this plugin/check?Screen Shot 2017-03-24 at 6.42.28 AM.png

ISCSI with Chap and Mutual Chap

$
0
0

I'm trying to setup chap and mutual chap on an hba for an iscsi connection on ESX6.5 with Power-CLI 6.5.  I grab the hba and then setup a new iscsi hba target and specify chap and mutual chap.

 

$hba = $vmHost | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"}

New-IScsiHbaTarget -IScsiHba $hba -Address $target -IScsiName $iscsiTargetName -type Static -ChapType 'Required' -ChapName $chapName -ChapPassword $chapPW -MutualChapEnabled:$true -MutualChapName $chapName -MutualChapPassword $mchapPW

 

It sets up everything but the chap and mutual chap. Those still show as 'Do not use CHAP' and the information I tried to set seems to have disappeared.

 

Any ideas?

naa to datastore name

$
0
0

how do I a naa id to datastore name?


Getting and Setting vmKernel IP

$
0
0

Currently I have this:

 

$vmkernel0 = Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq "xxx" } | Select Name

Set-VMHostNetworkAdapter -VirtualNIC $vmkernel0 -IP $xxx -SubnetMask $xxx

 

im receiving this error:

Set-VMHostNetworkAdapter : Cannot bind parameter 'VirtualNic'. Cannot convert the "@{Name=vmk1}"...

 

Im trying to use the output of Select Name, which in this case is vmk1 to input into the next command.

 

Doesnt work. Any assistance would be great

 

Thank you

Migrate all permissions from a built in role to a new role.

$
0
0

I'm in an environment where a built in vCenter role was used. There are many permissions set using this role at different levels of the vCenter. What approach would you take to point all the existing permissions to a new role?  I see a lot about exporting vCenter permissions between vCenters but nothing on this.

For Each Loop and Set-VMNetworkAdapter

$
0
0

I have two seperate rows in my csv. So two different hosts and values I want to manipulate.

Im calling the foreach to grab the first host, connect to it and get/set vmkernel IP. Then its supposed to discconnect from the host

Then grab the next host in the csv, connect to it, get/set different vmkernel IP. Then disconnect.

 

 

In actuality, what is happening is that the first host is completed successfully, everything is set right.

When the second host gets to set the vmkernel IP (with a different value than host 1), it then goes back and sets the second hosts vmkernel IP on the first host as well.

 

What gives? Im stuck.

 

 

foreach ($line in $csv)

{

 

#################################################################################

# Set Variables

#################################################################################

$newhost = $line.host

$var1 = $line.var1

$var2 = $linevar2

...

...

 

#################################################################################

# Connect to Hosts

#################################################################################

 

Connect-VIServer $newhost -User $vmhost_user -Password $vmhost_pass

 

 

#################################################################################

# Get VMKernel PortGroup and Assign IP and Subnet4

#################################################################################

Write-Host "Find the VMKernel PortGroup on Host $newhost and Assign New IP and Subnet to it!" -ForegroundColor Green

 

 

$vmkernel0 = Get-VMHostNetworkAdapter $newhost | where { $_.PortGroupName -eq "SAN 0" }

Set-VMHostNetworkAdapter -VirtualNIC $vmkernel0 -IP "$var1" -SubnetMask "$var2" -confirm:$False

 

Disconnect-VIServer $newhost

guest os ipaddress,subnet and gateway information

$
0
0

Hello

Can Some one correct me on below script...

&{foreach($vm in (Get-VM)){
$vm.ExtensionData.Guest.Net |Select
@{N="VM";E={$vm.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="OS";E={$vm.Guest.OSFullName}},
@{N="Tools";E={$vm.ExtensionData.Guest.ToolsRunningStatus}},
@{N="NicType";E={[string]::Join(',',(Get-NetworkAdapter -Vm $vm | Select -ExpandProperty Type))},
@{N="VLAN";E={[string]::Join(',',(Get-NetworkAdapter -Vm $vm | Select -ExpandProperty NetworkName))},
@{N="IP";E={[string]::Join(',',$vm.Guest.IPAddress)},
@{N="Gateway";E={[string]::Join(',',$vm.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress )| where {$_ -ne $null}},
{
foreach ($iproute in $vm.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute) {    if (($vm.Guest.IPAddress -replace "[0-9]$|[1-9][0-9]$|1[0-9][0-9]$|2[0-4][0-9]$|25[0-5]$", "0" | select -uniq) -contains $iproute.Network)    }    }
@{N="Subnet Mask";E={            $dec = [Convert]::ToUInt32($(("1" * $_.IpConfig.IpAddress[0].PrefixLength).PadRight(32, "0")), 2)            $DottedIP = $( For ($i = 3; $i -gt -1; $i--) {                    $Remainder = $dec % [Math]::Pow(256, $i)                    (                        $dec - $Remainder) / [Math]::Pow(256, $i)                    $dec = $Remainder                } )            [String]::Join('.', $DottedIP)        }},
@{N="DNS";E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.DnsConfig.IpAddress))}},
@{N="MAC";E={[string]::Join(',',$vm.MacAddress)}}
}
}
}
}
}

Looking for a Power CLI query /script which will dump all the contents of a datastore as we get to see when we browse it .

$
0
0

Hi All,

 

I am new to vmware and a beginner on power cli.I am posting a question for the first time :-)

I am in need to gather information about all the folder in a datastore .

What i exactly need is a browse datastore output in a excel , irrespective if it a vm added in inventory / a stale folder or a ISO folder .

Please help me ,. i have gone through a lot a blogs and found one thing which is close to what i need .

 

Link :Get datastore folders with PowerCLI

The output is as below , what it does is it lists the name of folder and the files in the foreground mode. I want it in a excel which i sent forward to the users.

Also i have been looking for some output formatting the length i believe is the size of file can it be in MB and the Name why does it come up as "Win2K8R2-ADDM-PRO..." rather then the complete name ?

Is there a way to format it .

 

Datastore path: [Customer_31]

         LastWriteTime            Type       Length Name

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

   1/18/2017   3:03 PM          Folder              Win2K8R2-ADDM-PROBE

 

Datastore path: [Customer_31] Win2K8R2-ADDM-PROBE

 

         LastWriteTime            Type       Length Name

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

   1/18/2017   3:03 PM    VmConfigFile         3756 Win2K8R2-ADDM-PRO...

   1/16/2017   3:22 PM     VmNvramFile         8684 Win2K8R2-ADDM-PRO...

   1/16/2017   3:22 PM       VmLogFile       600597 vmware.log

   1/16/2017   3:22 PM            File 214748364800 Win2K8R2-ADDM-PRO...

   1/16/2017   3:46 PM            File          274 Win2K8R2-ADDM-PRO...

   1/16/2017   3:22 PM            File            0 Win2K8R2-ADDM-PRO...

Viewing all 16717 articles
Browse latest View live


Latest Images

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