Compare commits

..
3 Commits
Author SHA1 Message Date
dyoder c753b13f1e use new funcs in Tools.ps1 2024-06-24 16:51:50 -04:00
dyoder b5bfe4b814 use new funcs in Tools.ps1 2024-06-24 16:51:40 -04:00
dyoder 907ee882bf added funcs for working with tickets 2024-06-24 16:51:19 -04:00
3 changed files with 45 additions and 29 deletions
+4 -15
View File
@@ -18,21 +18,11 @@ For ($i = 0; $i -lt 1200; $i++) {
If ( !(Test-Path $BSODReport) ) { Write-Output "BSOD report was not found: ${BSODReport}" ; Return } If ( !(Test-Path $BSODReport) ) { Write-Output "BSOD report was not found: ${BSODReport}" ; Return }
# Create ticket # Create ticket
Try { $BSODReportContent = $(Get-Content -Path $BSODReport) -join "`n"
Import-Module $env:SyncroModule -WarningAction SilentlyContinue New-RMMTicket -Subject "System Crash on ${Env:COMPUTERNAME}" -InitialIssue $BSODReportContent
$BSODReportContent = Get-Content -Path $BSODReport
$TicketSubject = 'System Crash on ' + $Env:COMPUTERNAME
$TicketIssueType = 'Remote Support'
$TicketStatus = 'New'
$TicketComment = $BSODReportContent -join "`n"
$TicketData = Create-Syncro-Ticket -Subject $TicketSubject -IssueType $TicketIssueType -Status $TicketStatus
$TicketID = $TicketData.ticket.id
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Issue" -Body $TicketComment -Hidden $true -DoNotEmail $true
}
Catch { Write-Error "Error creating ticket" ; Return }
# Update the ticket # Update the ticket
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body "It looks like your computer crashed. I'll get this resolved as soon as possible." -Hidden $false -DoNotEmail $false New-TicketComment -Comment "It looks like your computer crashed. I'll get this resolved as soon as possible."
# Wait a bit # Wait a bit
Start-Sleep -Seconds 120 Start-Sleep -Seconds 120
@@ -49,9 +39,8 @@ $StartAt = (Get-Date).AddMinutes(-$BillableTimeInMinutes).ToString("o")
Switch ( $CulpritProvider ) { Switch ( $CulpritProvider ) {
{ $_ -match $ProviderMicrosoft } { { $_ -match $ProviderMicrosoft } {
$TicketComment = "I've analyzed the crash report and it indicates a problem with a Windows component. I'll repair the system now." New-TicketComment -Comment "I've analyzed the crash report and it indicates a problem with a Windows component. I'll repair the system now."
$TimeEntryNote = "Analysis indicates crash caused by Windows component(s). Scanning and repairing corruption in the system." $TimeEntryNote = "Analysis indicates crash caused by Windows component(s). Scanning and repairing corruption in the system."
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body $TicketComment -Hidden $false -DoNotEmail $false
Create-Syncro-Ticket-TimerEntry -TicketIdOrNumber $TicketID -StartTime $StartAt -DurationMinutes $BillableTimeInMinutes -Notes $TimeEntryNote -UserIdOrEmail $TimeAttributedToUser -ChargeTime "true" Create-Syncro-Ticket-TimerEntry -TicketIdOrNumber $TicketID -StartTime $StartAt -DurationMinutes $BillableTimeInMinutes -Notes $TimeEntryNote -UserIdOrEmail $TimeAttributedToUser -ChargeTime "true"
$FixWindowsHealth = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Fix-WindowsHealth.ps1' $FixWindowsHealth = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Fix-WindowsHealth.ps1'
Start-Sleep -Seconds 120 Start-Sleep -Seconds 120
+6 -14
View File
@@ -1,5 +1,5 @@
# Check the RMM runtime variable to see if it's set to 'null', if not then set the $TicketID # Check the RMM runtime variable to see if it's set to 'null', if not then set the $TicketID
If ( $TicketNumber.Trim().ToLower() -ne 'null' ) { Import-Module $env:SyncroModule -WarningAction SilentlyContinue ; $TicketID = $TicketNumber.Trim() } If ( $TicketNumber.Trim().ToLower() -ne 'null' ) { $Global:TicketNumber = $TicketNumber.Trim() }
# Run SFC to check the filesystem, convert the result from Unicode to UTF8, delete the intermediate $tempFile # Run SFC to check the filesystem, convert the result from Unicode to UTF8, delete the intermediate $tempFile
$tempFile = New-TemporaryFile $tempFile = New-TemporaryFile
@@ -10,7 +10,7 @@ $TicketComment = "SFC Output:`n"
ForEach ( $line in $SFCOutput ) { ForEach ( $line in $SFCOutput ) {
If ( $line -notmatch 'Verification \d{1,2}% complete' ) { $TicketComment = $TicketComment + $line + "`n" } If ( $line -notmatch 'Verification \d{1,2}% complete' ) { $TicketComment = $TicketComment + $line + "`n" }
} }
If ( $TicketID ) { Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body $TicketComment -Hidden $true -DoNotEmail $true } New-TicketComment -Comment $TicketComment -Hidden -DoNotEmail
Remove-Item $tempFile -Force -ErrorAction SilentlyContinue Remove-Item $tempFile -Force -ErrorAction SilentlyContinue
# Examine $SFCOutput for integrity violations, if found make sure chkdsk runs at the next boot # Examine $SFCOutput for integrity violations, if found make sure chkdsk runs at the next boot
@@ -47,17 +47,9 @@ Else { Write-Output "Online image cleanup and restoration is only supported on W
If ( $ScheduleCheckDisk ) { If ( $ScheduleCheckDisk ) {
Write-Output "Scheduling disk repair at next boot" Write-Output "Scheduling disk repair at next boot"
Start-Process "cmd.exe" -ArgumentList '/C echo y | chkdsk /F /R /X' -Wait Start-Process "cmd.exe" -ArgumentList '/C echo y | chkdsk /F /R /X' -Wait
If ( $TicketID ) { New-TicketComment -Comment "Scheduled disk repair at next boot" -Hidden -DoNotEmail
$TicketComment = "Scheduled disk repair at next boot" New-TicketComment -Comment "I've made some changes that will require you to restart your computer.`n`nWhenver you're ready, please restart your computer and allow it 30min to complete the startup process."
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body $TicketComment -Hidden $true -DoNotEmail $true
$TicketComment = "I've made some changes that will require you to restart your computer.`n`nWhenver you're ready, please restart your computer and allow it 30min to complete the startup process."
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body $TicketComment -Hidden $false -DoNotEmail $false
}
} Else { } Else {
If ( $TicketID ) { New-TicketComment -Comment "Disk check was not scheduled to run, as no Windows integrity violations were found." -Hidden -DoNotEmail
$TicketComment = "Disk check was not scheduled to run, as no Windows integrity violations were found." New-TicketComment -Comment "Your computer has been repaired. Please restart as soon as you're able."
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body $TicketComment -Hidden $true -DoNotEmail $true
$TicketComment = "Your computer has been repaired. Please restart as soon as you're able."
Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject "Update" -Body $TicketComment -Hidden $false -DoNotEmail $false
}
} }
+35
View File
@@ -12,6 +12,9 @@
# Define the root path for the MSP in the Windows Registry # Define the root path for the MSP in the Windows Registry
[string]$Global:MSPRegistryRoot = "HKEY_LOCAL_MACHINE\SOFTWARE\${MSPName}" [string]$Global:MSPRegistryRoot = "HKEY_LOCAL_MACHINE\SOFTWARE\${MSPName}"
# Create a global variable to keep a ticket number if it needs to be used by any scripts
$Global:TicketNumber = $null
# Setup the MSP management directories # Setup the MSP management directories
Function Setup-MSPDirectories { Function Setup-MSPDirectories {
If ( Test-Path ${Env:ProgramData} ) { $Global:RootDirectory = "${Env:ProgramData}\${MSPName}" } Else { $Global:RootDirectory = "${Env:SystemDrive}\${MSPName}" } If ( Test-Path ${Env:ProgramData} ) { $Global:RootDirectory = "${Env:ProgramData}\${MSPName}" } Else { $Global:RootDirectory = "${Env:SystemDrive}\${MSPName}" }
@@ -1032,6 +1035,38 @@ Function Install-LocalTools () {
} }
} }
Function Import-RMMModule () {
Try { Import-Module $env:SyncroModule -WarningAction SilentlyContinue -ErrorAction Stop }
Catch { Write-Error $_.Exception.Message ; Return }
}
Function New-RMMTicket () {
param(
[Parameter(ValueFromPipeline=$false,Mandatory=$true)][string]$Subject,
[Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$IssueType="Remote Support",
[Parameter(ValueFromPipeline=$false,Mandatory=$true)][string]$InitialIssue
)
Import-RMMModule
Try { $Ticket = Create-Syncro-Ticket -Subject $Subject -IssueType $IssueType -Status "New" }
Catch { Write-Error $_.Exception.Message ; Return }
$Global:TicketNumber = $Ticket.ticket.id
New-TicketComment -TicketID $Global:TicketNumber -Subject "Issue" -Comment $InitialIssue -Hidden -DoNotEmail
}
Function New-TicketComment () {
param(
[Parameter(ValueFromPipeline=$false,Mandatory=$false)]$TicketID=$null,
[Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Subject="Update",
[Parameter(ValueFromPipeline=$true,Mandatory=$true)][string]$Comment,
[Parameter(ValueFromPipeline=$false,Mandatory=$false)][switch]$Hidden=$false,
[Parameter(ValueFromPipeline=$false,Mandatory=$false)][switch]$DoNotEmail=$false
)
If ( ($null -eq $TicketID) -and ($null -eq $Global:TicketNumber) ) { Return }
If ( ($null -eq $TicketID) -and ($null -ne $Global:TicketNumber) ) { $TicketID = $Global:TicketNumber }
Try { Create-Syncro-Ticket-Comment -TicketIdOrNumber $TicketID -Subject $Subject -Body $Comment -Hidden $Hidden -DoNotEmail $DoNotEmail }
Catch { Write-Error $_.Exception.Message ; Return }
}
Setup-MSPDirectories Setup-MSPDirectories
Setup-LogFile Setup-LogFile
Install-LocalTools Install-LocalTools