Skip to content

Instantly share code, notes, and snippets.

View Zsoldier's full-sized avatar

Chris Nakagaki Zsoldier

View GitHub Profile
@Zsoldier
Zsoldier / run-diskspd.ps1
Created March 3, 2021 14:18
How to run several diskspd instances.
$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 August 24, 2022 16:23
Clears NSX-T DNS Service cache
#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 March 15, 2021 14:24
Curl method to force clear NSX-T DNS cache.
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 September 1, 2021 15:09
Requesting JIT access for Azure VM example.
#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)]
@Zsoldier
Zsoldier / get-esxipcideviceinfo.ps1
Last active January 14, 2021 17:43
PowerCLI: Getting HCL DID, VID, and SVID information.
#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 December 16, 2020 19:03
Change VSAN storage policy on one or more VMs
#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 July 9, 2021 18:57
Example on how to change segment discovery, qos, and security profiles enmasse.
#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"
@Zsoldier
Zsoldier / delete-routeadvertisementrule.ps1
Created May 22, 2020 22:25
Example on how to call NSX-T Rest API via powershell to delete a route advertisement rule associated w/ a T1.
$NSXMgr=”IPorDNSName”
$Credential = Get-Credential #Must be Enterprise Admin role. Typically “admin”
$skipcertcheck = $true
$AuthMethod = “Basic”
$TargetRouterName = “LeeroyJenkinsT1”
#To get target logical router id
$lrdata = Invoke-restmethod -Uri “https://$($NSXMgr)/api/v1/logical-routers” -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
$routerid = ($lrdata.results | Where-Object {$_.display_name -eq $TargetRouterName}).id
# Grab VM object from HCX (Cannot be from vCenter)
$vm = Get-HCXVM -Name "NameofVM"
# If you have multiple sources or destination, you would need to augment with parameters such as name, server(hcxserver), and/or id.
$sourceSite = Get-HCXSite -Source
$targetSite = Get-HCXSite -Destination
# Source and target networks assume just one network adapter.
# For more than one adapter, you would need to loop through each source adapter and add to $NetworkMapping array.
$sourceNetwork = $vm.Network[0]
@Zsoldier
Zsoldier / Get-NSXESGFirewallRuleReport.ps1
Created April 25, 2020 03:40
Basically a way to pull the table you see in the interface in case you need to share config w/ someone.
#Requires -Module PowerCLI,PowerNSX
$ESG = Get-NsxEdge -Name "BobLoblaw"
$ESGFW = $ESG | get-NSXEdgeFirewall
$ESGFWRules = Get-NSXEdgeFirewallRule -EdgeFirewall $ESGFW
$CustomReport = @()
$i = 1
Foreach ($Rule in $ESGFWRules)
{
$NewObject = "" | Select-Object RuleNo, RuleID, RuleName, Source, Destination, Description, ServicePorts, Action, appliedTo, datacentername