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

Script for ssh service start then followed by other commands

$
0
0

Hi All,

 

I was trying to merge esxi SSH service start then following by other command in same script but unable to merge the same. Can someone good at powercli help me in creating such script.

 

The following activities should be done in script.

 

-> Start SSH service for esxi host (Specific Cluster in vCenter)

Then

-> esxcli sched swap system set -l false

then

-> esxcli system corefump file remove -F

 

Then stop the SSH service

 

 

 

the above 4 steps should be included in one script.

 

Thanks in Advance.

 

 

 


HA/DRS audit in HTML

$
0
0

Hi All,

is there already some script available for daily HA/DRS audit the output should come in html or trigger to email id.

 

My requirement is

 

to check --

ha/drs status enabled or disabled.

sdrs status enabled or disabled.

alarms status enabled or disabled

no. of vms connected to iso

 

the above requirement in nice html or trigger output in email.

 

thanks in advance.

Host is unavailable for checking compliance.

$
0
0

Hey guys, I'm having a little issue with some new ESXi 5.1 hosts I recently stood up.

 

We have a cluster built in vCenter 5.1 that is made up of 8 hosts. All are Cisco B200 M3s. 4 of which were recently stood up. I am having problems with these new 4 in that they will not fully accept the host profile that is attached to the cluster level for these hosts. The host profile that is built for this cluster is really just to apply the network configuration to new hosts added to this cluster. Unfortunately, for these new hosts it says it has applied this Host Profile but none of the network configurations are being applied and they are being shown as noncompliant with a reason of "Host is unavailable for checking compliance."  Thanks for any assistance.

vMA Migrate Virtual Machine

$
0
0

I am having a heck of a time trying to find documentation on how to use vMA to migrate a VM from one host to another.  I'm not talking storage vMotion, just simply migrating a machine from one host to another on shared storage.  Is it that this is not an option?  I would expect that it is.

 

Using vMA 5.5 or 6.0, how do I move a VM from one host to another from the command line?

 

Thank you.

Needing help with finding VM's that are missing Virtual USB Controller

$
0
0

I am needing help with a script that I am modifying from vCheck.  In my environment, I have to have a virtual usb controller in every vm.  So, I am trying to modify the script to look for missing virtual usb controllers.  Below is the script:

 

# Start of Settings

# Find wanted virtual hardware

$wantedHardware = "VirtualUSBController"

# End of Settings

 

$vWantedHw = @()

foreach ($vmguest in $FullVM) {

    $vmguest.Config.Hardware.Device | where {$_.GetType().Name -eq $wantedHardware} | %{

        $myObj = "" | select Name,Label

        $myObj.Name = $vmguest.name

        $myObj.Label = $_.DeviceInfo.Label

        $vWantedHw += $myObj

    }

}

 

$vWantedHw | Sort Name

 

Where I am getting stuck is at the Config.Hardware.Device -eq part.  Running it gives me all VM's that have the usb controller.  If I set it to -noteq it gives me everything that is attached to the VM.  All I want to do is find and list any VM's that do not have the virtual usb controller.  Any help is greatly appreciated.  Also, does anyone know where I can find any documentation on these sub-commands (-eq) on the cmdlets?

Deploy VM Guest Machine from Linux Command Line

$
0
0

Hello,

 

I would like to know how can i deploy existing VM template with customization  file from Linux machine to my VCENTER  

I download VMware-vSphere-CLI-5.5.0-1549297.x86_64.tar.gz   but what command should i use .

 

Thank You

vSwitch and Portgroup Security Settings

$
0
0

 

I am looking for a way to query the security settings (Promiscuous Mode, Forged Transmits and MAC Changes) of vSwitches and Portgroups. MY PS skills are limited. I can get about this far mostly from patching together various scripts I found. However at this point I must supply a vSwitch and even when I am able to pass that information I have no idea what to do after that.

 

 

    Foreach ($VMHost in Get-VMHost){

    Foreach ($vSwitch in ($VMHost | Get-VirtualSwitch )){

    $hostMoRef = Get-VMHost $VMhost | % {Get-View $_.Id}

    $hostNetwork = $hostMoRef.configManager.networkSystem

    $hostNetworkMoRef = Get-View $hostNetwork

    $hostNetworkMoRef.NetworkInfo   

        }

    }

 

 

 

 

 

 

 

 

      

 

 

