Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Nakagaki Zsoldier

View GitHub Profile
@Zsoldier
Zsoldier / DeleteNSXTRouteFilter.sh
Created Jan 14, 2022
A way to forcefully delete a route advertisement filter in NSX-T. Use w/ extreme caution.
View DeleteNSXTRouteFilter.sh
echo -n Enter NSX Manager IP:
read nsxmgr
echo -n Enter NSX Manager admin password:
read -s secret
# The below curl command will display logical router id's and display names for those id's.
curl -k -u admin:$secret https://$nsxmgr/api/v1/logical-routers/ | awk -F ': ' '/"id"/{print substr($2,2, length($2)-3)} /"display_name"/{print substr($2,2, length($2)-3)}'
echo -n Enter target router id:
read routerid
@Zsoldier
Zsoldier / NewNSXTApplianceCerts.sh
Created Jan 14, 2022
Generate a CSR w/ SAN entries using NSX-T API's for your manager appliances, self-sign, and apply them.
View NewNSXTApplianceCerts.sh
# These values are unique to your environment.
# DO NOT USE this code if your NSX-T instance is managed by a service provider.
# You risk breaking your SLA/contracts/blahblahblah and yourself.
NSXMgr=IPorDNSNameofyourNSXManager
domainsuffix=zsoldier.com
org=zsoldiernet
orgunit=blog
country=US
state=GA
locality=ATL
@Zsoldier
Zsoldier / Add-NSXVMTags.ps1
Last active Aug 20, 2021
NSX-T 3.x+ VM/Virtual Machine Tag Management
View Add-NSXVMTags.ps1
#Requires -Module vmware.powercli
$Credential = Get-Credential
$skipcertcheck = $true
$AuthMethod = Basic
$NSXMgr=0.0.0.0
$apiendpoint = "/api/v1/fabric"
$base_url = ("https://" + $NSXMgr + $apiendpoint)
$tag = "Naka"
$scope = "NakaScope" # If scope not required, simply define as $null or ""
$vmnamefilter = "nakabuntu" # Not required. Will loop through all VM's otherwise.
@Zsoldier
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
$NSXMgr=NSXTManagerIPorDNSName
$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
Zsoldier / getnsxt0bgproutes.sh
Created Mar 24, 2021
Gets NSX-T BGP Route Table via curl and jq.
View getnsxt0bgproutes.sh
#Have not figured out how to have jq output an array for bash to loop through.
nsxt=DNSnameORIPAddressofNSXTManager
username=admin
password='superduperSecure!'
endpoint='policy/api/v1'
#Checks to see if you have jq installed.
if ! command -v jq &> /dev/null
then
echo "jq is needed for code for below code to work. Download or use brew/apt/packagemanager to install. https://stedolan.github.io/jq/"
exit
@Zsoldier
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
Zsoldier / run-diskspd.ps1
Created Mar 3, 2021
How to run several diskspd instances.
View run-diskspd.ps1
$testtimer=1800
$writepct=50
$blocksize='64k'
$threads=4
$outstandingio=16
$warmuptime=5
$filesize="10G"
$drives=@('D','E','F','G')
#$drives=@('E')
$diskspdpath = "C:\Users\Administrator\Downloads\DiskSpd\amd64\diskspd.exe"
@Zsoldier
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
Zsoldier / ClearNSXTDNSCache.sh
Last active Mar 15, 2021
Curl method to force clear NSX-T DNS cache.
View ClearNSXTDNSCache.sh
nsxt=iporDNSnameofNSXManager
username=admin
password=''
if ! command -v jq &> /dev/null
then
echo "jq is needed for code for below code to work. Download or use brew/apt/packagemanager to install. https://stedolan.github.io/jq/"
exit
fi
@Zsoldier
Zsoldier / Request-AzureJIT.ps1
Last active Sep 1, 2021
Requesting JIT access for Azure VM example.
View Request-AzureJIT.ps1
#Requires -Module az.accounts, az.security
# Change all below mandatory to $true if you'd like to force parameters.
# Otherwise, you can fill in variables w/ defaults or your choosing like below.
function Request-AZJIT {
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]
$AzureVMName = "nameofyourAzureVM",
[Parameter(Mandatory=$false)]