Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all 9071 articles
Browse latest View live

Need help on script to sum the used diskspace for all VMs per folder (vCenter)

$
0
0

I got this far : Get-VM -Location <foldername> | foreach {Get-HardDisk -VM $_.name} | Measure-Object CapacityGB -Sum

 

This outputs the total size of all diskspace used by the VMs into the specified folder.

 

I would like to extend this and come to a report/table view below:

 

Foldername

VM1          used diskspace

VM2          used diskspace

VM3          used diskspace

Total size of all diskspace used all VM in this folder


Is this possible ?

 

Anyone having some tips and hints to point me in the right direction ?

 

Thanks a lot !

 




moving vm to a different datacenter

$
0
0

I was trying to move a vm from one datacenter to the other. The destination has 2 host clusters, each with multiple hosts. All hosts connect to the same datastore cluster.

 

Tried this but got an error: must be on the same datacenter:

$vm | Move-VM -Destination $vmHost -Datastore $ds

 

But if I tried -Destination as $datacenter object, PowerCLI didn't throw an error:

$vm | Move-VM -Destination $datacenter -Datastore $ds

 

However, the when I looked at the vSphere Client, it showed an error:

The operation is not supported on the object.

 

What's the best way to move a vm to a different datacenter?

ESXTOP and Get-esxtop

$
0
0

Hi All

 

 

I am trying to use get-esxtop to gather numofdroppedsend and numofdroppedrecv stat and i am using

 

get-esxtop -countername netport | where {$_.clientname -eq "vm"} | select *

it returns the data but has a number of 1952 for numofdropedrecv

 

when i look at esxtop on the same server for the same vm it shows 0 for $drptx and %drprx

 

i was wondering why and if i am gathering the data from the wrong counter.

 

Any help would be great

 

Thanks

John

Exporting RVtools report in CSV from Power Cli automation script

$
0
0

Hi all,

Can we Export the RV tools Report through Power Cli script.

I could get the details from RV tools per VC , but i want to get details of RVtools report of multiple VCs in sheet

from Power Cli script.

 

E.g.

 

RVTools.exe -passthroughAuth -s VM01.ze.zk.com -c ExportAll2xls -d %EXPORTDESTINATION% -f VM01_%RUNDATETIME%.xls

 

START /WAIT RVToolsSendMail.bat smtpek.us.zk.com 25 VMwareMEmailNotifications@ZK.comVMSV49_RVTooolsExport@ZK.com %LOG_FILE_ARCHIVE% >> %LOG_FILE_2% 2>&1

 

Thanks in advance.

 

vmk2014

orphaned vmdk files script

$
0
0

I found the below useful script for finding orphaned vmdk files as seen below:

 

  1. Purpose : List all orphaned vmdk on all datastores in all VC's

  2. Version: 1.1

  3. Author  : HJA van Bokhoven

  4. Modifications: LucD

 

$report = @()

$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}

$arrDS = Get-Datastore | Sort-Object -property Name

foreach ($strDatastore in $arrDS) {

          Write-Host $strDatastore.Name

          $ds = Get-Datastore -Name $strDatastore.Name | % {Get-View $_.Id}

          $fileQueryFlags = New-Object VMware.Vim.FileQueryFlags

          $fileQueryFlags.FileSize = $true

          $fileQueryFlags.FileType = $true

          $fileQueryFlags.Modification = $true

          $searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec

          $searchSpec.details = $fileQueryFlags

          $searchSpec.matchPattern = "*.vmdk"

          $searchSpec.sortFoldersFirst = $true

          $dsBrowser = Get-View $ds.browser

          $rootPath = ""

          $searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)

 

          foreach ($folder in $searchResult)

          {

               foreach ($fileResult in $folder.File)

               {

                    if ($fileResult.Path)

                    {

                         if (-not ($arrUsedDisks -contains ($folder.FolderPath + $fileResult.Path))){

                              $row = "" | Select DS, Path, File, Size, ModDate

                              $row.DS = $strDatastore.Name

                              $row.Path = $folder.FolderPath

                              $row.File = $fileResult.Path

                              $row.Size = $fileResult.FileSize

                              $row.ModDate = $fileResult.Modification

                              $report += $row

                         }

                    }

               }

          }

     }

 

 

When I run this script, it lists my datastores, but then after each datastore it brings up the following error message:

 

Exception calling "SeachDatastoresubfolders" with "2" argument (s): Invalid datastore path..........

 

Is there any reason why this script would bring this error message, I am using the lastest version of powercli client, or would it mean I have no orphaned vmdk files.  Any advise.

