try{
#Create Folder for Collecting Logs
if(-not (Test-Path -Path 'C:\Hexnode\Logs\LogCollection')){
$logs = New-Item 'C:\Hexnode\Logs\LogCollection' -ItemType Directory
}
#Collect Agent Logs
if((Test-Path -Path 'C:\Hexnode\Hexnode Agent\Logs\hexnodeagent.log' -PathType Leaf)){
if(-not (Test-Path -Path 'C:\Hexnode\Logs\LogCollection\AgentLogs')){
$agent = New-Item 'C:\Hexnode\Logs\LogCollection\AgentLogs' -ItemType Directory
}
Copy-Item 'C:\Hexnode\Hexnode Agent\Logs\*' -Destination 'C:\Hexnode\Logs\LogCollection\AgentLogs\'
}
#Collect Installer Logs
if((Test-Path -Path 'C:\hexnodeinstaller\hexnodeinstaller.log' -PathType Leaf)){
if(-not (Test-Path -Path 'C:\Hexnode\Logs\LogCollection\InstallerLogs')){
$installer = New-Item 'C:\Hexnode\Logs\LogCollection\InstallerLogs' -ItemType Directory
}
Copy-Item 'C:\hexnodeinstaller\*' -Destination 'C:\Hexnode\Logs\LogCollection\InstallerLogs\'
}
#Collect Updater Logs
if((Test-Path -Path 'C:\Hexnode\Hexnode Updater\Logs\hexnodeupdater.log' -PathType Leaf)){
if(-not (Test-Path -Path 'C:\Hexnode\Logs\LogCollection\UpdaterLogs')){
$updater = New-Item 'C:\Hexnode\Logs\LogCollection\UpdaterLogs' -ItemType Directory
}
Copy-Item 'C:\Hexnode\Hexnode Updater\Logs\*' -Destination 'C:\Hexnode\Logs\LogCollection\UpdaterLogs\'
}
#Collect MDMDiagnostics Reports
$mdmDiagnosticReport = MdmDiagnosticsTool.exe -area DeviceProvisioning -cab C:\Hexnode\Logs\LogCollection\MDMDiagnosticReport\Report.cab
#Create Zip
if((Test-Path -Path 'C:\Hexnode\Logs\LogCollection.zip' -PathType Leaf)){
Remove-Item -Path 'C:\Hexnode\Logs\LogCollection.zip'
}
Compress-Archive 'C:\Hexnode\Logs\LogCollection\*' -DestinationPath 'C:\Hexnode\Logs\LogCollection.zip'
if((Test-Path -Path 'C:\Hexnode\Logs\LogCollection.zip' -PathType Leaf)){
Remove-Item -Path 'C:\Hexnode\Logs\LogCollection' -Recurse
Write-Host Successfully Collected Logs at "C:\Hexnode\Logs\LogCollection.zip"
}
}
catch{
Write-Host Log Collection Failed : $_.Exception.Message
}