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

Customizing the vCheck script

$
0
0

Hi guys,

 

I would like to prune the vCheck script (available from http://www.virtu-al.net/vcheck-pluginsheaders/vcheck/ ) so that it is only reporting on a very select number of items rather than the vast amount of information it is reporting presently.

 

When I run vcheck -config I have been answer 0 to questions for things that I would rather not see such as:

 

HA VMs restarted

# HA VM restart day(s) number [0]:

 

Answer 0 does not appear to have the desired result (meaning simply don't perform this check).  Instead I'm seeing a lot of errors when running the report.  Is there a way to drop this from the script in its present form or do I need to modify the script itself?

 

Thanks.


Generate the datastore report using powercli script send the report through email every 4 hours

$
0
0

Hi Team,

 

Could you please assist on this request. Generate the datastore report using powercli script  send the report through email every 4 hours with below condition.

 

1) datastore above 90% should highlighted with red color.

2) datastore above 70% to 90% should be highlighted with yellow color.

3) datastore below 70% should highlighted with green color.

 

Thanks

Vijay

Remove a datastore that is in use

$
0
0

So, we have some datastores we're looking to retire, however removing them from the web client gives us a "datastore is in use" error.  We worked with VMware support, and they gave us a bunch of partedutil commands, but I'd like to try and automate this to reduce the human error factor. 

 

The commands to run are:

 

partedUtil getptbl /vmfs/devices/disks/naa.1234567890

 

partedUtil delete /vmfs/devices/disks/naa.1234567890

 

Everything else I can do with get-scsilun

 

This is what I have so far...

1. connect to vcenter

2. list the clusters

3. list the hosts in the selected cluster

4. list the datastores/luns on the host