invoke-vmscript change guest ip address

$
0
0

I am trying to use Alans function to change ip address on windows guests with an import-csv file

 

 

Function Set-WinVMIP ($VM, $IP, $SNM, $GW, $DNS1, $DNS2, $WINS, $GC){

 

 

$cmd = @'

netsh interface ip set address "Local Area Connection" static $IP $SNM $GW 1"

netsh interface ip add dns name="Local Area Connection" source=static addr=$DNS1 register=primary

netsh interface ip add dns name="Local Area Connection" source=static addr=$DNS2 index=2

netsh.exe interface ip set wins name="Local Area Connection" source=static addr=$WINS

'@

 

 

Invoke-VMScript -VM $VM -GuestCredential $GC -ScriptText $cmd -ScriptType bat

}

 

 

 

 

$GC = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for $VM", "", "")

 

Import-Csv "C:\Users\tkw\vms.csv" -UseCulture | %{

 

 

Set-WinVMIP $_.VM $_.IP $_.SNM $_.GW $_.DNS1 $_.DNS2 $_.WINS $GC

}

 

 

 

but keep getting this error

 

Screen Shot 2015-08-06 at 9.27.35 AM.png

 

 

any idea?

OVF property keys for vCC Node 2.7

$
0
0

Anyone could point me to information about OVF property keys for vCC Node 2.7?

 

I have tried automatic deployment :

 

--allowExtraConfig --acceptAllEulas --powerOn --name=VCCMT --numberOfCpus:VCCMT=1 --coresPerSocket:VCCMT=1 --diskMode=thick --datastore="DatastoreC" --network="Simple" --prop:vami.DNS.VMware_vCloud_Connector_Node="10.10.10.60" --prop:vami.netmask0.VMware_vCloud_Connector_Node="255.255.255.192" --prop:vami.ip0.VMware_vCloud_Connector_Node="10.10.10.120" --prop:vami.gateway.VMware_vCloud_Connector_Node="10.10.10.1" "C:\ovf\vCCNode-2.7.1.0-2651441_OVF10.ovf" " vi://root:password@vC"

 

But I see returned:


C:\Program Files\VMware\VMware OVF Tool>.\ovftool.exe  --allowExtraConfig --acce

ptAllEulas --powerOn --name=VCCMT --numberOfCpus:VCCMT=1 --coresPerSocket:VCCMT=

1 --diskMode=thick --datastore="DatastoreC" --network="Simple" --prop:vami.DNS.V

Mware_vCloud_Connector_Node="10.10.10.60" --prop:vami.netmask0.VMware_vCloud_Con

nector_Node="255.255.255.192" --prop:vami.ip0.VMware_vCloud_Connector_Node="10.1

0.10.120" --prop:vami.gateway.VMware_vCloud_Connector_Node="10.10.10.1" "C:\ovf\vC

CNode-2.7.1.0-2651441_OVF10.ovf" " vi://root:XXXX"

Opening OVF source: C:\ovf\vCCNode-2.7.1.0-2651441_OVF10.ovf

The manifest validates

Source is signed and the certificate validates

Opening VI target: vi://root@X

Deploying to VI: vi://root@X

Transfer Completed

Powering on VM: VCCMT

Warning:

- OVF property with key: 'vami.DNS.VMware_vCloud_Connector_Node' does not exist

s.

- OVF property with key: 'vami.gateway.VMware_vCloud_Connector_Node' does not e

xists.

- OVF property with key: 'vami.ip0.VMware_vCloud_Connector_Node' does not exist

s.

- OVF property with key: 'vami.netmask0.VMware_vCloud_Connector_Node' does not

exists.

Completed successfully

 

Thanks,

Audit user actions using Get-VIEvent.

$
0
0

Hi

 

Just wondering if there is a good way to audit user actions. I have seen a few post with using get-vievent to do things like check for when a VM has been created or removed.

But does anybody have any scripts or examples where they out-put all events by the user?

 

I know i can

 

Get-VIEvent -Start ((Get-Date).AddDays(-7)) -Finish (Get-date) -maxsamples 10000 | where-object {$_.username -like "*Domain*"}

 

Although for the output I can get the FullFormatedText I cant get much other details about the objects they are working with. Like DC, Cluster etc. Just wondering is somebody has worked on something similar, and did they use more than get-VIevent.


can i install PowerCLI 5.5 Release 1 on windows server 2012 R2

Unable to get SCSI ID for VM Harddisks

$
0
0

