Skip to content

Commit

Permalink
Refining Get-Help functionality, formating, export module bugfix, exc…
Browse files Browse the repository at this point in the history
…luded Set-WmiInstance

## Get-Help
* Added functionality to Get-WmiNamespace, Get-WmiNamespaceRecursive and Get-WmiClass
## Formating
* Standardized module header by moving info to Note section
## Export-Module
Fixed typo for Rename-WmiClass and Rename-WmiNamespace
  • Loading branch information
Ioan Popovici committed Jan 31, 2018
1 parent a910b24 commit 5acb6f6
Showing 1 changed file with 58 additions and 21 deletions.
79 changes: 58 additions & 21 deletions PSWmiToolkit.psm1
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
<#
*********************************************************************************************************
* Requires | PowerShell 4.0 *
* ===================================================================================================== *
* Created by | Date | Comments *
* _____________________________________________________________________________________________________ *
* Ioan Popovici | 2017-11-09 | *
* ===================================================================================================== *
* *
*********************************************************************************************************
.SYNOPSIS
This PowerShell module contains functions for managing WMI.
.DESCRIPTION
This PowerShell module contains functions for creating WMI Namespaces, Classes and Instances.
This PowerShell module contains functions for managing WMI Namespaces, Classes and Instances.
.EXAMPLE
Import-Module -Name 'C:\Temp\WmiToolkit.psm1' -Verbose
Import-Module -Name '.\WmiToolkit.psm1' -Verbose
.EXAMPLE
Get-Command -Module 'WmiToolkit'
.EXAMPLE
Get-Command -Module 'PSWmiToolkit' | ForEach-Object { Get-Help $_.Name -Examples }
.EXAMPLE
Get-Help -Component WMI
.EXAMPLE
Get-Help -Component WMI | Get-Help -Detailed
.INPUTS
None.
.OUTPUTS
None.
.NOTES
--
Released : 2017-11-09
Author : Ioan Popovici
Requirements : PowerShell v3.0
.LINK
https://sccm-zone.com
.LINK
https://github.com/JhonnyTerminus/SCCM
.COMPONENT
WMI
.FUNCTIONALITY
WMI Management
#>

## Setting module requirements
#Requires -Version '3.0'
#Requires -RunAsAdministrator

##*=============================================
##* VARIABLE DECLARATION
##*=============================================
Expand Down Expand Up @@ -567,21 +577,30 @@ Function Get-WmiNameSpace {
Get-WmiNameSpace -NameSpace 'ROOT' -List
.EXAMPLE
Get-WmiNameSpace -NameSpace 'ROOT' -Recurse
.INPUTS
None.
.OUTPUTS
None.
.NOTES
This is a module function and can typically be called directly.
.LINK
https://sccm-zone.com
.LINK
https://github.com/JhonnyTerminus/SCCM
.COMPONENT
WMI
.FUNCTIONALITY
WMI Management
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,Position=0)]
[ValidateNotNullorEmpty()]
[SupportsWildcards()]
[string]$Namespace,
[Parameter(Mandatory=$false,Position=1)]
[ValidateNotNullorEmpty()]
[ValidateScript({
[ValidateScript({
If ($Namespace -match '\*') { Throw "Wildcards are not supported with this switch." }
Return $true
})]
Expand All @@ -591,7 +610,7 @@ Function Get-WmiNameSpace {
[ValidateScript({
If ($Namespace -match '\*') { Throw "Wildcards are not supported with this switch." }
Return $true
})]
})]
[switch]$Recurse = $false
)

Expand Down Expand Up @@ -622,12 +641,20 @@ Function Get-WmiNameSpace {
Specifies the root namespace path from which to start searching.
.EXAMPLE
Get-WmiNamespaceRecursive -NameSpace 'ROOT\SCCM'
.INPUTS
None.
.OUTPUTS
None.
.NOTES
This is a private module function and should not typically be called directly.
.LINK
https://sccm-zone.com
.LINK
https://github.com/JhonnyTerminus/SCCM
.COMPONENT
WMI
.FUNCTIONALITY
WMI Management
#>
[CmdletBinding()]
Param (
Expand Down Expand Up @@ -700,7 +727,7 @@ Function Get-WmiNameSpace {
Write-Error -Message $NamespaceNotFoundErr -Category 'ObjectNotFound'
}
ElseIf (-not $Err) {
$GetNamespace = $WmiNamespace | ForEach-Object {
$GetNamespace = $WmiNamespace | ForEach-Object {
[PSCustomObject]@{
Name = $Name = $_.Name
Path = $Path = $_.CimSystemProperties.Namespace -replace ('/','\')
Expand Down Expand Up @@ -746,12 +773,20 @@ Function Get-WmiClass {
Get-WmiClass -Namespace 'ROOT\SCCM' -QualifierName 'Description'
.EXAMPLE
Get-WmiClass -Namespace 'ROOT\SCCM'
.INPUTS
None.
.OUTPUTS
None.
.NOTES
This is a module function and can typically be called directly.
.LINK
https://sccm-zone.com
.LINK
https://github.com/JhonnyTerminus/SCCM
.COMPONENT
WMI
.FUNCTIONALITY
WMI Management
#>
[CmdletBinding()]
Param (
Expand Down Expand Up @@ -3376,7 +3411,7 @@ Function Rename-WmiNamespace {

# Remove old Namespace
Remove-WmiNameSpace -Namespace $NamespaceSource -Recurse -Force

# Write success message to console
Write-Log -Message "Succesfully renamed namespace [$NamespaceSource -> $NamespaceDestination]" -Source ${CmdletName}
}
Expand Down Expand Up @@ -3458,7 +3493,7 @@ Function Rename-WmiClass {

## Remove the old class
Remove-WmiClass -Namespace $Namespace -ClassName $Name -ErrorAction 'Stop'

## Write success message to console
Write-Log -Message "Succesfully renamed class [$ClassPathSource -> $ClassPathDestination]" -Source ${CmdletName}
}
Expand Down Expand Up @@ -3508,7 +3543,9 @@ Function Set-WmiInstance {
'Date' = $(Get-Date)
}
Set-WmiInstance -Namespace 'ROOT' -ClassName 'SCCMZone' -Key 'File1' -PropertySearch $PropertySearch -Property $Property
.EXAMPLE
Set-WmiInstance -Namespace 'ROOT' -ClassName 'SCCMZone' -Key 'File1' -Property $Property
.EXAMPLE
Set-WmiInstance -Namespace 'ROOT' -ClassName 'SCCMZone' -Property $Property -CreateInstance
.NOTES
This is a module function and can typically be called directly.
Expand Down Expand Up @@ -3661,12 +3698,12 @@ Export-ModuleMember -Function Copy-WmiProperty
Export-ModuleMember -Function Copy-WmiInstance


Export-ModulMember -Function Rename-WmiNamespace
Export-ModulMember -Function Rename-WmiClass
Export-ModuleMember -Function Rename-WmiNamespace
Export-ModuleMember -Function Rename-WmiClass

Export-ModuleMember -Function Set-WmiClassQualifier
Export-ModuleMember -Function Set-WmiPropertyQualifier
Export-ModuleMember -Function Set-WmiInstance
#Export-ModuleMember -Function Set-WmiInstance

#endregion
##*=============================================
Expand Down

0 comments on commit 5acb6f6

Please sign in to comment.