Last active
December 5, 2015 08:25
-
-
Save PatrickTerlisten/829a7fcd299c530fc8b3 to your computer and use it in GitHub Desktop.
This script outputs a list of all VMs where VM inventory name and working directory name doesn't match.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Version 1 | |
#requires -PSSnapin VMware.VimAutomation. | |
function Get-VMWorkingDirMismatch { | |
<# | |
.SYNOPSIS | |
No parameters needed. Just execute the script. | |
.DESCRIPTION | |
This script outputs a list of all VMs where VM inventory name and working directory name doesn't match. | |
.EXAMPLE | |
Get-VMWorkingDirMismatch | |
Get a list of all VMs where inventory name and working dir doesn't match. | |
.NOTES | |
Author: Patrick Terlisten, [email protected], Twitter @PTerlisten | |
This script is provided "AS IS" with no warranty expressed or implied. Run at your own risk. | |
This work is licensed under a Creative Commons Attribution NonCommercial ShareAlike 4.0 | |
International License (https://creativecommons.org/licenses/by-nc-sa/4.0/). | |
.LINK | |
http://www.vcloudnine.de | |
#> | |
# Create empty hash table | |
$OutputTable = @() | |
# Get a list of all VMs | |
$AllVMs = Get-VM | |
try | |
{ | |
# Loop to process each VM and fill the $OutputTable hash table | |
ForEach ($VM in ($AllVMs | Get-View)) { | |
$Output = ''| Select-Object -Property VM, Path | |
$WorkingDirName = ((($VM.Summary.Config.VmPathName).Split(']')[1]).Split('/'))[0].TrimStart(' ') | |
$VMPath = ($VM.Summary.Config.VmPathName).Split('/')[0] | |
If ($VM.Name -ne $WorkingDirName) { | |
$Output.VM = $VM.Name | |
$Output.Path = $VMPath | |
$OutputTable += $Output | |
} | |
} | |
} | |
catch | |
{ | |
"Error was $_" | |
$line = $_.InvocationInfo.ScriptLineNumber | |
"Error was in Line $line" | |
} | |
finally | |
{ | |
# Output the filled hash table | |
If ($OutputTable.Length -eq 0) {Write-Host -Object 'No mismatched paths found!'} | |
else {$OutputTable} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment