Hi expert
I would like to get Horizon License usage using PowerCLI
Could you tell me how to get license usage using command ?
THX
Hi expert
I would like to get Horizon License usage using PowerCLI
Could you tell me how to get license usage using command ?
THX
I upgraded to 10.1 from 6.5 and since I am struggling to make my scripts run. Below is my script, I can run it manually in powershell and it works, but when I run it with a scheduled task just gets stuck at "The task is currently running". In the scheduled task the action is:
Program:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments:
-noe -c "Import-Module VMware.PowerCLI" -File "C:\util\scripts\Reports\Daily\VM-Tools.ps1"
Start in:
C:\
Script:
#############################
# Connect to vCenter #
#############################
Import-Module -Name VMware.PowerCLI
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false
$vc = 'IP'
$Cred = Import-Clixml C:\util\Scripts\creds\autoitjob2.xml
#############################
# Content #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="c:\util\Scripts\Temp\tools-$date.htm"
$report = Get-View -ViewType VirtualMachine -Property Config.Template,Name,Guest.ToolsStatus -Filter @{"Config.Template"="False";"Guest.ToolsStatus"="^(?!toolsOk$).*$" ;"Name"="^((?!_replica).)*$"; "Runtime.PowerState"="poweredOn"} |
Select-Object Name,@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}}
#############################
# Add Text to the HTML file #
#############################
$report | ConvertTo-Html –title "VMware VMTools Check" –body "<H1>VMware VMTools Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation
ConvertTo-Html –title "VMware VMTools Check" –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware VMTools Check" –body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
######################
# FTP HTML output #
#####################
#we specify the directory where all files that we want to upload
$Dir="$filelocation"
#Below for test
#$Dir="C:/Users/administrator/Desktop/tmp/"
#ftp server
$ftp = "ftp://IP/internal-backups/datacenter/vcenter/misc-reports/Tools/"
$user = "internal-ftp-backup"
$pass = "PW"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
#list every sql server trace file
foreach($item in (dir $Dir "*.bak")){
"Uploading $item..."
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.UploadFile($uri, $item.FullName)
}
##############################
# Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false
HI Lucd,
Hope you are doing good.
Am a beginner on powerci script slowly getting a hang of it,I have tried this below script which you have posted on page1. And am getting the below operator error. can you let me know were am going wrong.
Connect-VIServer <192.168.***.***> -User <root> -Password <Password**>
$allvms = @()
$vms = Get-Vm
$start = (Get-Date).AddDays(-7)
$metrics = "cpu.usage.average","mem.usage.average"
$stats = Get-Stat -Entity $vms -Start $start -Stat $metrics
$stats | Group-Object -Property {$_.Timestamp.Day},{$_.Entity.Name} | %{
$vmstat = "" | Select VmName, Day, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
$vmstat.VmName = $_.Values[1]
$vmstat.Day = $_.Group[0].Timestamp.Date
$cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum
$mem = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum
$vmstat.CPUMax = [int]$cpu.Maximum
$vmstat.CPUAvg = [int]$cpu.Average
$vmstat.CPUMin = [int]$cpu.Minimum
$vmstat.MemMax = [int]$mem.Maximum
$vmstat.MemAvg = [int]$mem.Average
$vmstat.MemMin = [int]$mem.Minimum
$allvms += $vmstat
}
$allvms |
Export-Csv "c:\VMs.csv" -noTypeInformation
This may or may not be the right forum to ask this. I am working with a company that wants to move toward saltstack for all of its devops. I have been asked to confirm that salt can handle PowerCLI, and have found a few blurbs on the saltstack forums to this end, however nothing that says the number of commands available. From what I have read, it looks like only a paltry number of commands are available, unless you do some sort of double-hop, using salt to call PowerCLI. Just curious if anyone has used saltstack for VMware automation, and what the level of ability there is as compared to the native PowerCLI functions.
With respect to Writing data with the HTTP API | InfluxData Documentation we can use curl to post multiple points from file to insert to influxdb
[ curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary @cpu_data.txt ]
As I am using PowerCLI script to post points to influxdb using
[ Invoke-RestMethod -Uri 'http://localhost:8086/write?&db=DBName' -Method Post -Body "measurement-name,tag-name=tag-value value-name=value"]
I want know the similar syntax in Invoke-RestMethod to post from file.
Hello All,
I'm trying to get a list of all snapshots in our vcenter so I'm using this very simple query:
Get-VM | Get-Snapshot | Select VM,Name
It does return a list of snapshots but the name of the associated VM is blank:
VM Name
-- ----
snapshot blablabla
snapshot blablabla
snapshot blablabla
snapshot blablabla
snapshot blablabla
snapshot blablabla
snapshot blablabla
What am I missing?
Hi All,
I need to obtain the following data by importing a list of VM's from a CSV file, can someone point me in the right direction.
vCPU provisioned
Memory Provisioned
Memory usage (whatever is fine, avg, peak, point in time)
Storage provision
Storage used
Thanks,
Greg
I currently get a spreadsheet of system names and the values, many of which are not annotations.
I pull out the system names, and the value I need to add/update, massage that data as needed (mainly fixing the system name) and then run this script.
<code>
Import-CSV .\data.csv |for-each-object
{
set-annotation -Entity $_,vmname -customattribute "attrib-name" -value $_.value
}
</code>
I'd like to simplify what I do, and set all of the annotations from one spreadsheet, so I am just massaging it once, instead of once per annotation.
TIA!!
~Jahn
Hi folks,
From this code:
Get-VM -name $vm | Get-VMGuest | Select-Object -ExpandProperty Nics | select NetworkName,IPAddress
NetworkName | IPAddress | |
----------- | --------- | |
IP Storage | {10.100.38.38} | |
Backup | {10.100.37.163} |
VM Produccion-42 {10.100.43.163}
VM Management | {10.100.29.163} |
i would like to filter by NetworkName.
i tried:
Get-VM -name $vm | Get-VMGuest | Select-Object -ExpandProperty Nics | select NetworkName,IPAddress | where {$_.Nics.NetworkName -eq "VM Management"}
but it doesn't work.
Please help me to find out the correct syntax.
Thanks very much!
i am using esxcli storage core device detached remove -d NAA.ID to remove the detached(status=off) LUNs from each esxi hosts individually.
how can i use powercli script to identify the detached LUNs(esxcli storage core device detached list) and remove it from the host.
is there a way to get a list of datastore's capacity, used space, allocated space for the past week with an interval of 120mins with the date?
I searched through the internet but couldnt find a solution...
hen i use the "Add-VirtualSwitchPhysicalNetworkAdapter" command i am able to migrate the vmnic from vswitch to vdswitch dvuplink. by Default, vmnic goes to DVuplink. im currently using DVSwitch with LAG Group and i would like to migrate the vmnic to LAG Group instead of default DVuplink. is there any command to do that.
unable to find the parameter from SYNTAX:
Add-VirtualSwitchPhysicalNetworkAdapter [-VMHostPhysicalNic] <PhysicalNic[]> [-VirtualSwitch] <VirtualSwitch> [-VirtualNicPortgroup
<VirtualPortGroup[]>] [-VMHostVirtualNic <HostVirtualNic[]>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Hi, I'm working on collecting list of VMs from esxi hosts, when storage (FC) is down.
We are facing storage controller down or crash issues, during that time multiple esxi hosts are affected and it's respective VMs as well.
Hence we need to communicate the list of VMs which are affected during this scenario??
During this time esxi host will also be in disconnected state right? So will the get-vm command will work??
I have installed PowerCLI Version 6.0. I want to use the VMware API using the VMware.Vim.dll in my program. So I wrote this line of code using c# to load the .dll file.
Assembly assembly =Assembly.LoadFrom(fileLocation +@"\VMware.Vim.dll");
Unfortunately I get this error :
The file or assembly file: /// C: \ Program Files (x86) \ VMware \ Infrast ructure \ vSphere PowerCLI \ VMware.Vim.dll "or a dependency on it was not found. The assembly is created by a runtime that is more recent than the is currently loaded, and can not be loaded.
I have the same Problem with PowerCLI 6.5 and PowerCLI 10.0. I mean the file exist but I think I've Problem with compatibility.
PowerShell Version 3 is installed and .Net Framework 4.7.
Any Suggestions!!
Taher
Hi,
Please help me with Unmount and Detach Datastore for a cluster
function Detach-Disk{
param(
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMHost,
[string]$CanonicalName
)
$storSys = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem
$lunUuid = (Get-ScsiLun -VmHost $VMHost |
where {$_.CanonicalName -eq $CanonicalName}).ExtensionData.Uuid
$storSys.DetachScsiLun($lunUuid)
}
The above script would detach but before that I would like to unmount. please help
Looking for a script which can fetch the existing datastore clusters in the vcentre along with the datastores associated with the datastore clusters.
Hey Guys,
I try to request some information from the vCenter VAMI, like health status.
But the Get-CisService command seems not to work as I want.
First I connect successfully to the CisServer with Connect-CisServer with Administrator@vsphere.local.
After that I want to use Get-CisService to retrieve the general system health.
(Get-CisService -Name 'com.vmware.appliance.health.system' -Server $global:DefaultCisServers).get()
But it throws an authorization error.
I use PowerCLi 10.1.0
I´m really sure it worked in a previous release.
The exception is attached as screenshot.
Hope you have any suggestions or may a better way to get the informations.
Thanks.
Max
Hi gurus,
I have a bunch of VMs that have different storage configuration, some has RAW mapping LUN disk with multiple paths. I'd like to scan the VM list and generate a report indicates the MPIO status including the number of active paths to SAN per VM, not per host. I have VBS and PowerShell script running on VM. It's based on WMI function but restricted by credential or something else, in many cases there's RPC server unavailable error. So running WMI script on VM is not ideal. I wonder if someone could help developing a PowerCli script and scan VMs at host level but generate the report per VM. This is to replace the manual check operation on vCenter, go to each VM, check how many RAW mapped disks and how many paths for each disk.
Thank you,
Daniel
I've been using this script for sometime and it has been working... All of a sudden two lines are returning errors, maybe i'm missing something? Please help..
Import-Csv "C:\Users\techill\Desktop\techdeploy.csv" -UseCulture | %{
New-vm -Name $_.VM -VMhost $_."ESX Host" -Template $_.Template -Datastore $_.Datastore -OSCustomizationspec $_.Customization
Set-VM -VM $_.VM -NumCpu $_.NumCpu -MemoryMB $_.MemoryMB -Confirm:$false
Start-VM $_.VM
Start-Sleep 360 # seconds
Get-VM $vm | Get-HardDisk | Where-Object {$_.Name -eq "Hard Disk 2"} | Set-HardDisk -CapacityGB 10 -Confirm:$false
Move-VM -VM $_."VM" -Destination $_."Folder"
Get-NetworkAdapter -VM $row.VM | Set-NetworkAdapter -NetworkName $row.NetworkName -Confirm:$false
This lines doesn't do anything but use to change the drive size. Get-VM $vm | Get-HardDisk | Where-Object {$_.Name -eq "Hard Disk 2"} | Set-HardDisk -CapacityGB 50 -Confirm:$false
This line returns an error message Get-NetworkAdapter -VM $row.VM | Set-NetworkAdapter -NetworkName $row.NetworkName -Confirm:$false
we have around 28vcenter servers, if i want to work a script for a VM or cluster or esxi host, i am getting tough time to find its vcenter server. then i am connecting to it and working on any script.
is there any other methods will ease my job, like creatingsimple apis from existing inventroy.
now i am using by giving input of vcneter as csv files, connecting one by one to find the host or vm.
i tried to get the excel invetory of vms or esxi list and update it periodically and use its vcenter value, but we have huge amount of list, hence it is taking long time.
so looking for an easy option.