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 / 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 / Get-NSXFirewallReport.ps1
Created January 19, 2018 20:06
NSX Firewall Rule Report
<# Uncomment if you'd like to use. These are assumed and needed for custom report to work. Must be connected to vCenter and NSXMgr.
Import-Module vmware.powercli,powernsx
$Creds = Get-Credential -Message "Provide vCenter Admin credentials"
$vCenterNameorIP = Read-Host "Provide name or IP of vCenter"
Connect-VIServer $vCenterNameorIP -Credential $Creds
Connect-NSXServer -vCenterServer $vCenterNameorIP -Credential $Creds
#>
$DFWRules = Get-NSXFirewallRule
$CustomReport = @()
@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 / 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 / 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 / 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 / Add-NSXVMTags.ps1
Last active August 20, 2021 14:19
NSX-T 3.x+ VM/Virtual Machine Tag Management
#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.