Skip to content

Commit 1de2df0

Browse files
committed
Merge branch 'dev'
2 parents 6475338 + cad80ab commit 1de2df0

14 files changed

+1720
-2
lines changed

ChangeLog.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### ChangeLog for vNugglets.Utility PowerShell module
2+
3+
#### v1.0, released 05 Dec 2016
4+
5+
- created module from many of the juicy snippets/functions that we shared at [vNugglets.com](http://vNugglets.com) over the years
6+
- updated `Copy-VNVIRole` to be a safer function overall by removing old `Invoke-Expression` methodology
7+
- standardized parameter names across cmdlets in the module and expanded some previously truncated/cryptic parameter names (go, usability and discoverability!)
8+
- added/updated "by name regular expression pattern" and "by liternal name string" parameters to several cmdlets
9+
- modernized cmdlets to use capabilities of somewhat newer PowerShell releases (like ordered hashtables) and built-in property return iteration, breaking PowerShell v2.0 compatibility (it's time to upgrade, right?)
10+
- updated `Invoke-VNEvacuateDatastore`:
11+
- added feature that uses any/all datastores in datastore cluster (when specifying a datastore cluster for Destination parameter value) for potential destination _per object_ (this allows for a potentially different datastore for each virtual disk on a VM)
12+
- added ability to exclude a VM/template's files from evacuation process (via parameter)
13+
- added `-WhatIf` support
14+
- updated cmdlet names to use standard/approved verbs where they were not already in use. Renamed functions/snippets as follows:
15+
- `Get-VNVMByRDM` was "Get-VMWithGivenRDM"
16+
- `Get-VNVMByVirtualPortGroup` was "Get-VMOnNetworkPortGroup"
17+
- `Get-VNVMHostBrokenUplink` was "Get-BustedVmnic"
18+
- `Invoke-VNEvacuateDatastore` was "Evacuate-Datastore"
19+
- started writing the Pester tests for the cmdlets (many more to go, still)
20+
- added proper comment-based help to all cmdlets (as described in PowerShell Help topic `about_Comment_Based_Help`)
21+
- included "about" help topic, `about_vNugglets.Utility`
File renamed without changes.

README.md

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

ReadMe.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# vNugglets PowerShell Module
2+
Contents:
3+
4+
- [QuickStart](#quickStart)
5+
- [Examples](#examplesSection)
6+
- [ChangeLog](#changelog)
7+
8+
This is the PowerShell module created from the nugglets from [vNugglets.com](http://vNugglets.com). This repo is meant to be a place where the vNugglets.com code can reside, separate from the blog, for easier/central consumption and collaboration.
9+
10+
Some of the functionality provided by the cmdlets in this module:
11+
- VIRole management (copying/duplicating)
12+
- Finding VMs in inventory by attributes other than "name", like by the guest IP address, by the RDMs it may have, by the virtual portgroup to which it is connected
13+
- Mining VMHost information, like host and peripheral firmware information, HBA WWNs, logical drive information, information about "broken" vmnics
14+
- Establishing VM network to virtual portgroup physical uplink relationship information (which of the active uplinks is VM0 actually currently using?)
15+
- Mining VM information, like standard and RDM disks, EVC setting
16+
- vCenter connection information (in title of PowerShell window)
17+
- Datastore evacuation, template evacuation from VMHosts
18+
- Mining virtual portgroup information (cluster-locations)
19+
20+
<a id="quickStart"></a>
21+
### QuickStart
22+
Chomping at the bit to get going with using this module? Of course you are! Go like this:
23+
- 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:
24+
`PS C:\> git clone https://github.com/vNugglets/vNuggletsPSMod.git C:\temp\MyVNuggsRepoCopy`
25+
- 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:
26+
`PS C:\> Copy-Item -Recurse -Path C:\temp\MyVNuggsRepoCopy\vNugglets.Utility\ -Destination ~\Documents\WindowsPowerShell\Modules\vNugglets.Utility`
27+
- import the PowerShell module into the current PowerShell session:
28+
`PS C:\> Import-Module -Name vNugglets.Utility`
29+
or, if the vNugglets.Utility module folder is not in your `Env:\PSModulePath`, specify the whole path to the module folder, like:
30+
`PS C:\> Import-Module -Name \\myserver.dom.com\PSModules\vNugglets.Utility`
31+
32+
<a id="examplesSection"></a>
33+
### Examples
34+
There are examples of some of the usages of the cmdlets in this PowerShell module at the module's GitHub Pages page [https://vNugglets.github.io/vNuggletsPSMod](https://vNugglets.github.io/vNuggletsPSMod/)
35+
36+
### Getting Help
37+
The cmdlets in this module all have proper help, so you can learn and discover just as you would and do with any other legitimate PowerShell module:
38+
- `Get-Command -Module <moduleName>`
39+
- `Get-Help -Full <cmdlet-name>`
40+
41+
<a id="changelog"></a>
42+
### ChangeLog
43+
The [ChangeLog](ChangeLog.md) for this module is, of course, a log of the major changes through the module's hitory. Enjoy the story.
44+
45+
### Other Notes
46+
A few notes on updates to this repo:
47+
48+
Dec 2016
49+
- initial public release
50+
51+
Nov 2016
52+
- started whole hog on creating PowerShell module to try to contain all of this goodness
53+
54+
Sep 2016
55+
- created repository, populated with first nugglet

ToDo.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### ToDo for vNugglets.Utility PowerShell module
2+
3+
- add more tests
4+
- update function `Get-VNVMHostBrokenUplink` to include:
5+
- support for virtual distributed switches ("vDS" or "vDSwitches"); currently only supports virtual standard switches ("vSS")
6+
- support for accepting VMHost ID from pipeline (by property), so that the following works tip top:
7+
`Get-Cluster myCluster | Get-VMHost | Get-VNVMHostBrokenUplink`
8+
- update function `Get-VNVMByAddress` to:
9+
- use `VMware.Vim.SearchIndex` for speed for FindAllByIp (does support wildcard, though)
10+
- support searching by guest DNS name (also using `VMware.Vim.SearchIndex`, via the `FindAllByDnsName` method)
11+
- update function `Get-VNVMByVirtualPortGroup` to take a standard- or distributed virtual portgroup as a parameter (and, from pipeline)
12+
- update function `Copy-VNVIRole` to take SourceVIRole as VIRole object, and to accept it from pipeline
13+
- update function `Get-VNVMEVCInfo` to take Cluster object from pipeline
14+
- update function `Get-VNUplinkNicForVM` to give more meaningful VDSwitch identification (currently returns something to the effect of `DvsPortset-1` for the VDSwitch name)

done.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\[feat_InitialModuleCreation]
2+
- function-ize the snippets on vNugglets, improving them as suitable
3+
- improved:
4+
- `Get-VNVMHostBrokenUplink` -- added more properties to returned object for more easily relating the given vmnic to the VMHost and vSwitch of which it is a part
5+
- added about_vNugglets.Utility help topic

makeModule.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## some code to generate the module manifest
2+
$strFilespecForPsd1 = "$PSScriptRoot\vNugglets.Utility\vNugglets.Utility.psd1"
3+
4+
$hshModManifestParams = @{
5+
Path = $strFilespecForPsd1
6+
Author = "Matt Boren"
7+
CompanyName = "vNugglets.com"
8+
Copyright = "MIT License"
9+
## 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)
10+
#DefaultCommandPrefix = ""
11+
#FormatsToProcess = "SomeModule.format.ps1xml"
12+
ModuleToProcess = "vNuggletsUtilityMod.psm1"
13+
ModuleVersion = "1.0.0"
14+
## 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
15+
NestedModules = @("vNuggletsUtilityMod_functions.ps1", "vNugglets_SupportingFunctions.ps1")
16+
PowerShellVersion = [System.Version]"4.0"
17+
Description = "Module with the functions that have previously been scattered about the web by the vNugglets team (particularly, at vNugglets.com"
18+
## 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
19+
# ScriptsToProcess = "New-HtmlReport_configItems.ps1"
20+
VariablesToExport = @()
21+
AliasesToExport = @()
22+
CmdletsToExport = @()
23+
FileList = Write-Output vNugglets.Utility.psd1 vNuggletsUtilityMod.psm1 vNuggletsUtilityMod_functions.ps1, vNugglets_SupportingFunctions.ps1, about_vNugglets.Utility.help.txt
24+
Verbose = $true
25+
}
26+
## 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)
27+
$oManifestOutput = New-ModuleManifest @hshModManifestParams -PassThru
28+
## have to do in separate step, as PSD1 file is "being used by another process" -- the New-ModuleManifest cmdlet, it seems
29+
# 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'
30+
# ($oManifestOutput -split "`n" | Foreach-Object {$_ -replace "^RootModule = ", "ModuleToProcess = "}) -join "`n" | Out-File -Verbose -FilePath $strFilespecForPsd1 -Encoding ASCII
31+
$oManifestOutput | Out-File -Verbose $strFilespecForPsd1 -Encoding ASCII
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## initialization code for use by multiple *.Tests.ps1 files for testing vNugglets.Utility PowerShell module
2+
3+
$strNameOfModuleToTest = "vNugglets.Utility"
4+
## if module not already loaded, try to load it (assumes that module is in PSModulePath)
5+
if (-not ($oModuleInfo = Get-Module $strNameOfModuleToTest)) {
6+
$oModuleInfo = Import-Module $strNameOfModuleToTest -PassThru
7+
if (-not ($oModuleInfo -is [System.Management.Automation.PSModuleInfo])) {Throw "Could not load module '$strNameOfModuleToTest' -- is it available in the PSModulePath? You can manually load the module and start tests again"}
8+
} ## end if
9+
Write-Verbose -Verbose ("Starting testing of module '{0}' (version '{1}' from '{2}')" -f $oModuleInfo.Name, $oModuleInfo.Version, $oModuleInfo.Path)
10+
11+
## ensure that this session is connected to at least one vCenter server (prompt to do so if not already connected)
12+
$oSomeVCConnection = if (-not (($global:DefaultVIServers | Measure-Object).Count -gt 0)) {
13+
$hshParamForConnectVIServer = @{Server = $(Read-Host -Prompt "vCenter server name to which to connect for testing")}
14+
ConnVIServer @hshParamForConnectVIServer
15+
} ## end if
16+
else {$global:DefaultVIServers[0]}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<# .Description
2+
Pester tests for vNugglets.Utility PowerShell module. Will expect that (once fully written):
3+
0) vNugglets.Utility module is already loaded (but, will try to load it if not)
4+
1) a connection to at least one vCenter is in place (but, will prompt for vCenter to which to connect if not)
5+
#>
6+
7+
## initialize things, preparing for tests
8+
. $PSScriptRoot\vNugglets.Utility.TestingInit.ps1
9+
10+
Write-Verbose -Verbose "tests not yet fully written"
11+
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+
29+
$oTestVMHost = Get-VMHost -State Connected | Select-Object -First 1
30+
31+
## 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
32+
$arrInfoOnCmdletsToTest = @(
33+
New-Object -Type PSObject -Property @{
34+
CmdletName = "Get-VNVMHostFirmwareInfo"
35+
TestDescription = "Gets VMHost physical server's firmware information (HP-focused)"
36+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
37+
ExpectedReturnObjNotePropertyNames = Write-Output HPSmartArray iLOFirmware Model SystemBIOS VMHostName
38+
TestScriptblock = {$oTestVMHost | Get-VNVMHostFirmwareInfo}
39+
}
40+
New-Object -Type PSObject -Property @{
41+
CmdletName = "Get-VNVMHostHBAWWN"
42+
TestDescription = "Gets VMHost HBA WWN information"
43+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
44+
ExpectedReturnObjNotePropertyNames = Write-Output DeviceName HBANodeWWN HBAPortWWN HBAStatus VMHostName
45+
TestScriptblock = {$oTestVMHost | Get-VNVMHostHBAWWN}
46+
}
47+
New-Object -Type PSObject -Property @{
48+
CmdletName = "Get-VNVMHostLogicalVolumeInfo"
49+
TestDescription = "Gets VMHost's logical volume information"
50+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
51+
ExpectedReturnObjNotePropertyNames = Write-Output LogicalVolume VMHostName
52+
TestScriptblock = {$oTestVMHost | Get-VNVMHostLogicalVolumeInfo}
53+
}
54+
New-Object -Type PSObject -Property @{
55+
CmdletName = "Get-VNVMHostNICFirmwareAndDriverInfo"
56+
TestDescription = "Gets VMHost's NIC drive and firmware information"
57+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
58+
ExpectedReturnObjNotePropertyNames = Write-Output NicDriverVersion NicFirmwareVersion VMHostName
59+
TestScriptblock = {$oTestVMHost | Get-VNVMHostNICFirmwareAndDriverInfo}
60+
}
61+
)
62+
63+
## perform the actual tests for standard Get- types of cmdlets
64+
$arrInfoOnCmdletsToTest | Foreach-Object {
65+
$oInfoForThisCmdletTest = $_
66+
Describe -Tags "Get" -Name $oInfoForThisCmdletTest.CmdletName {
67+
It $oInfoForThisCmdletTest.TestDescription {
68+
## the NoteProperties that the return objects should have
69+
$arrExpectedReturnObjNotePropertyNames = $oInfoForThisCmdletTest.ExpectedReturnObjNotePropertyNames
70+
$arrReturnObj = & $oInfoForThisCmdletTest.TestScriptblock
71+
$arrReturnTypes = $arrReturnObj | Get-Member | Select-Object -Unique -ExpandProperty TypeName
72+
$bGetsOnlyExpectedObjectType = $arrReturnTypes -eq $oInfoForThisCmdletTest.ExpectedReturnTypename
73+
## does the array of names of NoteProperties in the set of return objects have only the values expected for return objects? (does the comparison of the arrays return no difference objects?)
74+
$bHasExpectedNoteProperties = $null -eq (Compare-Object -ReferenceObject $arrExpectedReturnObjNotePropertyNames -DifferenceObject ($arrReturnObj | Get-Member -MemberType NoteProperty).Name)
75+
$bGetsOnlyExpectedObjectType | Should Be $true
76+
$bHasExpectedNoteProperties | Should Be $true
77+
} ## end it
78+
} ## end describe
79+
} ## end foreach-object
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
TOPIC
2+
about_vNugglets.Utility
3+
4+
SHORT DESCRIPTION
5+
Module encapsulating vNugglets.com functions and code snippets
6+
7+
LONG DESCRIPTION
8+
A module that centralizes the functions and code snippets from vNugglets.com
9+
into a cohesive toolset.
10+
11+
The cmdlets in this module focus largely (almost exclusively) on VMware
12+
virtual infrastructure. Some of the areas of focus are:
13+
- VIRole management (copying/duplicating)
14+
- Finding VMs in inventory by attributes other than "name", like by the
15+
guest IP address, by the RDMs it may have, by the virtual portgroup to
16+
which it is connected
17+
- Mining VMHost information, like host and peripheral firmware
18+
information, HBA WWNs, logical drive information, information about
19+
"broken" vmnics
20+
- Establishing VM network to virtual portgroup physical uplink
21+
relationship information (which of the active uplinks is VM0 actually
22+
currently using?)
23+
- Mining VM information, like standard and RDM disks, EVC setting
24+
- vCenter connection information (in title of PowerShell window)
25+
- Datastore evacuation, template evacuation from VMHosts
26+
- Mining virtual portgroup information (cluster-locations)
27+
28+
EXAMPLES
29+
All of the cmdlets in this module have proper comment-based help. Discover
30+
and learn via the standard PowerShell way:
31+
32+
Get-Help -Full <cmdlet-name>
33+
34+
KEYWORDS
35+
vNugglets
36+
vNuggs
37+
vNuggies
38+
vNooget
39+
vNoogets
40+
vNooglets
41+
42+
SEE ALSO
43+
vNugglets.com
44+
github.com/vNugglets

0 commit comments

Comments
 (0)