PowerEvents.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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'
     
#>