Hi,

 

I having issue with the attached script not able to retrieve the harddisk SCSI ID (1:0, 2:0)

 

Am I missing sometime, please help

 

Thanks

 

Get-VM | Get-HardDisk |

Select @{N='VM Name';E={$_.Parent.Name}},

@{N="IP Address";E={@($_.Parent.guest.IPAddress[0])}},

@{N='HD Name';E={$_.Name}},

@{N='HD Capacity';E={$_.CapacityGB}},

@{N='DiskType';E={$_.DiskType}},

@{N='HD Format';E={$_.StorageFormat}},

@{N="Datastore";E={Get-Datastore -VM $_}},

@{N="SCSIid";E={$strControllerKey = $_.ControllerKey.ToString(); "{0}`:{1}" -f $strControllerKey[$strControllerKey.Length - 1], $_.Unitnumber}},

@{N='NAA';E={$_.ScsiCanonicalName}} |

Export-Csv C:\Updated_Prod_VM_Datastore.csv -NoTypeInformation -UseCulture

Invoke-Item C:\Updated_Prod_VM_Datastore.csv

Does #PowerCLI use the /sdk or /mob link when making calls after connecting to #vCenter?

$
0
0

Does #PowerCLI use the /sdk or /mob link when making calls after connecting to #vCenter?  I'm looking for some logging and wondered what PowerCLI relies on for communication (aka a web service)

PowerCLI / PowerShell code building tool

$
0
0

I'm looking to find a tool that will take an existing REST API and create skeleton code in powershell to call that API, so that I don't have to create all the individual URIs and request headers myself.

 

Does anyone have a recommendation for a tool like this for use with powershell?

Can someone provide me a powercli script to retrieve Service Tag Details of HP ESXI Hosts

$
0
0

Can someone provide me a powercli script to retrieve Service Tag Details of HP ESXI Hosts in a cluster.

check if a service exists on a vmguest, using powercli

$
0
0

Is there a way I can check if a service exists on a vmguest, using powercli?

I found many ways to do this using powershell commands, but I want to know if I can do it using powercli.

 

Thanks

graphite - powercli

$
0
0

#vCenter settings

$vCenter = "VCENTER-IP"

$user = "USERNAME"

$password = "PASSWORD"

$cluster = "YOUR-CLUSTER"

#Graphite server

$remoteHost = "GRAPHITE-SERVER-IP"

 

#Socket to send results to Graphite server

$socket = new-object System.Net.Sockets.TcpClient($remoteHost, 2003)

$stream = $socket.GetStream()

$writer = new-object System.IO.StreamWriter $stream

 

Write-Host "Connected"

#Connect to vCenter

Connect-VIServer -Server $vCenter -User $user -Password $password

 

#Get all ESXi hosts from Cluster

$esxhosts = Get-VMHost -Location $cluster | Sort

 

#Collect stats foreach ESXi server and bring it in a Graphite compatible format

foreach ($esxName in $esxhosts){

 

$allstats = Get-Stat -Entity (Get-VMHost $esxName) -MaxSamples 1 -Realtime -Stat cpu.usage.average,disk.usage.average,net.usage.average | Sort

Write-Host $esxName

foreach($stat in $allstats){

#Get Timestamp of stats and convert to UNIX timestamp

$time = $stat.Timestamp

$date = [int][double]::Parse((Get-Date -Date $time -UFormat %s))

#Filter only average stats (Stats for CPU's are available foreach CPU and as average of all CPU's)

$instance = $stat.Instance

if($instance -eq [DBNull]::Value){

#create a base for the graphite tree

$base = "dc.vmware.prod."

#remove the .usage.average

$type = (($stat.MetricId).Replace(".usage.average",""))

#remove the domain from the esxi name

$name = (($esxName.Name).Replace(" ","")).Replace(".your-domain.de","")

$value = $stat.Value

#build the graphite compatible string

$result = "$base$name.$type $value $date"

#Console output just for testing

Write-Host "Sent Result: $result"

#send result to graphite server

$writer.WriteLine($result)

$writer.Flush()

}

}

Write-Host " "

}

## Close the streams

$writer.Close()

$stream.Close()

#disconnect from vcenter

Disconnect-VIServer -Server $vCenter -Confirm:$false -Force

Write-Host "Done"

 

 

===

 

Script works without err... but the data does not shows up in graphite

 

Anyone has any idea


ESXi Host NTP Info

$
0
0

