Skip to content

Commit 27bdcb4

Browse files
committed
Prep for fn add, update the Update script
1 parent 5389631 commit 27bdcb4

File tree

4 files changed

+36
-65
lines changed

4 files changed

+36
-65
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 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-VNModuleManifest.ps1

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
<# .Description
2-
Some code to help automate the updating of the ModuleManifest file
2+
Some code to help automate the updating of the ModuleManifest file (will create it if it does not yet exist, too)
33
#>
44
[CmdletBinding(SupportsShouldProcess=$true)]
5-
param()
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+
)
612
begin {
7-
## some code to generate the module manifest
8-
$strFilespecForPsd1 = "$PSScriptRoot\vNugglets.Utility\vNugglets.Utility.psd1"
13+
$strModuleName = "vNugglets.Utility"
14+
$strFilespecForPsd1 = Join-Path ($strModuleFolderFilespec = "$PSScriptRoot\$strModuleName") "${strModuleName}.psd1"
915

10-
$hshModManifestParams = @{
16+
$hshManifestParams = @{
1117
# Confirm = $true
1218
Path = $strFilespecForPsd1
13-
ModuleVersion = "1.2.0"
19+
ModuleVersion = $ModuleVersion
20+
Copyright = "Apache 2.0 License"
1421
Description = "Module with the super useful functions that were previously scattered about the web by the vNugglets team (particularly, at vNugglets.com)"
1522
## some aliases, both as written, and with "VN" prefixed on them
1623
AliasesToExport = Write-Output ConnVIServer DisconnVIServer | Foreach-Object {$_; "VN$_"}
17-
FileList = Write-Output vNugglets.Utility.psd1 vNuggletsUtilityMod.psm1 vNuggletsUtilityMod_functions.ps1, vNugglets_SupportingFunctions.ps1, en-US\about_vNugglets.Utility.help.txt
18-
FunctionsToExport = Write-Output Connect-VNVIServer Copy-VNVIRole Disconnect-VNVIServer Find-VNVMWithDuplicateMACAddress 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
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
1926
IconUri = "http://static.vnugglets.com/imgs/vNuggletsLogo.jpg"
20-
LicenseUri = "https://github.com/vNugglets/vNuggletsPSMod/blob/master/License"
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)
2129
NestedModules = Write-Output vNuggletsUtilityMod_functions.ps1 vNugglets_SupportingFunctions.ps1
2230
# PassThru = $true
31+
PowerShellVersion = [System.Version]"5.0"
2332
ProjectUri = "https://github.com/vNugglets/vNuggletsPSMod"
24-
ReleaseNotes = "See release notes at https://github.com/vNugglets/vNuggletsPSMod/blob/master/ChangeLog.md"
33+
ReleaseNotes = "See release notes at https://github.com/vNugglets/vNuggletsPSMod/blob/main/ChangeLog.md"
2534
## relies on a centrally-important VMware PowerCLI module
2635
RequiredModules = "VMware.VimAutomation.Core"
2736
Tags = Write-Output vNugglets vNugglets.com VMware vSphere FaF PowerCLI VIRole MAC VM RDM vPG VirtualPortgroup EVC VMHost HBA Datastore
@@ -30,43 +39,17 @@ begin {
3039
} ## end begin
3140

3241
process {
33-
if ($PsCmdlet.ShouldProcess($strFilespecForPsd1, "Update module manifest")) {
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)) {
3449
## do the actual module manifest update
35-
PowerShellGet\Update-ModuleManifest @hshModManifestParams
50+
if ((-not $bManifestFileAlreadyExists) -or $Recreate) {Microsoft.PowerShell.Core\New-ModuleManifest @hshManifestParams}
51+
else {PowerShellGet\Update-ModuleManifest @hshManifestParams}
3652
## replace the comment in the resulting module manifest that includes "PSGet_" prefixed to the actual module name with a line without "PSGet_" in it
37-
(Get-Content -Path $strFilespecForPsd1 -Raw).Replace("# Module manifest for module 'PSGet_vNugglets.Utility'", "# Module manifest for module 'vNugglets.Utility'") | Set-Content -Path $strFilespecForPsd1
53+
(Get-Content -Path $strFilespecForPsd1 -Raw).Replace("# Module manifest for module 'PSGet_$strModuleName'", "# Module manifest for module '$strModuleName'") | Set-Content -Path $strFilespecForPsd1
3854
} ## end if
3955
} ## end prcoess
40-
41-
42-
<#
43-
## used for original manifest creation
44-
$hshModManifestParams = @{
45-
Path = $strFilespecForPsd1
46-
Author = "Matt Boren"
47-
CompanyName = "vNugglets.com"
48-
Copyright = "MIT License"
49-
## when setting value for DefaultCommandPrefix in module, need to account for that when setting value for Aliases anywhere (need to code those to point at what the functions _will_ be called when the DefaultCommandPrefix is applied)
50-
#DefaultCommandPrefix = ""
51-
#FormatsToProcess = "SomeModule.format.ps1xml"
52-
ModuleToProcess = "vNuggletsUtilityMod.psm1"
53-
ModuleVersion = "1.1.0"
54-
## 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
55-
NestedModules = @("vNuggletsUtilityMod_functions.ps1", "vNugglets_SupportingFunctions.ps1")
56-
PowerShellVersion = [System.Version]"4.0"
57-
Description = "Module with the functions that have previously been scattered about the web by the vNugglets team (particularly, at vNugglets.com"
58-
## specifies script (.ps1) files that run in the caller's session state when the module is imported. You can use these scripts to prepare an environment, just as you might use a login script
59-
# ScriptsToProcess = "New-HtmlReport_configItems.ps1"
60-
VariablesToExport = @()
61-
AliasesToExport = @()
62-
CmdletsToExport = @()
63-
FileList = Write-Output vNugglets.Utility.psd1 vNuggletsUtilityMod.psm1 vNuggletsUtilityMod_functions.ps1, vNugglets_SupportingFunctions.ps1, about_vNugglets.Utility.help.txt
64-
Verbose = $true
65-
}
66-
## using -PassThru so as to pass the generated module manifest contents to a var for later output as ASCII (instead of having a .psd1 file of default encoding, Unicode)
67-
$oManifestOutput = New-ModuleManifest @hshModManifestParams -PassThru
68-
## have to do in separate step, as PSD1 file is "being used by another process" -- the New-ModuleManifest cmdlet, it seems
69-
# in order to have this module usable (importable) via PowerShell v2, need to update the newly created .psd1 file, replacing the 'RootModule' keyword with 'ModuleToProcess'
70-
# ($oManifestOutput -split "`n" | Foreach-Object {$_ -replace "^RootModule = ", "ModuleToProcess = "}) -join "`n" | Out-File -Verbose -FilePath $strFilespecForPsd1 -Encoding ASCII
71-
$oManifestOutput | Out-File -Verbose $strFilespecForPsd1 -Encoding ASCII
72-
#>

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

0 commit comments

Comments
 (0)