Skip to content

Commit 6ea2649

Browse files
authored
Merge pull request #4 from vNugglets/feat_AddFnForType
Add function for vSphere inventory object base types
2 parents 5389631 + 38b3878 commit 6ea2649

File tree

7 files changed

+135
-115
lines changed

7 files changed

+135
-115
lines changed

ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### ChangeLog for vNugglets.Utility PowerShell module
22

3+
#### v1.3, released 21 Jan 2023
4+
5+
- \[new] added function `Get-VNInventoryType` for getting more future-safer vSphere object types (follwing guidance from VMware)
6+
37
#### v1.2, released 18 Jun 2017
48

59
- \[improvement] updated function `Get-VNVMByAddress`:
@@ -12,7 +16,7 @@
1216
- \[internal improvement] updated module prepartion to use `Update-ModuleManifest` for keeping module manifest in shape
1317
- added manifest entries for tags and for URIs for project, release notes, license, etc.
1418
- prepared for publishing to the [PowerShellGallery](https://www.powershellgallery.com/))
15-
19+
1620

1721
#### v1.1, released 20 Dec 2016
1822

ReadMe.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Some of the functionality provided by the cmdlets in this module:
1818
- vCenter connection information (in title of PowerShell window)
1919
- Datastore evacuation, template evacuation from VMHosts
2020
- Mining virtual portgroup information (cluster-locations)
21+
- Determining parent/base vSphere object types for use in parameter type-ing in subsequent function development
2122

2223
<a id="quickStart"></a>
2324
### QuickStart
@@ -45,7 +46,7 @@ The [ChangeLog](ChangeLog.md) for this module is, of course, a log of the major
4546
- download the module, either from the latest release's .zip file on the [vNugglets.Utility Releases](https://github.com/vNugglets/vNuggletsPSMod/releases) page, or by cloning the project to some local folder with Git via:
4647
`PS C:\> git clone https://github.com/vNugglets/vNuggletsPSMod.git C:\temp\MyVNuggsRepoCopy`
4748
- put the actual PowerShell module directory in some place that you like to keep your modules, say, like this, which copies the module to your personal Modules directory:
48-
`PS C:\> Copy-Item -Recurse -Path C:\temp\MyVNuggsRepoCopy\vNugglets.Utility\ -Destination ~\Documents\WindowsPowerShell\Modules\vNugglets.Utility`
49+
`PS C:\> Copy-Item -Recurse -Path C:\temp\MyVNuggsRepoCopy\vNugglets.Utility\ -Destination ~\Documents\PowerShell\Modules\vNugglets.Utility`
4950
- import the PowerShell module into the current PowerShell session:
5051
`PS C:\> Import-Module -Name vNugglets.Utility`
5152
or, if the vNugglets.Utility module folder is not in your `Env:\PSModulePath`, specify the whole path to the module folder, like:

Update-ThisModuleManifest.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<# .Description
2+
Some code to help automate the updating of the ModuleManifest file (will create it if it does not yet exist, too)
3+
#>
4+
[CmdletBinding(SupportsShouldProcess=$true)]
5+
param(
6+
## Module Version to set
7+
[parameter(Mandatory=$true)][System.Version]$ModuleVersion,
8+
9+
## Recreate the manifest (overwrite with full, fresh copy instead of update?)
10+
[Switch]$Recreate
11+
)
12+
begin {
13+
$strModuleName = "vNugglets.Utility"
14+
$strFilespecForPsd1 = Join-Path ($strModuleFolderFilespec = "$PSScriptRoot\$strModuleName") "${strModuleName}.psd1"
15+
16+
$hshManifestParams = @{
17+
# Confirm = $true
18+
Path = $strFilespecForPsd1
19+
ModuleVersion = $ModuleVersion
20+
Copyright = "MIT License"
21+
Description = "Module with the super useful functions that were previously scattered about the web by the vNugglets team (particularly, at vNugglets.com)"
22+
## some aliases, both as written, and with "VN" prefixed on them
23+
AliasesToExport = Write-Output ConnVIServer DisconnVIServer | Foreach-Object {$_; "VN$_"}
24+
FileList = Write-Output "${strModuleName}.psd1" vNuggletsUtilityMod.psm1 vNuggletsUtilityMod_functions.ps1 vNugglets_SupportingFunctions.ps1 "en-US\about_${strModuleName}.help.txt"
25+
FunctionsToExport = Write-Output Connect-VNVIServer Copy-VNVIRole Disconnect-VNVIServer Find-VNVMWithDuplicateMACAddress Get-VNInventoryType Get-VNNetworkClusterInfo Get-VNUplinkNicForVM Get-VNVMByAddress Get-VNVMByRDM Get-VNVMByVirtualPortGroup Get-VNVMDiskAndRDM Get-VNVMEVCInfo Get-VNVMHostBrokenUplink Get-VNVMHostFirmwareInfo Get-VNVMHostHBAWWN Get-VNVMHostLogicalVolumeInfo Get-VNVMHostNICFirmwareAndDriverInfo Invoke-VNEvacuateDatastore Move-VNTemplateFromVMHost Update-VNTitleBarForPowerCLI
26+
IconUri = "http://static.vnugglets.com/imgs/vNuggletsLogo.jpg"
27+
LicenseUri = "https://github.com/vNugglets/vNuggletsPSMod/blob/main/License"
28+
## scripts (.ps1) that are listed in the NestedModules key are run in the module's session state, not in the caller's session state. To run a script in the caller's session state, list the script file name in the value of the ScriptsToProcess key in the manifest; RegisterArgCompleter apparently needs to be added _after_ function definition .ps1 files are run (via NestedModules) (else, given functions are not defined, and if RegisterArgCompleter is referring to commands from module dynamically, it would not get them; that is the case if the function definitions are in a .psm1 file instead of .ps1 file, and are being defined in NestedModules)
29+
NestedModules = Write-Output vNuggletsUtilityMod_functions.ps1 vNugglets_SupportingFunctions.ps1
30+
# PassThru = $true
31+
PowerShellVersion = [System.Version]"5.0"
32+
ProjectUri = "https://github.com/vNugglets/vNuggletsPSMod"
33+
ReleaseNotes = "See release notes at https://github.com/vNugglets/vNuggletsPSMod/blob/main/ChangeLog.md"
34+
## relies on a centrally-important VMware PowerCLI module
35+
RequiredModules = "VMware.VimAutomation.Core"
36+
Tags = Write-Output vNugglets vNugglets.com VMware vSphere FaF PowerCLI VIRole MAC VM RDM vPG VirtualPortgroup EVC VMHost HBA Datastore
37+
# Verbose = $true
38+
} ## end hashtable
39+
} ## end begin
40+
41+
process {
42+
$bManifestFileAlreadyExists = Test-Path $strFilespecForPsd1
43+
## check that the FileList property holds the names of all of the files in the module directory, relative to the module directory
44+
## the relative names of the files in the module directory (just filename for those in module directory, "subdir\filename.txt" for a file in a subdir, etc.)
45+
$arrRelativeNameOfFilesInModuleDirectory = Get-ChildItem $strModuleFolderFilespec -Recurse | Where-Object {-not $_.PSIsContainer} | ForEach-Object {$_.FullName.Replace($strModuleFolderFilespec, "", [System.StringComparison]::OrdinalIgnoreCase).TrimStart("\")}
46+
if ($arrDiffResults = (Compare-Object -ReferenceObject $hshManifestParams.FileList -DifferenceObject $arrRelativeNameOfFilesInModuleDirectory)) {Write-Error "Uh-oh -- FileList property value for making/updating module manifest and actual files present in module directory do not match. Better check that. The variance:`n$($arrDiffResults | Out-String)"} else {Write-Verbose -Verbose "Hurray, all of the files in the module directory are named in the FileList property to use for the module manifest"}
47+
$strMsgForShouldProcess = "{0} module manifest" -f $(if ((-not $bManifestFileAlreadyExists) -or $Recreate) {"Create"} else {"Update"})
48+
if ($PsCmdlet.ShouldProcess($strFilespecForPsd1, $strMsgForShouldProcess)) {
49+
## do the actual module manifest update
50+
if ((-not $bManifestFileAlreadyExists) -or $Recreate) {Microsoft.PowerShell.Core\New-ModuleManifest @hshManifestParams}
51+
else {PowerShellGet\Update-ModuleManifest @hshManifestParams}
52+
## replace the comment in the resulting module manifest that includes "PSGet_" prefixed to the actual module name with a line without "PSGet_" in it
53+
(Get-Content -Path $strFilespecForPsd1 -Raw).Replace("# Module manifest for module 'PSGet_$strModuleName'", "# Module manifest for module '$strModuleName'") | Set-Content -Path $strFilespecForPsd1
54+
} ## end if
55+
} ## end prcoess

Update-VNModuleManifest.ps1

Lines changed: 0 additions & 72 deletions
This file was deleted.

testing/vNugglets.Utility.Tests_Unit.ps1

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@
99

1010
Write-Verbose -Verbose "tests not yet fully written"
1111

12-
<#
13-
Cmdlets for which to still write tests:
14-
Copy-VNVIRole
15-
Disconnect-VNVIServer
16-
Get-VNNetworkClusterInfo
17-
Get-VNUplinkNicForVM
18-
Get-VNVMByAddress
19-
Get-VNVMByRDM
20-
Get-VNVMByVirtualPortGroup
21-
Get-VNVMDiskAndRDM
22-
Get-VNVMEVCInfo
23-
Get-VNVMHostBrokenUplink
24-
Invoke-VNEvacuateDatastore
25-
Move-VNTemplateFromVMHost
26-
Update-VNTitleBarForPowerCLI
27-
#>
28-
2912
$oTestVMHost = Get-VMHost -State Connected | Select-Object -First 1
3013

3114
## array of objects, each with information about what and how to test for the given cmdlet; used to create, for each cmdlet, the actual tests below

vNugglets.Utility/vNugglets.Utility.psd1

Lines changed: 31 additions & 24 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 = @()
@@ -32,20 +32,20 @@ Copyright = 'MIT License'
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 = ''
@@ -66,18 +66,19 @@ RequiredModules = @('VMware.VimAutomation.Core')
6666
# FormatsToProcess = @()
6767

6868
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69-
NestedModules = @('vNuggletsUtilityMod_functions.ps1',
69+
NestedModules = @('vNuggletsUtilityMod_functions.ps1',
7070
'vNugglets_SupportingFunctions.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.
73-
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',
79-
'Get-VNVMHostNICFirmwareAndDriverInfo',
80-
'Invoke-VNEvacuateDatastore', 'Move-VNTemplateFromVMHost',
73+
FunctionsToExport = 'Connect-VNVIServer', 'Copy-VNVIRole', 'Disconnect-VNVIServer',
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',
80+
'Get-VNVMHostNICFirmwareAndDriverInfo',
81+
'Invoke-VNEvacuateDatastore', 'Move-VNTemplateFromVMHost',
8182
'Update-VNTitleBarForPowerCLI'
8283

8384
# Cmdlets 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 cmdlets to export.
@@ -87,7 +88,7 @@ CmdletsToExport = @()
8788
# VariablesToExport = @()
8889

8990
# Aliases 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 aliases to export.
90-
AliasesToExport = 'ConnVIServer', 'VNConnVIServer', 'DisconnVIServer',
91+
AliasesToExport = 'ConnVIServer', 'VNConnVIServer', 'DisconnVIServer',
9192
'VNDisconnVIServer'
9293

9394
# DSC resources to export from this module
@@ -97,9 +98,9 @@ AliasesToExport = 'ConnVIServer', 'VNConnVIServer', 'DisconnVIServer',
9798
# ModuleList = @()
9899

99100
# List of all files packaged with this module
100-
FileList = 'vNugglets.Utility.psd1', 'vNuggletsUtilityMod.psm1',
101-
'vNuggletsUtilityMod_functions.ps1',
102-
'vNugglets_SupportingFunctions.ps1',
101+
FileList = 'vNugglets.Utility.psd1', 'vNuggletsUtilityMod.psm1',
102+
'vNuggletsUtilityMod_functions.ps1',
103+
'vNugglets_SupportingFunctions.ps1',
103104
'en-US\about_vNugglets.Utility.help.txt'
104105

105106
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
@@ -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

0 commit comments

Comments
 (0)