Skip to content

Commit 8ba299e

Browse files
committed
Add fn for vSphere object type info mining, rename module updater
1 parent 27bdcb4 commit 8ba299e

File tree

3 files changed

+66
-17
lines changed

3 files changed

+66
-17
lines changed

vNugglets.Utility/vNugglets.Utility.psd1

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Matt Boren
55
#
6-
# Generated on: 6/18/2017
6+
# Generated on: 1/19/2023
77
#
88

99
@{
@@ -12,7 +12,7 @@
1212
RootModule = 'vNuggletsUtilityMod.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.2.0'
15+
ModuleVersion = '1.3.0'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -27,25 +27,25 @@ Author = 'Matt Boren'
2727
CompanyName = 'vNugglets.com'
2828

2929
# Copyright statement for this module
30-
Copyright = 'MIT License'
30+
Copyright = 'Apache 2.0 License'
3131

3232
# Description of the functionality provided by this module
3333
Description = 'Module with the super useful functions that were previously scattered about the web by the vNugglets team (particularly, at vNugglets.com)'
3434

35-
# Minimum version of the Windows PowerShell engine required by this module
36-
PowerShellVersion = '4.0'
35+
# Minimum version of the PowerShell engine required by this module
36+
PowerShellVersion = '5.0'
3737

38-
# Name of the Windows PowerShell host required by this module
38+
# Name of the PowerShell host required by this module
3939
# PowerShellHostName = ''
4040

41-
# Minimum version of the Windows PowerShell host required by this module
41+
# Minimum version of the PowerShell host required by this module
4242
# PowerShellHostVersion = ''
4343

4444
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
4545
# DotNetFrameworkVersion = ''
4646

4747
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48-
# CLRVersion = ''
48+
# ClrVersion = ''
4949

5050
# Processor architecture (None, X86, Amd64) required by this module
5151
# ProcessorArchitecture = ''
@@ -71,11 +71,12 @@ NestedModules = @('vNuggletsUtilityMod_functions.ps1',
7171

7272
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
7373
FunctionsToExport = 'Connect-VNVIServer', 'Copy-VNVIRole', 'Disconnect-VNVIServer',
74-
'Find-VNVMWithDuplicateMACAddress', 'Get-VNNetworkClusterInfo',
75-
'Get-VNUplinkNicForVM', 'Get-VNVMByAddress', 'Get-VNVMByRDM',
76-
'Get-VNVMByVirtualPortGroup', 'Get-VNVMDiskAndRDM', 'Get-VNVMEVCInfo',
77-
'Get-VNVMHostBrokenUplink', 'Get-VNVMHostFirmwareInfo',
78-
'Get-VNVMHostHBAWWN', 'Get-VNVMHostLogicalVolumeInfo',
74+
'Find-VNVMWithDuplicateMACAddress', 'Get-VNInventoryType',
75+
'Get-VNNetworkClusterInfo', 'Get-VNUplinkNicForVM',
76+
'Get-VNVMByAddress', 'Get-VNVMByRDM', 'Get-VNVMByVirtualPortGroup',
77+
'Get-VNVMDiskAndRDM', 'Get-VNVMEVCInfo', 'Get-VNVMHostBrokenUplink',
78+
'Get-VNVMHostFirmwareInfo', 'Get-VNVMHostHBAWWN',
79+
'Get-VNVMHostLogicalVolumeInfo',
7980
'Get-VNVMHostNICFirmwareAndDriverInfo',
8081
'Invoke-VNEvacuateDatastore', 'Move-VNTemplateFromVMHost',
8182
'Update-VNTitleBarForPowerCLI'
@@ -111,7 +112,7 @@ PrivateData = @{
111112
Tags = 'vNugglets','vNugglets.com','VMware','vSphere','FaF','PowerCLI','VIRole','MAC','VM','RDM','vPG','VirtualPortgroup','EVC','VMHost','HBA','Datastore'
112113

113114
# A URL to the license for this module.
114-
LicenseUri = 'https://github.com/vNugglets/vNuggletsPSMod/blob/master/License'
115+
LicenseUri = 'https://github.com/vNugglets/vNuggletsPSMod/blob/main/License'
115116

116117
# A URL to the main website for this project.
117118
ProjectUri = 'https://github.com/vNugglets/vNuggletsPSMod'
@@ -120,13 +121,19 @@ PrivateData = @{
120121
IconUri = 'http://static.vnugglets.com/imgs/vNuggletsLogo.jpg'
121122

122123
# ReleaseNotes of this module
123-
ReleaseNotes = 'See release notes at https://github.com/vNugglets/vNuggletsPSMod/blob/master/ChangeLog.md'
124+
ReleaseNotes = 'See release notes at https://github.com/vNugglets/vNuggletsPSMod/blob/main/ChangeLog.md'
125+
126+
# Prerelease string of this module
127+
# Prerelease = ''
128+
129+
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
130+
# RequireLicenseAcceptance = $false
124131

125132
# External dependent modules of this module
126-
# ExternalModuleDependencies = ''
133+
# ExternalModuleDependencies = @()
127134

128135
} # End of PSData hashtable
129-
136+
130137
} # End of PrivateData hashtable
131138

132139
# HelpInfo URI of this module

vNugglets.Utility/vNuggletsUtilityMod_functions.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,3 +1428,45 @@ function Invoke-VNEvacuateDatastore {
14281428
} ## end foreach-object
14291429
} ## end process
14301430
} ## end fn
1431+
1432+
1433+
function Get-VNInventoryType {
1434+
<# .Description
1435+
Function to determine possible "correct" object type(s) to use from a vSphere inventory object, as described by Alan Renouf at http://blogs.vmware.com/PowerCLI/2016/04/powercli-best-practice-correct-use-strong-typing.html.
1436+
1437+
This is super helpful for when trying to determine most future-"safe" VMware object model types to use for parameter type-ing for our own functions/cmdlets
1438+
1439+
.Example
1440+
Get-DatastoreCluster myDSCluster0 | Get-VNInventoryType
1441+
Name FullName
1442+
---- --------
1443+
DatastoreCluster VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.DatastoreCluster
1444+
1445+
.Example
1446+
Get-VM myVM0 | Get-VNInventoryType -ReturnTypesType
1447+
Get the parent types of the VM object's type that include ".Types." in the name, of which "VMware.VimAutomation.Types.VirtualMachine" is probably a winner for subsequent use
1448+
#>
1449+
[CmdletBinding()]
1450+
[OutputType([System.Type])]
1451+
param(
1452+
## The vSphere object(s) for which to get so-called "safe" or "correct" Types for use in code
1453+
[parameter(mandatory=$true,ValueFromPipeline=$true)][VMware.VimAutomation.Sdk.Types.V1.VIObjectCore[]]$RelatedObject,
1454+
1455+
## Switch: return all types for this object type that contain ".Types." in their full name? (instead of just ones that match the "Impl" type name without the "Impl" string in them)
1456+
[Switch]$ReturnTypesType
1457+
) ## end param
1458+
1459+
process {
1460+
$RelatedObject | Foreach-Object {
1461+
$oThisEntity = $_
1462+
$oThisEntityType = $_.GetType()
1463+
## if "return all .Types.* types" switch is $true, return the full list of supported ".Types." types for this object
1464+
$(if ($ReturnTypesType) {$oThisEntityType.GetInterfaces() | Where-Object {$_.FullName -like "*.Types.*"}}
1465+
else {
1466+
## get the "future-safer" full type info for this object type, if any (essentially the same typename, but without the "Impl" portion in the it, if there is such a type)
1467+
$oThisEntityType.GetInterfaces() | Where-Object {($_.FullName -like "*.Types.*") -and ($_.Name -eq $oThisEntityType.Name.Replace("Impl", ""))}
1468+
} ## end else
1469+
) | Select-Object Name, FullName, @{n="RelatedObject"; e={$oThisEntity}}
1470+
} ## end foreach-object
1471+
} ## end process
1472+
}

0 commit comments

Comments
 (0)