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

Help with Adding Title to the output

$
0
0

Hi,

 

Please help me in adding the Title to the first Row of the Script. Below is the script

 

$report = Get-VM | Group-Object -Property {$_.Folder.Id} | Select @{N="Folder Name";E={$folder = $_.Group[0].Folder; $path = $folder.Name; $path}},

  @{N="Cluster";E={Get-Cluster -VM $_.Group}},

  @{N="CPU";E={$_.Group | Measure-Object -Property NumCpu -Sum | Select -ExpandProperty Sum}},

  @{N="Memory(GB)";E={$_.Group | Measure-Object -Property MemoryGB -Sum | Select -ExpandProperty Sum}},

  @{N="ProvisionedSpace(GB)";E={"{0:f1}" -f ($_.Group | Measure-Object -Property ProvisionedSpaceGB -Sum | Select -ExpandProperty Sum)}},

  @{N="Total VM's";E={$_.Group.Count}},

  @{N="PoweredOn VM's";E={($_.Group | Where-Object {$_.PowerState -eq "PoweredOn"}).Count}},

  @{N="PoweredOff VM's";E={($_.Group | Where-Object {$_.PowerState -eq "PoweredOff"}).Count}}

  $sum = $report | Measure-Object -sum "CPU", "Memory(GB)", "ProvisionedSpace(GB)", "Total VM's", "PoweredOn VM's", "PoweredOff VM's"

  $row1 = "" | Select "Folder Name","Cluster","CPU","Memory(GB)","ProvisionedSpace(GB)","Total VM's","PoweredOn VM's","PoweredOff VM's"

  $report += $row1

  $row2 = "" | Select "Folder Name","Cluster","CPU","Memory(GB)","ProvisionedSpace(GB)","Total VM's","PoweredOn VM's","PoweredOff VM's"

  $row2."Folder Name" = 'Total' -- Also I would like to Bold this row

  $row2.CPU = $sum | where{$_.Property -eq 'CPU'} | select -ExpandProperty Sum

  $row2."Memory(GB)" = $sum | where{$_.Property -eq "Memory(GB)"} | select -ExpandProperty Sum

  $row2."ProvisionedSpace(GB)" = $sum | where{$_.Property -eq "ProvisionedSpace(GB)"} | select -ExpandProperty Sum

  $row2."Total VM's" = $sum | where{$_.Property -eq "Total VM's"} | select -ExpandProperty Sum

  $row2."PoweredOn VM's" = $sum | where{$_.Property -eq "PoweredOn VM's"} | select -ExpandProperty Sum

  $row2."PoweredOff VM's" = $sum | where{$_.Property -eq "PoweredOff VM's"} | select -ExpandProperty Sum

  $report += $row2

  $report | Export-Excel -Path $reportlocation -WorksheetName Summary


List All Datastores based on vCenter Cluster

$
0
0

Hi,

 

I am issues listing datastores based on vCenter cluster. below script just shows same cluster name for all datastores.

 

Get-Datastore | Select Name, Datacenter,

@{N="Cluster"; E={(Get-Cluster).Name}},

@{N="CapacityInGB"; E={[math]::round($_.CapacityGB)}},

@{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) }},

@{N="FreeSpaceInGB";E={[math]::round($_.FreeSpaceGB)}},

@{N="VM Count";E={$_.ExtensionData.VM.Count}},

@{N="CanonicalName";E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}},

@{N="LUN";E={

             $esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

             $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

             $esxcli = Get-EsxCli -VMHost $esx.Name -V2

             $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')}}

Shrinking a thin .VMDK disk after deleting files

$
0
0

I have some Windows Server 2008 R2 and Windows Server 2012 R2 VMs using thin .VMDK files.

When the space used inside the partitions hosted by the .VMDK files decreases I need to reduce the space used by the .VMDK files as well.

Which PowerCLI commands can I use to shrink the .VMDK files?

Regards

marius

URGENT: PowerCLI Script to Redirect /var/core to External Datastore

$
0
0

Long story short, stateless auto deploy environment, 150+ hosts, hostd is crashing and filling up /var/core on the local partition. VMware support has instructed us to redirect /var/core directory to an external datastore. So..

 

1 - I have already created all the directories (ie /vmfs/volumes/datastore/coredumps/hostname)

2 - I need to see if I can script this for each host:

 

rm /var/core

ln -s /vmfs/volumes/datastore/coredumps/hostname /var/core

 

 

Also, if I have to do this manually, last resort, is there a way to script enabling SSH on all hosts?

 

Thanks in advance

Not able to fetch disk.read.average and disk.write.average of a virtual machine

$
0
0

We have around 20 virtual machines in an ESXi server, where I have used powerCli to fetch usage of cpu, memory, network and IO.

Till last week every parameter from all virtual machines was working fine without any errors, means was giving all values for all parameters fetched.

 

Today Suddenly for one of the VM I am getting an error

 

get-stat : 5/2/2018 3:52:27 PM  Get-Stat                The metric counter "disk.read.average" doesn't exist for entity "CloudVM"

At line:1 char:1

+ get-stat -Entity IPMVMCloudVM -stat disk.read.average

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

    + CategoryInfo          : ResourceUnavailable: (disk.read.average:String) [Get-Stat], VimException

    + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.

   ViCore.Cmdlets.Commands.GetViStats

 

I am getting values for other VMs.

 

Is there any configuration problem in ESXi ?

Edit/update Notes in VM

$
0
0

Hello, I have list of virtual machine where I need to modify existing notes, I would like to edit this notes (same for all) with powershell from a file (txt) Thanks

Is there a way to connect to multiple VMware servers in parallel using PowerCLI?

$
0
0

Hi,

 

I was just wondering if I can connect simultaneously on multiple VMware servers.

Today I'm using a foreach with the Connect-VIServer cmdlet, but it has to go though the entire list of servers.

Edit Alarm Action E-mail Recipients

$
0
0

I was wondering if anybody had a script for PowerCLI/vCenter 5.5 to mass edit the e-mail recipients under "Configuration" for 'Send a notification email' under Alarm->Actions in vCenter.

I looked throughout Google but I had only found broken links or scripts that are for version < 5.0

 

I would ideally like it to over-write the entire list of values but if there is one available that will simply append new recipients to all alarms, I could deal with that as well

 

Thanks for any help you may provide


Need a powerCLI script that helps to capture the ESXi hosts install date for the given servers (should be able to capture from the input text file) for ESXi 5.5, 6.0 and 6.5 versions

$
0
0

Need a powerCLI script that helps to capture the ESXi host install date for the given hosts (should be able to capture from the input text file) for ESXi 5.5, 6.0 and 6.5 versions and the output to be saved in a .csv output file. Can some one help asap please. Thanks in advance.

Is there a way to disable the ESXi host lockdown mode in vCenter as well as in the DCUI for entire vCenter hosts with a PowerCLI script ?

$
0
0

Is there a way to disable the ESXi host lockdown mode in vCenter as well as in the DCUI for entire vCenter hosts with a PowerCLI script ? - if any solution, would be grateful.

View SSH Status on hosts

$
0
0

Hello!

 

I am trying to create a function to view the status of SSH on a set of hosts. I kinda narrowed down what I want to see with this...

 

 

$VMHost.ExtensionData.Config.Service.Service

 

... but that lists every service on the host, and it does not show the actual VMHost Name.

 

Basically I'm looking for this...

 

Get-HostsSSH

 

... to yield

 

Name                                             

----

vmhost.local

 

Key           : TSM-SSH

Label         : SSH

Required      : False

Uninstallable : False

Running       : False

Ruleset       :

Policy        : off

SourcePackage : VMware.Vim.HostServiceSourcePackage

 

Name

___

vmhost2.local

 

Key           : TSM-SSH

Label         : SSH

Required      : False

Uninstallable : False

Running       : False

Ruleset       :

Policy        : off

SourcePackage : VMware.Vim.HostServiceSourcePackage

Script to get MPP for multiple DCs managed by different vCenters

$
0
0

I have below script to check MPP type and path state, it currently pulls details from "myDC1'.   Can anyone help modify it so that I can run this script against two different datacenters connected to two different VC ?

 

thanks in advance !

 

 

 

$DCName = 'myDC1'

 

$report = foreach($esx in Get-Datacenter -Name $DCName | Get-VMHost){

    $esxcli = Get-EsxCli -VMHost $esx -V2

    foreach($adapter in $esxcli.storage.core.adapter.list.Invoke() | where{$_.Driver -match 'fc'}){

        $esxcli.storage.core.path.list.Invoke() | where{$_.Adapter -eq $adapter.HBAName} |

        Select @{N='VMHost';E={$esx.Name}},

            @{N='Adapter';E={$adapter.HBAName}},

            Device,RuntimeName,State,

            @{N='PathPolicy';E={$esxcli.storage.nmp.device.list.Invoke(@{device="$($_.Device)"}) | select -ExpandProperty PathSelectionPolicy}}

    }

}

 

$report | Export-Csv C:\mylocation\MPP.csv -NoTypeInformation -UseCulture

Power CLI : Average CPU and Memory Utilization

$
0
0

HI,


Can some body provide me PowerCLI Script to find out Average CPU and Memory Utilization percentage for an ESX Cluster (Containing multiple ESX Hosts)?

Note : Require Average CPU and memory Utilization for multiple ESX Hosts together in a Cluster.

Get current time for all VM of the host or the cluster without authentication

$
0
0

Hello,

i want with powerCLi , obtain by host or by cluster the date-time and the VM name associate for each VM without authentication because each VM has its own password 

invoke-VMscript command given date-time but  we have to go through an identification, and the output don't give the name of the VM

It is possible

Thank you for your help

Connect-CisServer fails

$
0
0

Hey Guys,

 

I use the PowerCLI in version 10.1.0

I would like to Connect to the CisServer on up to 20 vCenters (all version 6.5 U1).

On each connection I use the administrator@vsphere.local

The connect fails on a few vcenters (the credentials are correct) with the following errormessage:

 

Connect-CisServer                         Error sending request

+ Connect-CisServer vcenterserver01

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

          + CategoryInfo                  : NotSpecified: (:) [Connect-CisServer], CisException

          + FullyQualifiedErrorId      : VMware.VimAutomation.Cis.Core.Impl.V1.Service.CisConnectionService.SessionCanNotBeCreated, VMware.VimAutomation.Cis.Core.Commands.Cmdlets.ConnectCisServer    

 

There is no firewall between my client and the vcenter server.

Has anyone a clue why it doesn´t work?

 

Thanks,

Max


invoke script output

$
0
0

Hi

I am trying to delete a registry key from windows machines by invoke method. Is there any way to write the output for the cmdlet (Remove-ItemProperty) or any other alternate to know whether the key is deleted or not.

$csvpath=""
$Credential= Get-Credential -Message "Enter the password for Administrator User" -UserName "Administrator"
$script = @'
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
if([IntPtr]::Size -eq 8){    $text = Remove-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -Name 'AgentGUID' -Force -ErrorAction SilentlyContinue        %{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 4){    $text = Remove-ItemProperty -Path "HKLM:\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -Name 'AgentGUID' -Force -ErrorAction SilentlyContinue


}
$text
'@
foreach($vmsincsv in (Import-CSV -Path $csvpath -UseCulture)){
$vm = Get-VM $vmsincsv.name
Invoke-VMScript -VM $vm -GuestCredential $Credential  -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
}

Sorting IP addresses

$
0
0

Hello Experts,

 

Wondering if anyone has a 'true' way to sort IP addresses... I do have:

 

Get-VM -Location $datacenter | where {$_.guest.IPAddress[0] -like "x.y.z*"} | Select @{N="IP Address";E={@($_.guest.IPAddress[0])}} | Sort -Property "IP Address"

 

Results in:

.

.

.

x.y.z.158

x.y.z.16

x.y.z.160

x.y.z.163

x.y.z.164

x.y.z.165

x.y.z.17

x.y.z.170

x.y.z.175

.

.

.

What I desire would return:

.

.

.

x.y.z.16

x.y.z.17

x.y.z.158

x.y.z.160

x.y.z.163

x.y.z.164

x.y.z.165

x.y.z.170

x.y.z.175

.

.

.

So, low to high.  In my case, x.y.z is the same first 3 octets, so, no need to sort based on those.  As I bonus, anything that returned the 'highest' IP address would be superb, but I could live with a numerically ascending list.  Using PowerCLI 10.  Thanks! 

KRAEMS

Creating equivalent vSphere Client report with PowerCLI

$
0
0

Perhaps this will offer a little bit of a challenge to some of you as it has me.  I'm trying to produce the same report that you can export from the vSphere Client (or web client) when you choose the Virtual Machines tab from either the Virtual Center Server, Datacenter, or Cluster objects.  You are able to customize it by adding or removing some columns and then export it in various formats.  I can't quite get it completely together, but I think I have a good start on this.

 

I apologize for the formatting, but here is the code I have done thus far.  Unfortunately it doesn't get all of the data for some of my VMs even though the vSphere Client reports data.  Most notably the GuestOS.

 

Does anyone have any idea what I might be missing or if there is a better way to do it?  I've included a table of the output below the code.

 

EDIT: I noticed the table didn't show up very well so I captured a screenshot of the output as well as the table in the vSphere Client.

 

Thanks,

Troy

 

 

&{get-vm |where-object {$_.VMHost.Parent -notlike "Excluded_Cluster_Here*"}|%{
$VMID=Get-View ($_.id)
new-object psobject -Property @{
VM = $_
PowerState = $_.Powerstate
OverallStatus = $_.ExtensionData.OverallStatus
VMHost = $_.VMHost
ProvisionedSpace = $_.ProvisionedSpaceGB.ToString("#.##")
UsedSpace = $_.UsedSpaceGB.ToString("#.##")
CPUUsage = ($_ | Get-Stat -Stat cpu.usagemhz.average -maxsamples 1 -realtime|where{$_.instance -eq ""})
MemUsage = ($_ | Get-Stat -Stat mem.usage.average -maxsamples 1 -realtime|where{$_.instance -eq ""})
GuestOS = $_.ExtensionData.Guest.GuestFullName
MemorySize = $_.MemoryMB
CPUCount = $_.NumCpu
Uptime = ($_ | Get-Stat -Stat sys.uptime.latest -maxsamples 1 -realtime|where{$_.instance -eq ""})
IPAddress = $_.guest.ipaddress[0]
DNSName = $_.ExtensionData.guest.hostname
Notes = $_.Notes
Cluster = $_.vmhost.Parent
Version = $_.Version
}|select VM,PowerState,OverallStatus,VMHost,ProvisionedSpace,UsedSpace,CPUUsage,MemUsage,GuestOS,MemorySize,CPUCount,Uptime,IPAddress,DNSName,Notes,Cluster,Version}
}|Export-Csv 'L:\Excel Docs\vmgather.csv' -notypeinformation -useculture

 

               

VMPowerStateOverallStatusVMHostProvisionedSpaceUsedSpaceCPUUsageMemUsageGuestOSMemorySizeCPUCountUptimeIPAddressDNSNameNotesClusterVersion
VUT-IT-LOG001-Nagios-Log-ServerPoweredOngreenmidvm42.local169.1567.242906553613012334Linux Clusterv7
VMLXTEST-RHEL-TestPoweredOngreenmidvm53.local50.1822.40371.99Red Hat Enterprise Linux 6 (64-bit)204821026628810.8.1.245vmlxtest.localv8
VWP-IT-APP046-Solarwinds-PollingPoweredOngreenmidvm35.local182.2168.4137634.99Microsoft Windows Server 2012 (64-bit)327684438611810.8.11.124VWP-IT-APP046.localProduction Clusterv9

Unmount an ISO using Views and ReconfigVm_Task()

$
0
0

I know it's possible to unmount an ISO using the PowerCLI Cmdlets:

 

Get-VM | Get-CDDrive | Where { $_.IsoPath } | Set-CDDrive -NoMedia -Confirm:$false

 

But I'm curious if the same thing can be done via the ReconfigVm_Task($Config) capability of a VirtualMachine View. I'm potentially changing several settings in this validation script (CPU/Memory Reservation/Limit/Shares, BootDelay, etc) - all captured as one large VMware.Vim.VirtualMachineConfigSpec. At the end of my validation script, I'm issuing one single Reconfigure task to speed up the process - rather than doing individual reconfigures.

 

Is it possible to unmount an ISO using only Get-View, manipulating a VirtualMachineConfigSpec, and ReconfigVm_Task()?

 

I'm running this against vSphere 6.5 with PowerShell 5.1 and the latest PowerCLI module from PSGallery.

Get-View filter with special characters like parentheses

$
0
0

I'm having an issue with the filter not working for some VMs that have a parentheses in their names.  It's likely just a RegEx problem, but I can't seem to figure it out.

 

Any thoughts?

 

 

&{get-vm |%{

$VMID=Get-View -ViewType VirtualMachine -Filter @{"Name"="$_"}

new-object psobject -Property @{

ViewName = $VMID.Name

VM = $_

PowerState = $_.Powerstate

}|select ViewName,VM,PowerState}

}|Export-Csv 'L:\Excel Docs\vmViewNames.csv' -notypeinformation -useculture

 

 

RESULTS

ViewNameVMPowerState
PACStest1PACStest1PoweredOff
ITDEV21 (WSUS)PoweredOff
Viewing all 16717 articles
Browse latest View live


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