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

Overhead memory for all VM's

$
0
0

I am using method mentioned below by william Lam for pulling report of overhead memory. It works great for a single VM however when i try it for all vm's  it just populate

data on the screen and do not export it in the export path file.

 

http://www.virtuallyghetto.com/2016/01/easily-retrieve-vm-memory-overhead-using-the-vsphere-6-0-api.html

 

Command using for exporting overhead memory for all  the vm's

Get-VM  | Get-VMMemOverhead | Export-Xlsx  -Path D:\overhead.xlsx -WorksheetName HA

 

 

It shows the result in the screen but do not export.

 

Best Regards,

Deepak Koshal


commandline or script to add user (user admin) to multiple Stand alone cisco ucs server

$
0
0

Hello, kindly pls. assist me what is the commandline or script  to add user (user admin) to multiple Stand alone cisco ucs server , same ip range, same username and pass

via powershell/powertool script instead of manually login to cimc cisco console.

 

Thank you

powershell script that can pull NFS datastore info mounted from VC host

$
0
0

Hello! I would like to ask assistance to create a powershell script that can pull the following multiple

NFS datastore1, datastore2, mounted to multiple ESXi  v5/v6 Host in a VCenter and the possibility to send schedule email report.

sample output should be like this.

Datastorename    RemotePath          RemoteHost     VMname UsedSpaceGB ProvisionedSpaceGB  ownerfolder

Datastore1          /vol/datastore1/a1  192.168.192.10   VM1         30                80                                OS1

 

Hope someone can assist me, thank you in advance

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

Templates with RHEL7

$
0
0

Looking to see how people go about using templates to deploy RHEL7 servers. The challenge I am seeing with this is getting the MAC Address and IP information to update what we put in DHCP/DNS. Or what process are you using to build servers based off of customers spec request?

 

feedback/thoughts much appreciated

Change VM Name and harddisk path directory and vmdk to reflect new VM name

$
0
0

Hello Experts,

 

I'm in the process of preparing a script to change some VMs names. I prepared the script and applied it on PowerCli to change VM names on the fly (VMs were powered on). However,  when i was checking the VM files (get-harddisk), i noticed that the VM files are still keeping the old VM names and it did not reflect the new VM name. I have performed a little bit of a research and i did find a few remedies for that but they all require the VM to be down.

 

so my first question, is there a way to change the VM name and its files names on the fly while the VM is powered on? If the change cannot be done on the fly and VMs must be powered off what is the easiest and cleanest way to do it?

 

I could see two possible solutions for it, one of them is to change the VM name and then try cold migration of the VM to another data store or another host and then move it back to the original host and this should trigger the VM to change its file names to reflect the new name. the second possible solution is to follow the steps of Renaming virtual machine files in-place using the console in this link (Renaming a virtual machine and its files in VMware ESXi and ESX (1029513) | VMware KB ). Your help is always appreciated. Thanks

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.

how to get sessions use powercli

$
0
0

how to get sessions use powercli.this is no get-sessions command.


Set annotation on multiple vmguests from csv file

$
0
0

I have a csv with 2 columns. First column is a list of vmguest names and the second is an annotation I want to add to those vmguests. I basically want to add a unique key for each vmguest. So I'm using this script.

 

csv file

vmguestname,vmguestkey

name1,key1

name2,key2

name3,key3

script

$csv = (Import-Csv "annotations.csv")

$vmguestkey = ($csv.vmguestkey)

$vmguestname = ($csv.vmguestname)

 

foreach ($computer in $vmguestname){

Set-Annotation-Entity $computer -CustomAttribute "Key" -Value $vmguestkey

}

When I run the script I get a message

Set-Annotation : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Value'. Specified method is not supported.

Any idea what could I be doing wrong?

Delete vCloud Director related Custom Attribute on a VM

$
0
0

Hello

 

Following Tomas Fojta's blog post

How to Export Running VM from vCloud Director – Tom Fojta's Blog

 

I'm looking for a way to automate step 4: Remove vCloud Director related Custom Attribute on a set of powered on VMs

 

I gave a try with powerCLI, this gives the below error to me, whether the VM is powered on or off by the way.

 

PowerCLI E:\LabShare\Scripts> $vm.CustomFields.remove(“system.service.vmware.vsla.fraise”)

Exception calling “Remove” with “1” argument(s): “Cannot remove value from a
read-only dictionary.”
At line:1 char:1
+ $vm.CustomFields.remove(“system.service.vmware.vsla.fraise”)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException

 

Help welcome !

 

thanks

Tag multiple VM's