5. browse the foor of the datastore selected (to verify nothing is on it and it's the one to be removed)

6. This would be where the partedutil commands go. 

 

Thanks in advance!

 

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

 

# Define the LunDatastoreName function

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

 

# connect to selected vCenter

connect-viserver $vcenter

 

 

# List Clusters

write-host ""

Write-host "Choose which Cluster where the LUN you want to remove presented:"

write-host "(it may take a few seconds to build the list)"

write-host ""

$ICLUSTER = get-cluster | Select Name | Sort-object Name

$i = 1

$ICLUSTER | %{Write-Host $i":" $_.Name; $i++}

$HCLUSTER = Read-host "Enter the number for the host to Patch."

$SCLUSTER = $ICLUSTER[$HCLUSTER -1].Name

write-host "You have selected $($SCLUSTER)."

start-sleep -s 3

 

# List hosts to select

write-host ""

Write-host "Choose which vSphere host that has the LUN presented."

write-host "(it may take a few seconds to build the list)"

write-host ""

$IHOST = get-cluster $SCLUSTER | Get-VMhost | Select Name | Sort-object Name

$i = 1

$IHOST | %{Write-Host $i":" $_.Name; $i++}

$DSHost = Read-host "Enter the number for the host to Patch."

$SHOST = $IHOST[$DSHost -1].Name

write-host "you have selected" $SHOST"."

 

 

# List all scsi devices

write-host ""

Write-host "Choose which LUN to remove.  *** VERIFY VIA THE vSPHERE CLIENT ***"

write-host "(it may take a minute to build the list)"

write-host ""

$ILUN = get-scsilun -vmhost $SHOST | Select LunDatastoreName, CanonicalName, RuntimeName, CapacityGB | Sort lundatastorename

$i = 1

$ILUN | %{Write-Host $i":" $_.lunDatastoreName, $_.RuntimeName, $_.CapacityGB; $i++}

$DSLUN = Read-host "Enter the number for the LUN to remove."

$SLUN = $ILUN[$DSLUN -1].LunDatastoreName

write-host "you have selected" $SLUN"."

 

 

# List the files on the LUN you selected

get-childitem (get-datastore $SLUN).datastorebrowserpath

Import-VApp Host did not have any virtual network defined

$
0
0

I have used the OVF tool to export a couple VM's from my 5.1 environment. When trying to import these VM's back into the environment using PowerCLi I get the error that is in the subject line. My hosts all currently use a VDS and one thing I read was add a virtual switch to the host that I am trying to import too. I have not tried that yet but I am curious why that would be required since it was not required on the export. I am using the 5.1 PowerCLi and my code is below.

 

 

********* Edit**********

Adding a regular vswitch to the host the script is now working. I have on physical adapter assigned to it, but it is not connected.

 

$items = Get-ChildItem -Path $OVF_Location -recurse | where {$_.psIsContainer -eq $false}
$format = ".ovf"
$VC_Password = ConvertTo-SecureString $VC_Password -AsPlainText -Force
$VCcred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Virtual_Center_Username, $VC_Password
Connect-VIServer -Server $Virtual_Center_Ip -Credential $VCcred
foreach ($item in $items)
{  $filename = $item.Name  if ($filename.Contains($format) -eq $true)  {        $vmhost = Get-Cluster | Get-VMHost | ?{$_.ConnectionState -eq "Connected"} | Get-Random  $myds = Get-datastore | Get-Random  if (($myds.FreeSpaceMB) -gt ($myds.CapacityMB * .25))    {  $datastore = $myds  }  else  {  Write-Host "There is not enough free space to create a Virtual Machine"  exit  }  $importPath = $item | select fullname  Write-Host "Importing OVF from: " $importPath.FullName " please wait as this will take some time."  $path = $importPath.FullName  Import-VApp -Source $path -VMHost $vmhost -Datastore $datastore  }
}
Disconnect-VIServer -Force -Confirm:$false

Unable to setRecoverySettings over the SRM API

$
0
0

Hello all,

I am create script for automation of adding server into SRM with requested settings, like priority, postRecoverySteps and so on.

I am strugled in the last step to set the requested settings to the SRM plan over a method srmPlan.SetRecoverySettings(vm, settings) with the following error:

Exception calling "SetRecoverySettings" with "2" argument(s): "fault.drextapi.fault.InvalidArgument.summary"

At C:\PowerShell\srm\SRM-Cmdlets\SrmFunctions.ps1:726 char:3                                               

+         $RecoveryPlan.SetRecoverySettings($moRef, $RecoverySettings)                                     

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

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

    + FullyQualifiedErrorId : VimException                                                                 

 

Could anybody help me with this,

thank you all in advance.

vSphere 6.0: VM cannot boot after assigning PCI passthrough QAT Co-processor by PowerCLI

$
0
0

The PCI device was an Intel QAT (Quick Assistant Technology) device.

 

This (add PCI passthrough then poweron) can be done by vSphere Client, or vSphere Web Client

but failed to do it via powershell CLI: when the device was added via powershell CLI, the VM cannot boot, no matter by powercli or vSphere Client.

 

The error message from powershell:

DEBUG: 7/13/2017 12:36:44 PM Start-VM  The operation for the entity

"colin-61-4" failed with the following message: "The systemId does not match

the current system or the deviceId, and the vendorId does not match the device

currently at 97:0.0.". The systemId does not match the current system or the

deviceId, and the vendorId does not match the device currently at 97:0.0.

Failed to start the virtual machine. An error was received from the ESX host

while powering on VM colin-61-4.

 

I tried to get /dump the PCI device with powercli passed through the VM via both vSphere Client and powercli, they seemed identical. details attached in the end of this post

 

The only suspect was the VendorID was dumped to a negative integer, could it be that the Vendor ID was saved incorrectly when adding the device via powercli for that the error message said venderid mismatch?

And there's a thread reporting similar issue like this, which seemed a bug in vSphere web interface: ESXi 6.0 - VM can't boot after assigning PCIE GPU passthrough : vmware

 

1.  script used to dump the device:

    $pass_set1 = $vm | Get-PassthroughDevice -Type 'Pci'

    ForEach ($d in $pass_set1) {

        Write-Debug $d.Uid

        Write-Debug($d | Format-List | Out-String)

    }   

 

 

2. when the device was added via vSphere Client, in this case, the VM can boot smoothly.

the device was dumped as followed:

 

DEBUG: 7/13/2017 12:10:08 PM Get-PassthroughDevice

DEBUG:

/VIServer=root@10.32.228.84:443/PassthroughDevice=10.32.228.154-VirtualMachine-

vm-1945-<class> Co-processor-0000:61:00.0/

DEBUG:

 

 

Bus           : 97

ClassId       : 2880

DeviceId      : 14280

Function      : 0

Slot          : 0

State         : Active

VendorId      : -32634

Uid           :

/VIServer=root@10.32.228.84:443/PassthroughDevice=10.32.228.154

                -VirtualMachine-vm-1945-<class> Co-processor-0000:61:00.0/

VendorName    : Intel Corporation

Name          : <class> Co-processor

VMId          : VirtualMachine-vm-1945

VM            : colin-61-4

VMHostId      : HostSystem-host-1415

VMHost        : 10.32.228.154

Key           : 13000

ExtensionData : VMware.Vim.VirtualMachinePciPassthroughInfo

Client        : VMware.VimAutomation.ViCore.Impl.V1.VimClient

 

3. when the device was added via powercli, VM cannot boot.

the device was dumped as followed:

 

DEBUG: 7/13/2017 1:23:42 PM Get-PassthroughDevice

DEBUG:

/VIServer=root@10.32.228.84:443/PassthroughDevice=10.32.228.154-VirtualMachine-

vm-1945-<class> Co-processor-0000:61:00.0/

DEBUG:

 

 

Bus           : 97

ClassId       : 2880

DeviceId      : 14280

Function      : 0

Slot          : 0

State         : Active

VendorId      : -32634

Uid           :

/VIServer=root@10.32.228.84:443/PassthroughDevice=10.32.228.154

                -VirtualMachine-vm-1945-<class> Co-processor-0000:61:00.0/

VendorName    : Intel Corporation

Name          : <class> Co-processor

VMId          : VirtualMachine-vm-1945

VM            : colin-61-4

VMHostId      : HostSystem-host-1415

VMHost        : 10.32.228.154

Key           : 13000

ExtensionData : VMware.Vim.VirtualMachinePciPassthroughInfo

Client        : VMware.VimAutomation.ViCore.Impl.V1.VimClient

Host data gathering

$
0
0

Hi

 

I am trying to write a script that will return some information but this is also a general question.

Here is a one-liner. i am seeking to get the Name of the esx hosts as well as the model. The name is not a parameter that is returned from Systeminfo . So how can i get a parameter that appears sooner in the script to be included in the final output?

 

((get-vmhost| select -ExpandProperty extensiondata).hardware.systeminfo |where {$_.Model-like"* M*"})| select Name, Model

 

Thank you for any help.

John

Script to check if iDRAC is a member of Domain or not

$
0
0

Hi All,

is there a script where we can know if a iDRAC  is a domain member or not.

 

It is important to have idrac in domain so as to login the idrac with AD account with proper track.

 

 

Thanks a ton


Automating the process of adding Active Directory as authentication source in vCenter

$
0
0

Hi,

 

I am looking for automating (using PowerCli) the process of adding AD as an authentication source in vCenter and add 'domain admins' group as Administrators.  I am running vCenter 6.5 on windows server joined to the same domain.

 

thanks

List all VMs in a DataCenter with a particular tag in a category even if tag is missing.

$
0
0

Disclaimer:  I powershell challenged.

 

I am looking for a powercli that can list ALL VMs in a particular datacenter that do or do not have the tag category 'ApplicationOwner' assigned to them.

 

The closest i have seen is the following which will list out all the tag catogories for each vm.

 

$cat = Get-TagCategory -Name 'ApplicationOwner'

Get-VM | Where{Get-TagAssignment -Entity $_ -Category $cat} | Select Name,@{N="Tag";E={(Get-TagAssignment $_.name).tag}}       (lists VM with it)

Get-VM | Where{!(Get-TagAssignment -Entity $_ -Category $cat)} | Select Name,@{N="Tag";E={(Get-TagAssignment $_.name).tag}}    (lists VMs without it)

 

I just want to get all vms in a datacenter and have a list with the two columns Name and Tag.  The name would be the VM and the Tag would be something like  ApplicationOwner/HR.  The real trick is it would be nice to list all VMs wheather this particualr tag is assigned or now.  I.E.  It it is not assigned, then just have a blan in the Tag column.

 

I hope someone can help.

 

Thank you.

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

Retrieving VM Settings in Power Shell

$
0
0

Basically, I want my script to be able to check for a particular setting, in this case "isolation.tools.copy.disable", whether it exist in each VM or not. And after checking, it would want to retrive/store the VM without the setting and add a new one. If setting exist, it would then continue and check on the existing setting value . So, here's my 'try' on achieving it however it doesn't seem to work at all. any help would be appreciated. Here the code:

 

#Check for console copy

Write-Host "`nCheck for Console Copy`n" -ForegroundColor Gray

$copytool = Get-VM | Get-AdvancedSetting -Name "isolation.tools.copy.disable" | Select Entity, Name, Value

$setting = Get-VM | Get-AdvancedSetting

$vmcount = (Get-VM | Measure).Count

#Check if setting exist

for ($y = 0;$y -lt $vmcount; $y++){

     if ($setting[$y].Name -ne "isolation.tools.copy.disable"){

     $name = $setting[$y].Entity

     Write-Host "'isolation.tools.copy.disable' in $name is not Found!"

}

#check if existing setting value

else { ...... <this part is fine>

NSX Ipsec tunnel status

$
0
0

Hi Lucd,

 

Good day, We are using powernsx to get some info for NSX, But there is no details about IPSec VPn statistics status. Is there anyway to achive this?

Thanks in advance.

PowerCLI 6.5.1 connect-viserver returns nothing

$
0
0

I recently installed PowerCLI 6.5.1 on a Windows 2012 R2 server.

From this Server is I run connect-viserver 'MyVCenterServerName',

  • nothing is returned when attempting to connect to a v5.5 U3b vCenter. the vCenter does not connect
  • I can connect to v6.0 vCenters

 

From a Server running powerCLI 6.3, if I run connect-viserver 'MyVCenterName' for the same v5.5 U3b vCenter, it does connect

 

I've checked the compatibility matrix for powerCLI 6.5 and, it looks like it is compatible with vCenter 5.5

Anyone else encountered this ?

Get VM Name, Hard disk file name, and size

$
0
0

Hello,

 

I need to get a VM name, VMDK file name, provisioned size, and actual size please.


using an input file

$
0
0

For most of the scripts I have created I have done:

 

 

$vmlist="blah","blah1","blah2"      <--- would like file located for example in c:\tmp\inputfile

 


foreach ($vm in $vmlist)
   {
     Get-VM $vm | Select-Object   -Property Name,NumCpu |FT -AutoSize

 

 

I really would like to use an input file instead of listing it like I am above. I have tinkered with it but  im just not getting it.

 

 

Thank you!!!

list disks rdm with powershell

$
0
0

 

Hello ,

 

 

i like how lists disk rdm of a vm .Command get-hardisk give me location vmdk , capacity , but i want more informatation disks RDMs

 

 

Por example , i want to list imformation like vmhba 1:0:9:0 , SCSI (2:1) , etc  for each disk . 

 

 

Someone can gime some help

 

 

Thanks

 

 

Finding out relation between vmdk and file system

$
0
0

Hi All,

 

We have a few VM which uses multiple small VMDKs to make up one file system.

 

For example, this is the disk layout for one of our VM.

PS > $vm.ExtensionData.Layout.Disk

Key DiskFile                                                               

--- --------                                                               

2000 {[ca02sanp10-sata-crypt08] ca02webp22/ca02webp22_6.vmdk}

2001 {[ca02sanp10-sata-crypt08] ca02webp22/ca02webp22_1.vmdk}

2002 {[ca02sanp10-sata-crypt08] ca02webp22/ca02webp22_2.vmdk}

2003 {[ca02sanp10-sata-crypt09] ca02webp22/ca02webp22_3.vmdk}

2004 {[ca02sanp10-sata-crypt08] ca02webp22/ca02webp22_4.vmdk}

2005 {[ca02sanp10-sata-crypt09] ca02webp22/ca02webp22.vmdk} 

2006 {[ca02sanp10-sata-crypt09] ca02webp22/ca02webp22_7.vmdk}

2008 {[ca02sanp10-sata-crypt11] ca02webp22/ca02webp22.vmdk}

 

Here are the file systems on the VM:

PS > $vm.guest.disks

CapacityGB      FreeSpaceGB     Path                                             

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

3.812           2.792           /                                                

0.117           0.044           /boot                                            

3.812           3.043           /home                                            

1.445           1.442           /tmp                                             

3.812           0.829           /usr                                             

9.718           5.213           /var                                             

4,802.861       2,189.231       /data01                                          

7,219.176       649.892         /data01/archiveold                               

10,902.010      4,332.745       /data01/archive                                  

 

Using info from VM guest OS and vCenter, we know that /data01/archiveold is made up of ca02webp22/ca02webp22_3.vmdk, ca02webp22/ca02webp22_4.vmdk, ca02webp22/ca02webp22_6.vmdk.

 

Is there a way in powercli to find that out?

 

I would like to script this and collect all VMs which has multiple VMDKs for one single file system.

 

Thanks,

Andrew

I am getting an error -"Connect-VIServer : Invalid URI: The hostname could not be parsed." when i try to connect from Powershell script. however if i try the command from powecli promt it works. Can someone hlep here?

$
0
0

I am getting an error -"Connect-VIServer : Invalid URI: The hostname could not be parsed." when i try to connect from Powershell script. however if i try the command from powecli promt it works. Can someone hlep here?

Gather Edge information

$
0
0

Dear Community,

 

I'm in need of a script which can gather the following information:

 

- versions of all Edges (adminVAppNetwork, adminOrgNetwork and edgeGateway)

- type of Edge

- organizations they are located in

 

Looked pretty simple but it isn't, at least for me.

 

I am able to gather the versions in one script (Get-VM | Get-View). I can gather different types in another, using API, and of course I can gather the list or organizations but I am currently unable to match them.

 

Can you help me out please?

Thank you.

Viewing all 14549 articles
Browse latest View live


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