Update samy.ps1
This commit is contained in:
81
samy.ps1
81
samy.ps1
@@ -381,19 +381,78 @@ $ConfirmPreference = 'None'
|
||||
}
|
||||
}
|
||||
|
||||
function Repair-SVSMspEventLogBinding {
|
||||
param(
|
||||
[string]$EventSource = "SVSMSP_Module",
|
||||
[string]$TargetLog = "SVSMSP Events"
|
||||
)
|
||||
|
||||
Write-LogHybrid "Checking Event Log binding for source '$EventSource'..." Info SVSModule -LogToEvent
|
||||
|
||||
# 1) Make sure the source exists
|
||||
try {
|
||||
if (-not [System.Diagnostics.EventLog]::SourceExists($EventSource)) {
|
||||
Write-LogHybrid "Event source '$EventSource' not found. Nothing to repair." Info SVSModule -LogToEvent
|
||||
return
|
||||
}
|
||||
|
||||
$currentLog = [System.Diagnostics.EventLog]::LogNameFromSourceName($EventSource, '.')
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Failed to query Event Log binding for '$EventSource': $($_.Exception.Message)" Warning SVSModule -LogToEvent
|
||||
return
|
||||
}
|
||||
|
||||
if (-not $currentLog) {
|
||||
Write-LogHybrid "Could not determine current log for event source '$EventSource'. Skipping repair." Warning SVSModule -LogToEvent
|
||||
return
|
||||
}
|
||||
|
||||
# 2) If it's already correct, bail out
|
||||
if ($currentLog -eq $TargetLog) {
|
||||
Write-LogHybrid "Event source '$EventSource' already bound to '$TargetLog'." Info SVSModule -LogToEvent
|
||||
return
|
||||
}
|
||||
|
||||
Write-LogHybrid "Rebinding event source '$EventSource' from '$currentLog' to '$TargetLog'..." Warning SVSModule -LogToEvent
|
||||
|
||||
# 3) Delete and recreate the source bound to the desired log
|
||||
try {
|
||||
[System.Diagnostics.EventLog]::DeleteEventSource($EventSource)
|
||||
|
||||
if (-not [System.Diagnostics.EventLog]::Exists($TargetLog)) {
|
||||
New-EventLog -LogName $TargetLog -Source $EventSource -ErrorAction Stop
|
||||
}
|
||||
else {
|
||||
New-EventLog -LogName $TargetLog -Source $EventSource -ErrorAction Stop
|
||||
}
|
||||
|
||||
Write-LogHybrid "Event source '$EventSource' rebound to '$TargetLog'." Success SVSModule -LogToEvent
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Failed to rebind event source '$EventSource' to log '$TargetLog': $($_.Exception.Message)" Error SVSModule -LogToEvent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Perform-ToolkitInstallation {
|
||||
Initialize-NuGetProvider
|
||||
Perform-Cleanup
|
||||
Write-LogHybrid "Registering repo $NewRepositoryName…" "Info" "SVSModule" -LogToEvent
|
||||
if (-not (Get-PSRepository -Name $NewRepositoryName -ErrorAction SilentlyContinue)) {
|
||||
Register-PSRepository -Name $NewRepositoryName -SourceLocation $NewRepositoryURL -InstallationPolicy Trusted
|
||||
}
|
||||
Write-LogHybrid "Installing module $NewModuleName…" "Info" "SVSModule" -LogToEvent
|
||||
Install-Module -Name $NewModuleName -Repository $NewRepositoryName -Scope AllUsers -Force
|
||||
Write-LogHybrid "Toolkit installation complete." "Success" "SVSModule" -LogToEvent
|
||||
}
|
||||
function Perform-ToolkitInstallation {
|
||||
Initialize-NuGetProvider
|
||||
Perform-Cleanup
|
||||
|
||||
Write-LogHybrid "Registering repo $NewRepositoryName…" "Info" "SVSModule" -LogToEvent
|
||||
if (-not (Get-PSRepository -Name $NewRepositoryName -ErrorAction SilentlyContinue)) {
|
||||
Register-PSRepository -Name $NewRepositoryName -SourceLocation $NewRepositoryURL -InstallationPolicy Trusted
|
||||
}
|
||||
|
||||
Write-LogHybrid "Installing module $NewModuleName…" "Info" "SVSModule" -LogToEvent
|
||||
Install-Module -Name $NewModuleName -Repository $NewRepositoryName -Scope AllUsers -Force
|
||||
|
||||
# After module install, repair Event Log binding for legacy systems
|
||||
Repair-SVSMspEventLogBinding -EventSource "SVSMSP_Module" -TargetLog "SVSMSP Events"
|
||||
|
||||
Write-LogHybrid "Toolkit installation complete." "Success" "SVSModule" -LogToEvent
|
||||
}
|
||||
|
||||
|
||||
Write-LogHybrid "Install-SVSMSP called" "Info" "SVSModule" -LogToEvent
|
||||
if ($Cleanup) {
|
||||
|
||||
Reference in New Issue
Block a user