Skip to content

Instantly share code, notes, and snippets.


Chris Nakagaki Zsoldier

View GitHub Profile
Zsoldier / Get-NSXTVirtualMachineData.ps1
Created Jul 12, 2021
Someone was looking for a way to find 'Tagless' NSX-T VMs. Seems like the NSX-T realized state endpoint was the way to go.
View Get-NSXTVirtualMachineData.ps1
$Credential = Get-Credential
$skipcertcheck = $true
$AuthMethod = Basic
$policyapi = "/policy/api/v1"
$base_url = ("https://" + $NSXMgr + $policyapi)
$endpoint = "/infra/realized-state/virtual-machines"
$Data = Invoke-restmethod -Uri ($base_url + $EndPoint) -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
Zsoldier /
Created Mar 24, 2021
Gets NSX-T BGP Route Table via curl and jq.
#Have not figured out how to have jq output an array for bash to loop through.
#Checks to see if you have jq installed.
if ! command -v jq &> /dev/null
echo "jq is needed for code for below code to work. Download or use brew/apt/packagemanager to install."
Zsoldier / Get-NSXT0BGPRouteTable.ps1
Created Mar 10, 2021
Get BGP route table information from NSX-T T0.
View Get-NSXT0BGPRouteTable.ps1
$NSXMgr = Read-Host "Please provide NSX-T DNS name or IP address."
$Credential = Get-Credential -Message "Please provide NSX-T username and password."
$skipcertcheck = $true
$AuthMethod = Basic
$policyapi = "/policy/api/v1"
$base_url = ("https://" + $NSXMgr + $policyapi)
$endpoint = "/infra/tier-0s/"
Zsoldier / run-diskspd.ps1
Created Mar 3, 2021
How to run several diskspd instances.
View run-diskspd.ps1
$diskspdpath = "C:\Users\Administrator\Downloads\DiskSpd\amd64\diskspd.exe"
Zsoldier / Clear-NSXTDNSCache.ps1
Last active Feb 22, 2021
Clears NSX-T DNS Service cache
View Clear-NSXTDNSCache.ps1
#Clear NSX-T DNS Cache
$creds = Get-Credential -Message "Provide NSX-T username and password"
$HostnameorIP = Read-Host "Provide IP or hostname for NSX-T Manager"
$DNSForwarders = Invoke-restmethod -Uri "https://$HostnameorIP/api/v1/dns/forwarders" -Method Get -Credential $creds -Authentication:Basic -SkipCertificateCheck:$true
$DNSForwarders.results | Select id, listenerip, display_name
#Copy the id value from the DNS forwarder you would like to clear cache on and place into $id variable below.
#$id=$DNSForwarders.results[0].id # < Works against first return. If you have more than one NSX-T DNS Forwarder, you'll need to select different record.
$id='id value provided by above'
Zsoldier /
Last active Mar 15, 2021
Curl method to force clear NSX-T DNS cache.
if ! command -v jq &> /dev/null
echo "jq is needed for code for below code to work. Download or use brew/apt/packagemanager to install."
Zsoldier / Request-AzureJIT.ps1
Last active Mar 1, 2021
Requesting JIT access for Azure VM example.
View Request-AzureJIT.ps1
#Requires -Module az.accounts,
function Request-AZJIT {
param (
$AzureVMName = "nameofyourAzureVM",
$SubscriptionID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx",
$AllowedSourceIP = (Invoke-Restmethod,
$TimeRequested = (get-date).AddHours(3),
$PortRequested = 22,
$JITPolicyName = "default"
Zsoldier / get-esxipcideviceinfo.ps1
Last active Jan 14, 2021
PowerCLI: Getting HCL DID, VID, and SVID information.
View get-esxipcideviceinfo.ps1
#Requires -Modules vmware.powercli
$esxihost = "DNSorIPofESXihost"
$vmhost = get-vmhost $esxihost
$vmhostcli = $vmhost | get-esxcli -v2
$pcidevices = $vmhostcli.hardware.pci.list.invoke()
#$pcidevices | where {$_.vendorname -match "Mellanox"}
$HCLData = @()
Foreach ($pcidevice in $pcidevices){
Zsoldier / vSANStoragePolicyApplytoVMsExample.ps1
Created Dec 16, 2020
Change VSAN storage policy on one or more VMs
View vSANStoragePolicyApplytoVMsExample.ps1
#See storage policies available
#Define storage policy you want to apply
$storagepolicyname = "RAID-1 FTT-1"
#Capture Storage policy object.
$storagepolicies = Get-SpbmStoragePolicy
$targetstoragepolicy = ($storagepolicies | where-object {$ -eq $storagepolicyname})
Zsoldier / Set-NSXTSegmentProfiles.ps1
Last active Jul 9, 2021
Example on how to change segment discovery, qos, and security profiles enmasse.
View Set-NSXTSegmentProfiles.ps1
#Change Segment Profiles
$Credential = Get-Credential
$skipcertcheck = $true
$AuthMethod = Basic
$policyapi = "/policy/api/v1"
$base_url = ("https://" + $NSXMgr + $policyapi)
#Change these to the name of the various profiles you want to remap all your segments to.
$TargetIPDPName = "default-ip-discovery-profile"