Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 236824

Re: Pulling information from /usr/lib/vmware/vm-support/bin/swfw.sh

$
0
0

Luc,

 

Worked on a method for getting this done last night. Here is the function I came up with (how do you get syntax highlighting and spacing to look right in the communities for powershell??)

 

function get-swfw ($vmhost, $cluster, $Plink, $Password){

  $User = "root"

  $Report = @()

 

  if ($VMhost -ne $null){

  $vmhosts = $VMhost

  }

  if ($cluster -ne $null){

  $vmhosts = $cluster | Get-VMHost

  }

 

  # Start SSH

  $vmhosts | Get-VMHostService | where {$_.Key -like "*SSH*"} | start-VMHostService -Confirm:$false | out-null

  Sleep 10

 

 

  foreach ($VMHost in $VMHosts){

  #Define Regexes

  $PrimaryKeyValueRegex = [regex]"(\S+)\.InstanceID=(.+)"

  $PropertyKeyValueRegex = [regex]"(\S+.)\s=\s(.+)"

  $instanceIDs = @()

 

  # Get SWFW Info

  $SWFWInfo = '/usr/lib/vmware/vm-support/bin/swfw.sh'

  $remoteCommand = '"' + $SWFWInfo + '"'

  $command = $plink + " " + "-batch -pw " + "'" + $Password + "'" + " -auto_store_key_in_cache" + " " + $User + "@" + $vmhost.name + " " + $remoteCommand

  $SWFWOutput = Invoke-Expression -command $command

 

  # Parse SWFW Info

  foreach ($item in $SWFWOutput){

  if ($item -like "*.InstanceID=*"){

  $InstanceIDs += [array]::IndexOf($SWFWOutput,$item)

  }

  }

  foreach ($item in $instanceIDs){

  $number = $item + 1

  $object = New-Object –TypeName PSObject

 

  Do {

  $Key = $PropertyKeyValueRegex.Match($SWFWOutput[$number]).Groups[1].Value

  $Value = $PropertyKeyValueRegex.Match($SWFWOutput[$number]).Groups[2].Value

  $object | Add-Member –MemberType NoteProperty –Name $Key –Value $Value

  $number = $number + 1

  }

  Until ($SWFWOutput[$number].length -eq 0)

  $Report += $object

  }

  }

 

  # Stop SSH

  $vmhosts | Get-VMHostService | where {$_.Key -like "*SSH*"} | stop-VMHostService -Confirm:$false | out-null

  return $Report

}

 

 

get-swfw -vmhost (get-vmhost (Read-Host "VMhost Name")) -Plink $Plink -Password (Read-Host "Password") | ft


Viewing all articles
Browse latest Browse all 236824

Trending Articles



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