Skip to content

Commit

Permalink
Log Version used in Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
VertigoRay committed Jan 10, 2023
1 parent a520ffb commit a7710f6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions PSWriteLog/PSWriteLog.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ foreach ($import in $ps1s) {
# The PSD1 is generated from the build pipeline.
#endregion
$psd1 = Import-PowerShellDataFile ([IO.Path]::Combine($PSScriptRoot, 'PSWriteLog.psd1'))

# Check if the current context is elevated (Are we running as an administrator?)
if ((New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
# Anytime this Module is used, the version and timestamp will be stored in the registry.
# This will allow more intelligent purging of unused versions.
$versionUsed = @{
LiteralPath = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\VertigoRay\PSWriteLog\VersionsUsed'
Name = $psd1.ModuleVersion
Value = (Get-Date -Format 'O')
Force = $true
}
Write-Debug ('Version Used: {0}' -f ($versionUsed | ConvertTo-Json))
if (-not (Test-Path $versionUsed.LiteralPath)) {
New-Item -Path $versionUsed.LiteralPath –Force
}
Set-ItemProperty @versionUsed
}

$moduleMember = @{
Cmdlet = $psd1.CmdletsToExport
Function = $psd1.FunctionsToExport
Expand Down

0 comments on commit a7710f6

Please sign in to comment.