Get-ContentLibraryItem doesn't work

$
0
0

Hello,

 

I just installed PowerCLI 6.3 Release 1, in order to get 'Get-ContentLibraryItem' cmdlet available.

After launching the console, and connect to a vCenter, I run 'Get-ContentLibraryItem' command but, nothing happens.

The console doesn't return anything and it's like stuck. I can't even stop the command by CTRL+C.

 

It works for the other commands with no issue (get-vm, get-vmhost, and so on).

 

Has anybody been able to get content library information via PowerCLi?

 

If anybody can help, no idea how to troubleshoot this issue.

 

 

Thanks in advance.


Setting sys.global.loghost to null

$
0
0

I had one Loginsight Server and somehow it has been removed from the system. Now i need to remove its ip address from ESXi's Syslog parameter under advanced settings. Do you have an powercli script that removes and sets the sys.global.loghost parameter to null? I like to do it Cluster by cluster. Thanks

Inject WMI query into existing PowerCLI Inventory

$
0
0

I need some help.  I have a nice PowerCLI script that I run and pull just about every piece of information that I could possible think of.  When posting the inventory for other internal resources to view, it was brought to my attention that my script returns the generic VMWare OS information.  My challenge is to integrate a WMI query into the report that will gather the detailed Operating System information.

 

(Get-WmiObject -Class Win32_OperatingSystem).Caption

 

This powershell commandlet returns what I desire....

 

Microsoft Windows Server 2012 R2 Standard

 

My full inventory script is below:

 

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password xxxxxxxx

Connect-VIServer -Server YYY-vcenter1 -User administrator@vsphere.local -Password xxxxxxxx

function  Get-VMinventory {

 

   foreach ($vm in Get-VM | sort Name) {

     Write-Host $vm.Name 

     #All global info here 

     $GlobalHDDinfo = $vm | Get-HardDisk 

     $vNicInfo = $vm | Get-NetworkAdapter 

     $Snapshotinfo = $vm | Get-Snapshot 

     $Resourceinfo = $vm | Get-VMResourceConfiguration 

      

     #IPinfo 

     $IPs = $vm.Guest.IPAddress -join "," #$vm.Guest.IPAddres[0] <#it will take first ip#> 

  

     #FQDN - AD domain name 

     $OriginalHostName = $($vm.ExtensionData.Guest.Hostname -split '\.')[0] 

     $Domainname = $($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.' 

    

     #All hardisk individual capacity 

     $TotalHDDs = $vm.ProvisionedSpaceGB -as [int] 

    

     #All hardisk individual capacity 

      

     $HDDsGB = $($GlobalHDDinfo | select-object -ExpandProperty CapacityGB) -join " + " 

  

     #All HDD disk type,($vdisk.Capacity /1GB -as [int])} 

     $HDDtype = foreach ($HDDtype in $GlobalHDDinfo) {"{0}={1}GB"-f ($HDDtype.Name), ($HDDtype.StorageFormat)} 

     $HDDtypeResult = $HDDtype -join (", ") 

  

     #Associated Datastores 

     $datastore = $(Get-Datastore -vm $vm) -split ", " -join ", " 

    

     #Guest OS Internal HDD info 

     $internalHDDinfo = ($vm | get-VMGuest).ExtensionData.disk 

     $internalHDD = foreach ($vdisk in $internalHDDinfo) {"{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int])} 

     $internalHDDResult = $internalHDD -join (",") 

  

     #vCenter Server 

     $vCenter = $vm.ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")  

  

     #VM Macaddress 

     $Macaddress = $vNicInfo.MacAddress -join ", " 

  

     #Snapshot info 

     $snapshot = $Snapshotinfo.count 

    

     #Datacenter info 

     $datacenter = $vm | Get-Datacenter | Select-Object -ExpandProperty name 

  

     #Cluster info 

     $cluster = $vm | Get-Cluster | Select-Object -ExpandProperty name 

  

     #vNic Info 

     $vNics = foreach ($vNic in $VnicInfo) {"{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type)} 

     $vnic = $vNics -join (", ") 

  

     #Virtual Port group Info 

     $portgroup = $vNicInfo.NetworkName -join ", " 

  

     #RDM Disk Info 

     $RDMInfo = $GlobalHDDinfo | Where-Object {$_.DiskType -eq "RawPhysical"-or $_.DiskType -eq "RawVirtual"}  

     $RDMHDDs = foreach ($RDM in $RDMInfo) {"{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)} 

     $RDMs = $RDMHDDs -join (", ")

 

 

 

     #Custom Attributes 

     $Annotation = Get-Annotation -Entity $vm

     $Application = $Annotation | Where-Object {$_.Name -eq "Application"} | Select-Object -ExpandProperty value 

     $Owner = $Annotation | Where-Object {$_.Name -eq "Owner"} | Select-Object -ExpandProperty value 

     $Creationdate = $Annotation | Where-Object {$_.Name -eq "CreationDate"} | Select-Object -ExpandProperty value

     $Decommisiondate = $Annotation | Where-Object {$_.Name -eq "DecommisionDate"} | Select-Object -ExpandProperty value

     $Maintenance = $Annotation | Where-Object {$_.Name -eq "Maintenance Window"} | Select-Object -ExpandProperty value

     $Notes = $Annotation | Where-Object {$_.Name -eq "Notes"} | Select-Object -ExpandProperty value

         

     $Vmresult = New-Object PSObject  

     $Vmresult | add-member -MemberType NoteProperty -Name "VMName" -Value $vm.Name

     $Vmresult | add-member -MemberType NoteProperty -Name "datacenter" -Value $datacenter 

     $Vmresult | add-member -MemberType NoteProperty -Name "Cluster" -Value $cluster

     $Vmresult | add-member -MemberType NoteProperty -Name "Installed-OS" -Value $vm.guest.OSFullName 

     $Vmresult | add-member -MemberType NoteProperty -Name "Setting-OS" -Value $VM.ExtensionData.summary.config.guestfullname

     $Vmresult | add-member -MemberType NoteProperty -Name "IP Address" -Value $IPs

     $Vmresult | add-member -MemberType NoteProperty -Name "MacAddress" -Value $macaddress

     $Vmresult | add-member -MemberType NoteProperty -Name "vNic" -Value $vNic 

     $Vmresult | add-member -MemberType NoteProperty -Name "Portgroup" -Value $portgroup

     $Vmresult | add-member -MemberType NoteProperty -Name "PowerState" -Value $vm.PowerState 

     $Vmresult | add-member -MemberType NoteProperty -Name "Hostname" -Value $OriginalHostName 

     $Vmresult | add-member -MemberType NoteProperty -Name "Domain Name" -Value $Domainname 

     $Vmresult | add-member -MemberType NoteProperty -Name "vCPU" -Value $vm.NumCpu 

     $Vmresult | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.ExtensionData.config.hardware.NumCPU 

     $Vmresult | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.ExtensionData.config.hardware.NumCoresPerSocket 

     $Vmresult | add-member -MemberType NoteProperty -Name "RAM(GB)" -Value $vm.MemoryGB 

     $Vmresult | add-member -MemberType NoteProperty -Name "Total-HDD(GB)" -Value $TotalHDDs 

     $Vmresult | add-member -MemberType NoteProperty -Name "HDDsType" -Value $HDDtypeResult 

     $Vmresult | add-member -MemberType NoteProperty -Name "Datastore" -Value $datastore 

     $Vmresult | add-member -MemberType NoteProperty -Name "Partition/Size" -Value $internalHDDResult 

     $Vmresult | add-member -MemberType NoteProperty -Name "EsxiHost" -Value $VM.VMHost 

     $Vmresult | add-member -MemberType NoteProperty -Name "vCenter Server" -Value $vCenter 

     $Vmresult | add-member -MemberType NoteProperty -Name "Folder" -Value $vm.folder

  $Vmresult | add-member -MemberType NoteProperty -Name "Hardware Version" -Value $vm.Version

     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Version" -Value $vm.ExtensionData.Guest.ToolsVersion 

     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Version Status" -Value $vm.ExtensionData.Guest.ToolsVersionStatus 

     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Running Status" -Value $vm.ExtensionData.Guest.ToolsRunningStatus 

     $Vmresult | add-member -MemberType NoteProperty -Name "SnapShots" -Value $snapshot 

     $Vmresult | add-member -MemberType NoteProperty -Name "RDM" -Value $RDMs

  $Vmresult | add-member -MemberType NoteProperty -Name "Application" -Value $Application

     $Vmresult | add-member -MemberType NoteProperty -Name "Owner" -Value $Owner

  $Vmresult | add-member -MemberType NoteProperty -Name "Notes" -Value $Notes

  $Vmresult | add-member -MemberType NoteProperty -Name "Maintenance Window" -Value $Maintenance

  $Vmresult | add-member -MemberType NoteProperty -Name "CreationDate" -Value $Creationdate

  $Vmresult | add-member -MemberType NoteProperty -Name "DecommisionDate" -Value $Decommisiondate

     $Vmresult

   } 

}

$CurrentDate = Get-Date

$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hh-mm-ss')

Get-VMinventory | Sort VMname | Export-CSV -Path "C:\Reports\ESXi_Inventory_$CurrentDate.csv" -NoTypeInformation

invoke-vmscript requirments

$
0
0

What are the requirements for invoke-vmscript to work on a remote 2012R2 server? My script is getting stuck at the invoke-vmscript command

 

any idea?

PoweShell Q

$
0
0

For a change i am asking a powershell question here

 

 

 

$zone  = 'xxx.com'

$range = 'xx.xx.xx.1', 'xx.xx.xx.254'

 

function Addr2UInt($addr) {

  $bytes = $addr.GetAddressBytes()

  [array]::Reverse($bytes)

  [BitConverter]::ToUInt32($bytes, 0)

}

 

$addrFrom = Addr2UInt ([Net.IPAddress]::Parse($range[0]))

$addrTo   = Addr2UInt ([Net.IPAddress]::Parse($range[1]))

 

$date = (Get-Date).ToString('MMM-dd-yyyy-hh-mm-ss-tt')

 

Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer  | ? {

  $addr = Addr2UInt $_.RecordData.IPv4Address;

  $addrFrom -le $addr -and $addr -le $addrTo

}

 

 

 

on the sceen the o/p is as expected

 

HostName              RecordType Timestamp        TimeToLive  RecordData
--------              ---------- ---------        ---------- 

----------

 

 

 

 

Where RecordData shows me IP

 

But if i do

 

 

 

Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer  | ? {

  $addr = Addr2UInt $_.RecordData.IPv4Address;

  $addrFrom -le $addr -and $addr -le $addrTo

} |  Export-csv -path C:\temp\x-$date.csv -NoTypeInformation

 

i do not get the RecordData as below

RecordData
DnsServerResourceRecordA

 

Please  help on this.

Another quick question about a LucD inventory scripting technique

$
0
0

I've been working with brilliant nested ForEach loops thanks to LucD :

 

foreach ($dc in Get-Datacenter) {

        foreach ($cluster in Get-Cluster -Location $dc) {

            foreach ($esx in Get-VMHost -Location $cluster) {

                Get-VM -Location $esx

 

Walking down the tree is fantastic because this method collects the datacenter and cluster name for each VM as a byproduct of the scripting logic.  Unfortunately we have some VMs that aren't part of a cluster.  Is there a simple way to pick up these outliers?  I think I'd need to compare the output of the above with a simple Get-VM then += the delta to the original output.  But I'm a PowerShell novice and I'm struggling a little.  Has anyone already solved this issue?

New-Datastore on ESXi 6.0 Not working?

$
0
0

Got a strange one, I've been using this script for quite some time, not sure whats different on Esxi 6 U2:

 

I feed in a CSV for mass datastore creation:

 

CSV looks like:

DeviceNAA,DatastoreName

 

Script is:

$deviced = import-Csv "$path\FarmNAAID.csv"

$farmhosts = get-cluster $ESXFarmName | Get-VMHost | Select -First 1

 

Foreach ($dev in $deviced){

         Write-host "Creating Datastore" $dev.DatastoreName "on Primary Host -" $farmhosts ", device labeled " $dev.DeviceNAA

       $farmhosts | New-Datastore -Name $dev.DatastoreName -Path $dev.DeviceNAA -Vmfs -FileSystemVersion 5 -Confirm:$false

    }

 

Currently it kicks back " New-Datastore        Could not find the specified disk or the disk is already in use:<DeviceNAA ID Here>

 

No idea what has changed in the way of powercli on ESXi 6, but hopefully someone can shed some light? I have a ton of Datastores to add.

 

I'm runing Powercli 6.3 R1, and just for kicks I've tried on a slightly older version of PowerCLI 6, but no dice.

 

thanks!

Where did they hide the host count?

$
0
0

Trying to figure out how to get a count of the number of hosts connected to each datastore.  Can someone tell me where that value is hiding?


set VM Overrides for Keep VMDKs together sDRS cluster

$
0
0

Hi,

 

for VMs with storage/vDisks >1 TB we override the "Keep VMDKs together" policy with "No". This is usually done while deployment or expansion of a VM. For whatever reason these overrides get lost sometimes (there is KB about this http://kb.vmware.com/kb/2053792Storage DRS keeps VMDKs together and does not allocate to most optimal datastore , but AFAICS nobody here uses the C# client for theses settings any more).

 

I'm tired of setting theses overrides ever week again. So I want to create a powercli script that checks for VMs with > 1TB vDISKs (diskspace used for all vDisks) and create a VM override rule. I did not find anything how to set this with powercli, anyone has an idea or a quick example?

 

Thx!

Reserve Memory per VM or Resources Pool

$
0
0

If I want to reserve RAM to 3 VMs, is better to reserve memory in each VM or create a resource pool? I have enough resources in my host.

use foreach(), the output of export-csv was repeat for vmhost.

$
0
0

Hi Master,

 

I just encounter an issue which made me confused and not have a soluation till now , Anybody who could help me on it ? thanks!

 

 

Situation;

 

I want to get ESXi host Modules info via ESXCLI for powercli script. but output are still have repeat vmhostname, is there have modity for it , below is my orginal code.

 

#$cred = get-credential

$vCenter = "win2012c.demo.com"

$vmhosts = ( get-cluster -name "prod"  | get-vmhost )

Connect-VIserver -server $vCenter

$esxcli = @()

 

 

foreach( $vmhost in $vmhosts )

{

$esxcli += get-esxcli -vmhost $vmhost

 

$result = $EsxCli.software.vib.list() | where {$_.Name -match "mega"} | select Name,Version,Vendor,CreationDate,@{n="VMhost";e={$vmhost.name}}

 

}

 

$result |  export-csv -path c:\modules.csv -notype .

 

 

Modules.jpg

 

Attached is result. you can see it,   it contains repeat server name,     just I have there VMhost name  which are myesxi01,myesxi02 and myesxi03.

Error with ViewDBChk

$
0
0

Hello,

 

I want to delete VM using ViewDBChk inside Powershell script from Workstation.

 

This code :

$Session = New-PSSession -ComputerName $ViewBroker
Invoke-Command -Session $Session -ScriptBlock { Add-PSSnapin VMware.View.Broker }
Invoke-Command -Session $Session -ScriptBlock { ViewDBChk --removeMachine --machineName VMXXXXXX --desktopName PoolXXXXX --force --noErrorCheck }

gives me this error :

Error occurred during initialization of VM

Could not reserve enough space for object heap

 

When I use this code directly on Powershell window in View broker, I don't have error.

 

Do you know Why ?

Export/import Baseline from update manager 5.x to 6.1

$
0
0

Hi ,

 

We are trying to export/import VUM 5.1 baselines to VUM 6.0. We tried using the scripts provided in VMware blog but we are not able to get the result.

 

Scripts https://communities.vmware.com/docs/DOC-11973

Script https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.vsphere.update_manager.doc%2FGUID-FB9C8381-9D6C-4451-8CCF-99A14B552D59.html

 

Our existing environment has 3 VUM on 5.1 and about 50+ baselines. New environment is on 6.1.

 

When we try to run the script as per the above links ,we pass through till line 3 and then we get error as ExportImpotBaselines.ps1 is not a cmdlet. If we remove line 4 then we get Param is not a proper cmdlet.

 

Script -----------------------------------------------------------------------

$destinationServer = Connect-VIServer <ip_address_of_the_destination_server>

$sourceServer = Connect-VIServer <ip_address_of_the_source_server>

$baselines = Get-PatchBaseline MyBaseline -Server $sourceServer

ExportImportBaselines.ps1 $baselines $destinationServer

Param([VMware.VumAutomation.Types.Baseline[]] $baselines, [VMware.VimAutomation.Types.VIServer[]]$destinationServers)

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

 

We are using VMware Power CLI 6.3 which is having vSphere Update Manager PowerCLI integrated.

 

Are we missing some thing?  The above links is written for versions 5.1 we tried for exporting from 5.1 to 6.1 but failed.

 

Can some one help us ? Has any one used the above scripts for other VUM versions?

 

Regards,

mominn

 

 

Viewing all 9071 articles
Browse latest View live


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