Skip to content

Instantly share code, notes, and snippets.

View Zsoldier's full-sized avatar

Chris Nakagaki Zsoldier

View GitHub Profile
@Zsoldier
Zsoldier / Delete-HCXvCenterPlugin.ps1
Created June 29, 2023 06:56
Deletes HCX related extension from vcenter
connect-viserver $vcenter -Credential $creds
$view = get-view extensionmanager
$hcxextensions = $view.extensionlist | where {$_.key -match "com.vmware.hybridity"}
foreach ($ext in $hcxextensions){
$view.UnregisterExtension($ext.key)
}
@Zsoldier
Zsoldier / osx-pw-policies.sh
Created November 15, 2022 16:22 — forked from Freccia/osx-pw-policies.sh
Sets Os X Password Policies
#!/bin/sh
###################################################################################
## Create a pwpolicy XML file based upon variables and options included below.
## Policy is applied and then file gets deleted.
## Use "sudo pwpolicy -u <user> -getaccountpolicies"
## to see it, and "sudo pwpolicy -u <user> -clearaccountpolicies" to clear it.
##
## Tested on: OS X 10.10 10.11 10.12
####################################################################################
@Zsoldier
Zsoldier / SkipQuickStart.ps1
Created October 11, 2022 17:46
Demonstrates creating a cluster w/ quickstart disabled or skipping quickstart on an already deployed cluster.
#Creates a simple cluster object in vCenter Inventory with quickstart disabled.
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.InHciWorkflow = $false #Disables QuickStart
$_this = Get-View -Id 'Folder-group-h5'
$_this.CreateClusterEx($name, $spec)
#Disables QuickStart on an existing cluster
$Cluster = Get-Cluster "SomeCrazyName"
$Cluster.ExtensionData.AbandonHciWorkflow()
@Zsoldier
Zsoldier / Delete-NSXTOrphanedPorts.ps1
Created October 7, 2022 01:08
Automated Method to delete orphaned ports.
$NSXMgr = Read-Host "Enter NSX Manager IP or DNS name:"
$Creds = Get-Credential -Message "Enter NSX username and password"
$PortData = @()
$Segments = Invoke-RestMethod -Authentication Basic -Credential $creds -Method Get -Uri "https://$NSXMgr/policy/api/v1/infra/segments/" -SkipCertificateCheck:$true
Foreach ($Segment in $Segments.results){
$Ports = Invoke-RestMethod -Authentication Basic -Credential $creds -Method Get -Uri "https://$NSXMgr/policy/api/v1/infra/segments/$($Segment.id)/ports/" -SkipCertificateCheck:$true
$PortData += $Ports.results
While (!([string]::IsNullOrEmpty($Ports.cursor))){
@Zsoldier
Zsoldier / DeleteNSXTRouteFilter.sh
Created January 14, 2022 21:06
A way to forcefully delete a route advertisement filter in NSX-T. Use w/ extreme caution.
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
Last active April 12, 2023 15:40
Generate a CSR w/ SAN entries using NSX-T API's for your manager appliances, self-sign, and apply them.
# 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.
# This script works when running from a MacOS zsh Terminal Session. YMMV w/ Linux Terminals
NSXMgr=IPorDNSNameofyourNSXManager
domainsuffix=zsoldier.com
org=zsoldiernet
orgunit=blog
country=US
state=GA
@Zsoldier
Zsoldier / Add-NSXVMTags.ps1
Last active June 27, 2024 22:42
NSX-T 3.x+ VM/Virtual Machine Tag Management
#Requires -Module vmware.powercli
$VCCredential = Get-Credential
$NSXCredential = Get-Credential
$skipcertcheck = $true
$AuthMethod = Basic"
$VCServer="0.0.0.0"
$NSXMgr=0.0.0.0
$apiendpoint = "/api/v1/fabric"
$base_url = ("https://" + $NSXMgr + $apiendpoint)
$tag = "Naka"
@Zsoldier
Zsoldier / Get-NSXTVirtualMachineData.ps1
Created July 12, 2021 15:44
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.
$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 March 24, 2021 14:51
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.
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 March 10, 2021 03:00
Get BGP route table information from NSX-T T0.
$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/"