Updated
This commit is contained in:
parent
ef0c35fcef
commit
972ef5eeb7
1 changed files with 15 additions and 38 deletions
|
|
@ -1,43 +1,20 @@
|
||||||
# ==========================================
|
# Check if a Name variable was passed from the calling script
|
||||||
# 1. Setup Variables (Fix for missing vars)
|
# If not, generate a default name (e.g., for manual use or other scripts)
|
||||||
# ==========================================
|
if (-not $Name) {
|
||||||
$TicketNumber = "INC-12345" # Your Ticket Number
|
$Name = "RestorePoint-$(Get-Date -Format 'yyyy-MM-dd-HHmmss')"
|
||||||
$ScriptStartTime = Get-Date # Current DateTime object
|
|
||||||
$LogFile = "C:\Logs\QuestCleanup.log" # Path to your log file
|
|
||||||
$ScriptResult = @{} # Initialize the result hashtable
|
|
||||||
|
|
||||||
# (Optional) Define Write-Log if it is not available in your environment
|
|
||||||
function global:Write-Log {
|
|
||||||
param(
|
|
||||||
[string]$Message,
|
|
||||||
[string]$Level = "INFO"
|
|
||||||
)
|
|
||||||
"$Level - $Message"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 2. Main Script Logic
|
|
||||||
# ==========================================
|
|
||||||
|
|
||||||
$RestorePointName = "QUEST-CLEANUP-$($TicketNumber -replace '[^A-Za-z0-9]', '')-$($ScriptStartTime.ToString('yyyy-MM-dd'))"
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Log "Creating initial restore point: $RestorePointName"
|
# Create the restore point using the $Name variable
|
||||||
|
Checkpoint-Computer -Description $Name -RestorePointType "Application" -ErrorAction Stop
|
||||||
# Requires Admin Rights and System Restore enabled
|
$status = "Success"
|
||||||
Checkpoint-Computer -Description $RestorePointName -ErrorAction Stop
|
} catch {
|
||||||
|
$status = "Failed: $($_.Exception.Message)"
|
||||||
$ScriptResult.restore_point_initial.created = $true
|
|
||||||
$ScriptResult.restore_point_initial.name = $RestorePointName
|
|
||||||
Write-Log "Initial restore point created successfully."
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
$ErrorMsg = "Failed to create initial restore point: $($_.Exception.Message)"
|
|
||||||
$ScriptResult.restore_point_initial.error = $ErrorMsg
|
|
||||||
Write-Log $ErrorMsg -Level "ERROR"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Log "Initial restore point section completed."
|
# Return the result as JSON (the main script expects JSON)
|
||||||
|
@{
|
||||||
# Appends a blank line to the log file
|
Name = $Name
|
||||||
"" | Out-File -FilePath $LogFile -Append -Encoding UTF8
|
Status = $status
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
} | ConvertTo-Json
|
||||||
Loading…
Add table
Add a link
Reference in a new issue