Skip to content

Instantly share code, notes, and snippets.

View lamw's full-sized avatar

William Lam lamw

View GitHub Profile
@lamw
lamw / gist:2a10d4941baf140f94d15f68d951c4c9
Last active September 9, 2020 09:10
List all Unassociated/Orphaned vSAN Objects using PowerCLI
$ClusterName = "Cluster-01"
$clusterView = Get-Cluster $ClusterName
$vmhost = ($clusterView | Get-VMHost) | select -First 1
$vsanClusterObjectSys = Get-VsanView -Id VsanObjectSystem-vsan-cluster-object-system
$results = (($vsanClusterObjectSys.VsanQueryObjectIdentities($clusterMoRef,$null,$null,$true,$true,$false)).Identities | where {$_.Vm -eq $null})
foreach ($result in $results) {
$jsonResult = ($vsanIntSys.GetVsanObjExtAttrs($result.Uuid)) | ConvertFrom-JSON
@lamw
lamw / gist:a744df89a5b8aab18c2b69af9399565b
Last active July 10, 2019 21:52
Add custom color to vSphere HTML5 UI Header/Footer in vSphere 6.7 Update 1
NEW_HEX_COLOR=632771
cp /usr/lib/vmware-vsphere-ui/plugin-packages/root-app/plugins/h5ngc.war /usr/lib/vmware-vsphere-ui/plugin-packages/root-app/plugins/h5ngc.war.bak
mkdir -p /root/TEST
cd /root/TEST
cp /usr/lib/vmware-vsphere-ui/plugin-packages/root-app/plugins/h5ngc.war .
unzip h5ngc.war
rm -f h5ngc.war
cat << EOF >> resources/css/vghetto-custom.css
.main-nav HEADER{
background-color:#${NEW_HEX_COLOR} !important; }
#!/usr/bin/env python
# VMware vSphere Python SDK
# Copyright (c) 2008-2013 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@lamw
lamw / check-latest-vsan-hcl-json.ps1
Last active December 1, 2017 14:24
PowerShell script to check for latest vSAN HCL JSON file
$vsanJsonURL = "https://partnerweb.vmware.com/service/vsan/all.json"
$currentJsonFile = "current-vsan-hcl.json"
$latestJsonFile = "latest-vsan-hcl.json"
if(-Not (Test-Path $currentJsonFile)) {
# Never ran before, download current JSON and the next time
# the script run, it will have something to compare to
$results = Invoke-WebRequest -Uri $vsanJsonURL
$results.Content | Out-File -FilePath $currentJsonFile
} else {
@lamw
lamw / gist:8fedd19e27ff9276169e1bdd5404ca8c
Created October 15, 2017 22:48
Powershell snippet to help extract the SSL Thumbprint (SHA256) of a remote system
# Modification from https://gist.github.com/lamw/988e4599c0f88d9fc25c9f2af8b72c92
# Thanks to https://stackoverflow.com/a/22251597 for SHA256 details
Function Get-SSLThumbprint256 {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
@lamw
lamw / gist:d87946a1c103062f1c6a817444479dd2
Created September 22, 2017 03:06
PowerShell function to retrieve YouTube video stats
Function Get-YouTubeStat {
param(
[Parameter(Mandatory=$true)][String]$VideoId
)
# Replace APIKey with your Google API key and ensure YouTube API is enabled
$stats = irm "https://www.googleapis.com/youtube/v3/videos?id=$VideoId&key=$APIKey&part=statistics"
$stats.items.statistics | Select ViewCount,LikeCount
}
Get-YouTubeStat -VideoId Ek6FArKyMBc
@lamw
lamw / gist:8bbb3e753f2a44eef5f6de354d1c98dc
Created July 10, 2017 16:39
PowerCLI sample using vSphere API to create new VMkernel interface & assigning to existing default Netstack (vMotion)
$esxi_name = "192.168.30.10"
$portgroup_name = "vMotion"
$hostsystem = (Get-VMHost -Name $esxi_name).ExtensionData
$networkSystem = Get-View $hostsystem.ConfigManager.NetworkSystem
$nic = New-Object VMware.Vim.HostVirtualNicSpec
$ip = New-Object VMware.Vim.HostIpConfig
$ip.Dhcp = $false
$ip.IpAddress = "192.168.1.10"
$ip.SubnetMask = "255.255.255.0"
@lamw
lamw / gist:5aefdfb846075252efce1b54e4a6d0a0
Created June 29, 2017 14:31
Example of using vSphere GuestOps API via PowerCLI
$guestOpsMgr = (Get-View $global:DefaultVIServer.ExtensionData.Content.guestOperationsManager)
$authMgr = (Get-View $guestOpsMgr.AuthManager)
$vm = (Get-VM -Name MacOSX-10.11).ExtensionData.MoRef
$credential = New-Object VMware.Vim.NamePasswordAuthentication
$credential.InteractiveSession = $false
$credential.Username = "lamw"
$credential.Password = "vmware123"
$authMgr.ValidateCredentialsInGuest($vm,$credential)
# Author: William Lam
# Blog: www.virtuallyghetto.com
# Reference: http://www.virtuallyghetto.com/2016/07/how-to-automate-vsphere-mob-operations-using-powershell.html
# Example of calling QuerySyncingVsanObjects() (http://pubs.vmware.com/vsphere-60/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.host.VsanInternalSystem.html) w/PowerCLI + vSphere MOB ###
Function Get-VsanObjectStatus {
param(
[Parameter(
Position=0,
Mandatory=$true,
@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