I am looking to write a script to tell me the Host Name, NTP Server, Service Running (yes or no), Policy (start with host, manual, automatic) and the time on the server. Is this possible? I have the one liner below that is pulling half of what I am looking for - although the policy piece is not pulling and I need to get the time to display.

 

Get-VMHost |Sort Name|Select Name, @{N=“NTPServer“;E={$_ |Get-VMHostNtpServer}}, @{N=“ServiceRunning“;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq “ntpd“}).Running}},@{N=“Policy”;E={(Get-VmHostService -policy $_ |Where-Object {$_.key-eq “ntpd“})}}

 

Thanks

bug in Set-VMHostNetworkAdapter

$
0
0

Please check the note in

 

https://www.batchworks.de/set-vmhostnetworkadapter-vmotion-option-is-broken/

 

 

is this bug ?

i tried

 

get-vmhost xxx |set-VMHostNetworkAdapter  -IP xxx -SubnetMask 255.255.255.0  -VirtualSwitch vswitch1 -PortGroup  vmotion  -VMotionEnabled $true

 

get-vmhost xx-xxx* | Get-VMHostNetworkAdapter -VMKernel - gives me 3 vmks

 

i have vmk0 1 g with vmotion on & mgmt on - vswitch0

 

i want to use  vcwst1 vmk namee XYZ vmotion only turned on

Failed to check for updates Error downloading manifest. Please contact your vendor. couldn't connect to host URL

$
0
0

Hello,

 

I am trying to patch JRE to 1.7.0_76 on our vMA per this KB: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2112648

 

Our vMA does not have internet connectivity so I am used the section under the KB for  'Updating Existing vMA Installation by Using tar.gz Update Bundle'

 

My vMA's web files (.xml and .html files) were located under /opt/vmware/share/htdocs

I made a /repo directory there and extracted the tar file to the /opt/vmware/share/htdocs/repo directory.

In the vMA web client under Settings, I saved the repository url as https://ip-address-of-vma:5480/opt/vmware/share/htdocs/repo

 

After clicking the 'Check Updates' button I get the following error:

 

Failed to check for updates(Error downloading manifest. Please contact your vendor. couldn't connect to host URL: https://ip-address-of-vma/opt/vmware/share/htdocs/repo/manifest/manifest-latest.xml) on Tuesday, September 29, 2015 12:56:09 PM GMT-04:00

 

I contacted VMware Support and they noted VMware Communities is the only place that supports vMA.

Any assistance would be appreciated.

 

Thanks.

 

Also the root file system has mysterious run out of space since I extracted this patch for JRE 1.7.0_76.

PowerCLI 6.0 R2 - Exception calling "OnImportModule" error on Windows 10

$
0
0

Hello - I am looking for some support on this little issue.  When running PowerCLI 6.0 R2 on Windows 10 x64, I receive the following exception message at the top of the window and I'd like to figure out how to resolve it.  I have spoke briefly with Brian Graf but he was unsure of how to resolve this and mentioned that this version of PowerCLI is not yet "technically" compatible with Windows 10, although it may still work for the most part.  Can anyone help me out please?

 

Error Message:

Exception calling "OnImportModule" with "2" argument(s): "A provider is not

available for the following required component service: LicenseService"

At C:\Program Files (x86)\VMware\Infrastructure\vSphere

PowerCLI\Modules\VMware.VimAutomation.License\Initialize-SDKComponent.ps1:1

char:1

+ [VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory]::CoreService ...

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

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

    + FullyQualifiedErrorId : NotSupportedException

PowerCLI.png

Need tiny sub scripts to confirm available datastore usage prior to running a script that clones a bunch of VM's to a specific datastore.

$
0
0

Hi Guys,

 

Thanks you in advance for any assistance you can provide I really feel a tad out of my depth here and scripting is definitely a weak point of mine which I am trying hard to rectify.  I have stolen a script that does pretty much exactly what I want, it clones a bunch of VM's to a specific datastore, it checks a file for a list of VM's.  However if case this operation fails I need to it to perform some prerequisite checks at the start of the script.  If the prerequisites are not met I need the script to halt with an exit code.  One example of a prerequisite I can think of would be...


-     is there more that 500GB of free space? or is 50% of the datastore free?  (and if this prerequisite is not met I would need it to halt halt with exit code 2? For example)


Is there someone that could be kind enough to provide an example of the above so I can get my head around it and any others I can think of.  And for bonus points feel free to suggest any other basic checks I might need to perform to validate the operations?  The purpose of this is anyone else that examines the script when/if it fails will obviously see what went wrong. 

Viewing all 9071 articles
Browse latest View live


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