PowerEvents.psm1
function Write-Introduction() { Write-Host "Thank you for installing the $($PowerEvents.ModuleName) module!" Write-Host "".PadLeft(40, "=") } # TODO: Build a Windows Installer (MSI) package for PowerEvents # Define the name of the module # Build a hashtable with basic properties for use elsewhere in the module $Global:PowerEvents = @{ ModuleName = "PowerEvents" } Write-Host "Loading PowerShell module: $($PowerEvents.ModuleName)" #region Check admin rights # Check if user token is an administrator ${Identity} = [System.Security.Principal.WindowsIdentity]::GetCurrent() ${Principal} = new-object System.Security.Principal.WindowsPrincipal(${Identity}) ${IsAdmin} = $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) if (-not ${IsAdmin}) { Write-Error -Message "User is not an administrator. Module installation cannot continue." -RecommendedAction "Please install this module as an administrator." Export-ModuleMember # Remove-Module $PowerEvents.ModuleName return } #endregion Check admin rights #region Get script path $MyInvocation.MyCommand.Path ${ScriptPath} = Split-Path $MyInvocation.MyCommand.Path #Write-Host "Script path is: ${ScriptPath}" #endregion #region Dot-source cmdlet scripts # Dot-source supporting scripts try { . ${ScriptPath}\Functions\New-WmiEventFilter.ps1 . ${ScriptPath}\Functions\New-WmiEventConsumer.ps1 . ${ScriptPath}\Functions\New-WmiFilterToConsumerBinding.ps1 # . ${ScriptPath}\Functions\Get-WmiEventConsumer.ps1 # . ${ScriptPath}\Functions\Get-WmiEventFilter.ps1 # . ${ScriptPath}\Functions\Get-WmiFilterToConsumerBinding.ps1 } catch { throw "$($PowerEvents.ModuleName): Error occurred while loading module functions." } #endregion # Call the function to write some help to the screen # TODO: Implement this function. Commenting out for initial release # Write-Introduction Write-Host "Finished loading PowerShell module: $($PowerEvents.ModuleName)" # TODO: Create a module manifest <# New-ModuleManifest ` -Author 'Trevor Sullivan' ` -CmdletsToExport * ` -FileList $(Get-ChildItem *) ` -Copyright 'Trevor Sullivan' ` -CompanyName 'Trevor Sullivan' #> |