PowerShell - Export devices with log types

PowerShell - Export devices with log types

Written by Fernando

Last published at: August 8th, 2023

If you would like to export all devices with their log types, please use the below PowerShell script:

Import-Module ThinScaleManagement

$URI = "your_server_uri/tstmgmt"    # Enter URI
Connect-TSTMGMTServer -Uri $URI -Credentials (Get-Credential)

Get-TSTMGMTRefreshData

#Output Location
$location = "$env:SystemDrive\folder"    # Enter path where the csv file will be saved to
$file = "filename.csv"    # Enter desire file name eding with .csv

$date = (Get-Date -Format "MM-dd-yyyy_HH-mm-ss_" )     # Date for unique file creation
$filename =  $date + $file     # Filename for the export

$devices = Get-TSTMGMTDevices | Select-Object devicename,objectid
foreach ($d in $devices)
{
    $export = Get-TSTMGMTLogsEvent -DeviceId $d.ObjectId | select type,@{n="DeviceName";e={$d.devicename}},datetime | where { 
        ($_.type -like "Connect") -or 
        ($_.Type -like "Disconnect") -or
        ($_.Type -like "Lock") -or
        ($_.Type -like "Unlock") -or
        ($_.Type -like "Unlock Attempt Fail") -or
        ($_.type -like "GUI Start") -or 
        ($_.type -like "GUI End") -or 
        ($_.type -like "Device Login") -or 
        ($_.type -like "Device Logoff") -or
        ($_.Type -like "ConnectorLogin") -or
        ($_.Type -like "Connector Logoff") -or 
        ($_.Type -like "Connector Resource List") -or
        ($_.Type -like "Connector Errors") -or
        ($_.Type -like "Resource Launch") -or 
        ($_.Type -like "Resource End") -or
        ($_.Type -like "Resource Launch Fail") -or 
        ($_.Type -like "Active Profile") -or 
        ($_.Type -like "Browser Link Select") -or
        ($_.Type -like "LDAP Password Change") -or
        ($_.Type -like "Power Action") -or
        ($_.Type -like "Security Center Status") -or
        ($_.Type -like "Windows Update Status") -or
        ($_.Type -like "Windows Firewall Status") -or
        ($_.Type -like "WiFi Adapter Status") -or
        ($_.Type -like "VM Detection Status") -or
        ($_.Type -like "Process ACtion Apply") -or
        ($_.Type -like "Process Action Release") -or
        ($_.Type -like "Local Application Launch") -or
        ($_.Type -like "AEP Allow") -or
        ($_.Type -like "AEP Deny") -or
        ($_.Type -like "Session Action Apply") -or
        ($_.Type -like "Session Action Release") -or
        ($_.Type -like "SEP Start") -or
        ($_.Type -like "SEP Stop") -or
        ($_.Type -like "SEP Notify") -or
        ($_.Type -like "Legacy Validation Tool Results") -or
        ($_.Type -like "DEPRECATED") -or
        ($_.Type -like "Website Blocked") -or
        ($_.Type -like "USB Device Blocked") -or
        ($_.Type -like "AMP Module Blocked") -or
        ($_.Type -like "DEP Driver Blocked") -or
        ($_.Type -like "Auth Provider Request Success") -or
        ($_.Type -like "Auth Provider Request Failed") }

    $export | Export-Csv -Path "$location\$filename" -NoTypeInformation -Force -Append
}

 

This will generate a csv file with the contents as shown below: