Skip to content

Instantly share code, notes, and snippets.

View lamw's full-sized avatar

William Lam lamw

View GitHub Profile
####### PS Script (test2.ps1)
if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) {
. "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
}
$vcserver = "172.30.0.112"
$vcusername = "administrator@vghetto.local"
$vcpassword = "VMware1!"
@lamw
lamw / gist:cbd128eb4f8e3713a9d6
Created September 30, 2015 16:40
Using PowerCLI to display which vCenter Server the ESXi host is currently being managed by
$esxiserver = "192.168.1.200"
$esxiusername = "root"
$esxipassword = "vmware123"
Connect-VIServer -Server $esxiserver -User $esxiusername -Password $esxipassword -WarningAction SilentlyContinue
$vihost = Get-View -Server $esxiserver -ViewType HostSystem -Property Name, Summary
Write-host "`nESXi Host: " $vihost.Name
Write-Host "vCenter Server: " $vihost.Summary.ManagementServerIp
@lamw
lamw / getDrsRules.ps1
Created November 20, 2015 19:23
Listing all vSphere DRS Rules that have been defined for a VM
$clusterName = "VSAN-Cluster"
$cluster = Get-Cluster -Name $clusterName
$vms = Get-View ($cluster| Get-VM)
$cluster_view = Get-View ($cluster)
foreach ($vm in $vms) {
# Using new vSphere 6.0 API (http://www.virtuallyghetto.com/2015/02/handy-new-vsphere-6-0-apis-to-be-aware-of.html)
$cluster_view.FindRulesForVm($vm.MoRef)
}
@lamw
lamw / keybase.md
Created February 5, 2016 17:15
Verifying myself on Keybase.io

Keybase proof

I hereby claim:

  • I am lamw on github.
  • I am lamw (https://keybase.io/lamw) on keybase.
  • I have a public key whose fingerprint is E88C 6F19 C677 D636 B010 D47B 5106 881E 8111 94BD

To claim this, I am signing this object:

@lamw
lamw / gist:86791da8fc548762b142
Created February 8, 2016 15:30
Examples of extracting SSL Certificate Thumbprint for *Nix & Windows
##### *Nix using openssl (http://www.virtuallyghetto.com/2012/04/extracting-ssl-thumbprint-from-esxi.html)
echo -n | openssl s_client -connect 192.168.1.200:443 2>/dev/null | openssl x509 -noout -fingerprint -sha1
SHA1 Fingerprint=AF:3F:70:E6:78:50:41:76:F0:E0:55:78:C0:77:49:FB:69:36:93:6C
##### Windows using PowerShell Option #1 (https://communities.vmware.com/thread/501913?start=0&tstart=0)
Function Test-WebServerSSL {
# Function original location: http://en-us.sysadmins.lv/Lists/Posts/Post.aspx?List=332991f0-bfed-4143-9eea-f521167d287c&ID=60
@lamw
lamw / gist:c6eb8b5a7229c807bd1b
Created February 18, 2016 16:24
Retrieve ESXi Major / Update version number using ESXCLI
$esxcli = Get-EsxCli
### To retrieve Major/Update version number of ESXi via ESXCLI
PS C:\Users\lamw\Desktop> $esxcli.system.version.get().version + " Update" + $esxcli.system.version.get().update
6.0.0 Update1
### To retrieve all version information from ESXi via ESXCLI
PS C:\Users\lamw\Desktop> $esxcli.system.version.get()
@lamw
lamw / vcsa-embed.json
Created April 4, 2016 19:15
Example govc import.ova spec for VCSA 6.x Embedded deployment
{
"Deployment": "tiny",
"DiskProvisioning": "thin",
"IPAllocationPolicy": "dhcpPolicy",
"IPProtocol": "IPv4",
"InjectOvfEnv": true,
"Name": "VCSA-60u2-Embedded",
"PowerOn": true,
"PropertyMapping": [
{
@lamw
lamw / Get-SSLThumbprint.ps1
Created May 22, 2016 13:37
Powershell snippet to help extract the SSL Thumbprint (SHA1) of a remote system
Function Get-SSLThumbprint {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[Alias('FullName')]
[String]$URL
@lamw
lamw / gist:a397b85b2aa27b96259d2c3a8a89e701
Created October 1, 2016 19:16
Extract Service Tag from ESXi hosts using vSphere API
Connect-VIServer -Server 192.168.1.51 -User administrator@vghetto.local -password VMware1! | Out-Null
$vmhosts = Get-VMHost
foreach ($vmhost in $vmhosts) {
$vmhostName = $vmhost.Name
$vmhostServiceTag = "N/A"
$otherInfos = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo
foreach ($info in $otherInfos) {
@lamw
lamw / gist:f25820bccdd858033fa1f3bf0fcc5981
Created November 25, 2016 17:03
Installing OVFTool 4.2 within a Photon Docker Container
FROM photon
RUN tdnf -y install tar gzip sed gawk ncurses-compat
ADD VMware-ovftool-4.2.0-4586971-lin.x86_64.bundle /tmp/
RUN chmod +x /tmp/VMware-ovftool-4.2.0-4586971-lin.x86_64.bundle
RUN echo -e "/w00t\n" >> /tmp/answer
RUN /tmp/VMware-ovftool-4.2.0-4586971-lin.x86_64.bundle --eulas-agreed --required --console < /tmp/answer