Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Nakagaki Zsoldier

View GitHub Profile
@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 Mar 1, 2021
Requesting JIT access for Azure VM example.
View Request-AzureJIT.ps1
#Requires -Module az.accounts, az.security
function Request-AZJIT {
[CmdletBinding()]
param (
$AzureVMName = "nameofyourAzureVM",
$SubscriptionID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx",
$AllowedSourceIP = (Invoke-Restmethod http://ipinfo.io/json).ip,
$TimeRequested = (get-date).AddHours(3),
$PortRequested = 22,
$JITPolicyName = "default"
@Zsoldier
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
Zsoldier / vSANStoragePolicyApplytoVMsExample.ps1
Created Dec 16, 2020
Change VSAN storage policy on one or more VMs
View vSANStoragePolicyApplytoVMsExample.ps1
#See storage policies available
Get-SpbmStoragePolicy
#Define storage policy you want to apply
$storagepolicyname = "RAID-1 FTT-1"
#Capture Storage policy object.
$storagepolicies = Get-SpbmStoragePolicy
$targetstoragepolicy = ($storagepolicies | where-object {$_.name -eq $storagepolicyname})
@Zsoldier
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
$NSXMgr=IPorDNSName
$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"