$
0
0

Hi,

I'm trying to tag multiple VM's in a large environment (thousands).

I'm hoping that I can read the contents of a csv and use PowerCLI to do the Tagging

 

cvs format would be

MyServer1,ApplicationNameXxxx

MyServer1,ApplicationNameBbbb

 

What I have so far is

 

$tc = New-TagCategory -Name "Application Name"
Get-Content -Path c:\VMTags.csv | ConvertFrom-Csv -Header VMname,Tag | foreach {
    if (!(Get-Tag -Name $_.tag)) {
        $t = $tc | New-Tag $_.tag
    }

    Get-VM -Name $_.VMname | New-TagAssignment -Tag $t -Confirm:$false
}

 

My intention is

  1. PowerCLI reads the csv file
  2. If the specified Tag does not exist already, it is created and assigned to the "Application Name" tag category
  3. The tag is then assigned to the VM

 

Thanks

Output vCenter SSO Password Policy

$
0
0

I need to do several monthly checks on my vCenters for permissions and Policies.  I have found a command that will output permissions for me but I am struggling to find a command that will output the vCenter SSO Configuration Password Policy settings.  Can anyone help me with what I need?

AggregateException when using a txt file to exclude VM's from output

$
0
0

I'm trying to use a text file that includes an extensive list of VM's i want excluded from an output.  The problem is when i run the script and it goes to exclude a larger number of VM's it throws AggregateException

 

Here's a sample:

 

 

$GetAllVms = Get-VM

$VMXNET3OneOffException = get-content "C:\scripts\ComplianceScriptBundle\ExceptionFiles\OneOffExceptions\Vmxnet3OneOffException.txt"

 

$GetAllVMs | Get-NetworkAdapter | Where-object {($VMXNET3WildcardException -notcontains $_.parent)} | select parent

 

 

This is the error in PS

 

Also if i remove this text file OR have a smaller list it will work fine.

 

I know you can have exclusions in the script itself but I'm trying to make it easier to view the script and change exclusions.

 

Any ideas would be helpful.  thanks!

Vcenter Alarms - what property?

$
0
0

Hi, 

Vcenter alerts are present in the GUI, but I don't know how to obtain them from CLI.  Anyone know the property / connection?

I'm writing an advanced function to query for the Alarms depicted in the Vsphere 6.2 Web GUI, in the Alarms Pane.  Via PowerShell I can query .ExtensionData.TriggeredAlarms for VMs and ESX hosts and obtain the results required.  What I can't seem to find, is where to find Vcenter Specific alerts.  Worded another way, alerts that apply to the Vcenter itself, not to the VM running the Vcenter.  Example alerts from my lab are Certificate Status, vpxd turned green from yellow, database space is low.  Connecting directly to the Vcenter (Get-VC), doesn't intuitively (to me) reveal where the alarm data is.  Or is it elsewhere?  I'm not searching for definitions - I'm searching for the live alerts.

Thanks

JoeA

Powershell Array

$
0
0

Hi Luc,

Need your help in redcuing the script run time. I've created the below script to combine powernsx and powercli to get the report that i wanted, But it is taking hours to complete the report. Can this be tweaked by changing anything?

