Skip to content

Instantly share code, notes, and snippets.

@NamedJason
NamedJason / Make-VDSPGs.ps1
Last active December 1, 2015 16:33
Powershell Script to create Distributed Port Groups based on an input CSV
<#
.SYNOPSIS
Creates Distributed Port Groups from input file, skipping correctly configured existing port groups. Optionally, reconfigures existing Port Groups to match the specifications in the file.
.EXAMPLE
Get-VDSPGs.ps1 -vdSwitch SAC-Production -ConfigFile E:\Temp\DVS.csv -fixErrors
This command will read the input file at E:\Temp\DVS.csv for all entries pertaining to the SAC-Production Distribtued vSwitch and will add any new Port Groups and will reconfigure any existing Port Groups that have had configuration drift.
.NOTES
Input File: Needs these columns: Name, VLAN, PortBinding, DVS
Author: Jason Coleman
@NamedJason
NamedJason / Find-Orphans.ps1
Last active June 10, 2024 15:59
Finds Orphaned VMDK Files
# Powershell script to discover VMDK files that are not referenced in any VM's VMX file.
# Warning - I've heard reports that this doesn't work on some versions of ESXi and have no had time to troubleshoot/test it.
# Also detects VMDKs from machines that need snapshot consolidation (from differentials that exist but are not part of the tree).
# Author: HJA van Bokhoven
# Modifications: LucD
function LoadSnapin{
param($PSSnapinName)
if (!(Get-PSSnapin | where {$_.Name -eq $PSSnapinName})){
Add-pssnapin -name $PSSnapinName
@NamedJason
NamedJason / Change-Passwords.ps1
Last active December 1, 2015 16:21
Change many ESXi Host root Passwords
#Description: Changes ESXi Host root passwords for all specified ESXi Servers
#Author: Jason Coleman
#Website: http://virtuallyjason.blogspot.com/
#Reference: http://virtuallyjason.blogspot.com/2015/10/batch-changing-esxi-root-passwords.html
#Usage: change-passwords.ps1 -oldPass <old root password> -passString <new root password>
param
(
$passString = "StrongPassword" + '<_<">_>',
$oldPass = "WeakPassword",
@NamedJason
NamedJason / DVS.csv
Last active October 26, 2015 14:38
Example CSV for the Make Distributed Switch Port Groups Script
Name VLAN PortBinding DVS
VL1-NetMgmt 1 Ephemeral SAC-Production
VL2-Servers 2 Ephemeral Production
VL3-VDI 3 Ephemeral SF-Production
@NamedJason
NamedJason / ThisIsMyBoomstick.ps1
Created November 9, 2015 15:53
Generates VMKFSTOOLS commands to rename and then delete orphaned VMDK files.
<#
.SYNOPSIS
Takes an array of file names (output from something like RV Tools) that are zombie VMDK files. Outputs VMKFSTOOLS commands to rename the files and to delete the files
.EXAMPLE
ThisIsmyBoomStick.ps1 -zombies E:\Temp\RV-Out.csv -outRename E:\Temp\RenameCommands.txt -outDelete E:\Temp\DeleteCommands.txt
This command will read the E:\Temp\RV-Out.csv input file, which can be the raw output from the RVTools vHealth tab, parse through it for Zombie VMDK lines, and generate rename and delete VMKFSTOOLS commands for those identified files.
.NOTES
The input file should be the output from the vHealth tab of the RVTools application. It expects a CSV with 2 columns: Name and Message. The message column must include the word Zombie and the Name column must be in the "[LUN] Folder/File.vmdk" syntax.
#>
@NamedJason
NamedJason / Rename-Local.ps1
Last active December 1, 2015 16:03
Renames local datastores on an ESXi host based on the hostname to which the datastore is local.
# Renames local datastores on ESXi hosts to use the hostname plus a specified suffix.
# Usage: Rename-Local.ps1 -cluster <Cluster name> -suffix <Datastore Suffix>
# Website: http://virtuallyjason.blogspot.com/
# Reference: http://virtuallyjason.blogspot.com/2015/12/renaming-esxi-host-local-datastores-by.html
# Original script by VMNick0 at http://www.pcli.me/?p=25
[cmdletbinding(SupportsShouldProcess=$True)]
param(
$cluster = "sac-cluster",
$suffix = "-local"
)
@NamedJason
NamedJason / Microsoft.PowerShell_profile.ps1
Created December 9, 2015 19:19
PowerShell Profile for Multiple vCenters
set-location E:\Scripts
$Shell = $Host.UI.RawUI
$size = $Shell.WindowSize
$size.width=80
$size.height=25
$Shell.WindowSize = $size
$size = $Shell.BufferSize
$size.width=80
$size.height=5000
$Shell.BufferSize = $size
@NamedJason
NamedJason / get-brocadeAliases.ps1
Created May 30, 2017 22:22
Get a list of all Aliases from the specified Brocade Switch, then output a list of which of those Aliases correspond to currently active WWNs
#Get a list of all Aliases from the specified Brocade Switch, then output a list of which of those Aliases correspond to currently active WWNs
#The -ReportAll switch will spit out a list of ALL discovered Aliases instead of just the active ones
param
(
$user = "admin",
$switch,
$password,
[switch]$reportAll
)
if ($plinkAliases = plink $user@$switch -pw $password 'alishow'){
$items = 1..3
$i = 1
foreach ($item in $items){
write-progress -id 1 -activity "Parent Progress Bar" -status "Iteration $item" -percentComplete ($i++ / $items.count * 100)
$j = 1
foreach ($child in $items){
write-progress -parentId 1 -activity "Child Progress Bar" -status "Iteration $item`.$child" -percentComplete ($j++ / $items.count * 100)
Start-sleep 1
}
}
<#
.SYNOPSIS Datastore Functions
.DESCRIPTION A collection of functions to manipulate datastore Mount + Attach status
.EXAMPLE Get-Datastore | Get-DatastoreMountInfo | Sort Datastore, VMHost | FT -AutoSize
.EXAMPLE Get-Datastore IX2ISCSI01 | Unmount-Datastore
.EXAMPLE Get-Datastore IX2ISCSI01 | Get-DatastoreMountInfo | Sort Datastore, VMHost | FT -AutoSize
.EXAMPLE Get-Datastore IX2iSCSI01 | Mount-Datastore
.EXAMPLE Get-Datastore IX2iSCSI01 | Get-DatastoreMountInfo | Sort Datastore, VMHost | FT -AutoSize
.EXAMPLE Get-Datastore IX2iSCSI01 | Detach-Datastore
.EXAMPLE Get-Datastore IX2iSCSI01 | Get-DatastoreMountInfo | Sort Datastore, VMHost | FT -AutoSize