I have 8 Nsx server so it is taking 9hrs to complete. :(

$report =@()
$cred = get-credential
Get-Module -ListAvailable | where{$_.Name -match "vmware*"} | Import-Module
Import-Module PowerNSX

foreach ($test in $nsx){
Connect-NsxServer $test -Username admin -Password xxxxxx -VICred $cred
$sectags = Get-NsxSecurityTag |where {$_.vmcount -ne "0"} | foreach{$_.name}
foreach ($tag in $sectags){
$data = Get-NsxSecurityTag -Name $tag | Get-NsxSecurityTagAssignment | select Virtualmachine
$data | Add-Member -Name "Security Tag" -Value $tag -MemberType NoteProperty
$data | Add-Member -Name "Server" -Value $test -MemberType NoteProperty
$report += $data
}
Disconnect-NsxServer
}


Get-VMHostNetworkAdapter not working on some hosts

$
0
0

hi,

i have a script that use the Get-VMHostNetworkAdapter cmdlet.

it runs on several esxi server (5.5u3) but other fail with the following error:

 

Get-VMHostNetworkAdapter : 03/08/2017 09:53:25Get-VMHostNetworkAdapterValue cannot be null.
Parameter name: key

At line:4 char:76

+ ... .xxx.internal" | Get-VMHostNetworkAdapter | Where ...

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

    + CategoryInfo          : NotSpecified: (:) [Get-VMHostNetworkAdapter], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostNetworkAdapter

 

i can't figure out what is the difference between the hosts (as they installed from the same iso, use the same profile etc..)

 

Example:

PS M:\> Get-VMHost "pru-esx01.xxx.internal" | Get-VMHostNetworkAdapter

 

 

Name       Mac               DhcpEnabled IP              SubnetMask      DeviceName

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

vmnic0     00:25:xx:xx:00:00 False                                           vmnic0

vmnic1     00:25:xx:xx:00:00 False                                           vmnic1

vmnic10    00:25:xx:xx:00:05 False                                          vmnic10

vmnic11    00:25:xx:xx:00:05 False                                          vmnic11

vmnic2     00:25:xx:xx:00:01 False                                           vmnic2

vmnic3     00:25:xx:xx:00:01 False                                           vmnic3

vmnic4     00:25:xx:xx:00:02 False                                           vmnic4

vmnic5     00:25:xx:xx:00:02 False                                           vmnic5

vmnic6     00:25:xx:xx:00:03 False                                           vmnic6

vmnic7     00:25:xx:xx:00:03 False                                           vmnic7

vmnic8     00:25:xx:xx:00:04 False                                           vmnic8

vmnic9     00:25:xx:xx:00:04 False                                           vmnic9

vmk0       00:25:xx:xx:00:00 False       10.xxx.xxx.40   255.255.255.0         vmk0

vmk1       00:50:xx:xx:63:22 False       30.30.30.1      255.255.255.0         vmk1

vmk4       00:50:xx:xx:b2:d7 False       10.xxx.xxx.1    255.255.255.224       vmk4

vmk3       00:50:xx:xx:c5:cf False                                             vmk3

 

 

 

 

 

 

PS M:\> Get-VMHost "pru-esx05.xxx.internal" | Get-VMHostNetworkAdapter

Get-VMHostNetworkAdapter : 03/08/2017 10:28:30 Get-VMHostNetworkAdapter Value cannot be null.

Parameter name: key

At line:1 char:63

+ ... sx05.oob.ramportal.eng.pelephone.internal" | Get-VMHostNetworkAdapter

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

    + CategoryInfo          : NotSpecified: (:) [Get-VMHostNetworkAdapter], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostNetworkAdapter

 

any help will be appreciated.

 

thanks

mordechai

How to remove redundant Permissions

$
0
0

Hi Guys,

 

So the goal is, to remove the redundant Permissions which you can see in the screenshot below. I'm not a PowerCLI Expert so I am looking for some guidance to do this. Environment is quiet large so scripting would be preferable.

 

The screenshot below shows that the Folder Permission is the same as the individual VM Permission. We want to remove all of the VM permissions which match the folder permission.

 

 

Here is the Pseudo code which I want to accomplish:

 

Where Folder Permission == VM Permission
$permission == VM Permission
$vm == VM Name
Remove $permission from $vm

 

I found the remove permission command:

 

Remove-VIPermission -Permission $permission -Confirm:$false

 

At the moment we currently have CSV files for each vCenter which lists the following:

 

foreach($vCenter in $vCenters)

{

Connect-VIServer -Server $vCenter.FQDN -Credential $credentials

Get-VIPermission | select role, principal, entity, UID | export-csv "c:\temp\$vCenter.FQDN-permissions.csv"

}

 

Any help much appreciated!

$esxcli.network.nic.list()

$
0
0

trying to get a list of my nic

 

$vmhosts = get-cluster "XXX" | get-vmhost

foreach ($vmhost in $vmhosts) {

$esxcli = get-esxcli -vmhost $vmhost

$esxcli.network.nic.list() | select *

 

}\

how do I add the vmhost in there?

PowerCLI script to create a clone with some conditions

$
0
0

Hello All, Can any one suggest me a script that should possible with below conditions. 1) Need create clone for every day 2 PM EST and that clone should be automatically deleted after 7 days. 2) Clone name format should be "Backup_MMDDYY" and the clone should be placed on "VM_BACKUPS" folder. 3) And it should be placed only in local datastore which has more than 150 GB freespace. 4) Once clone is completed or else failed to take a clone, need send an email. Thanks!!

 

Message was edited by: a.ß. - Changed title from all caps.

Script to export Network and VLAN info in Datacenter

$
0
0

Hello all,

 

Im looking for a script to export all network and vlan info across multiple clusters in one datacenter. This would only be the  Network info and none of the hardware info. I will use this to build out a new dvswitch.

 

Thank you,

Viewing all 14549 articles
Browse latest View live


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