PowerShell - Export all Devices and their details to .CSV
Export all Devices and their details to .CSV
Script Events:
- Connect to the server
- Discover all devices
- Create a Thinscale folder in C:\Temp unless specified otherwise
- Export the details into .CSV with date and time stamp
Log example:
Usage
1. Right-click the link and choose Save As to download the Export-DeviceData.ps1 file: Export-DeviceData.ps1
2. Import it and run it like so:
Results:
Script
Script:
import-module ThinScaleManagement
$creds = Get-Credential
$server = 'ServerURI' #specify Server URI
$Filepath = 'C:\Temp\Thinscale' # Specify export folder for the csv
$date = get-date -UFormat "%d-%a-%Y--%H-%M"
Connect-TSTMGMTServer -Uri $server -Credentials $creds
$Devices = Get-TSTMGMTDevices | Select ObjectId, FolderId, @{n='FolderName';e={(Get-TSTMGMTFolder -FolderId $_.FolderId).FolderName}}, DeviceName, ProductType, ProductVersion, LastBootTime, LastHeardFrom, LastUsed, LastUser
### create logs in C:\Temp\ThinScale
New-Item -Path $Filepath -ItemType Directory -Force -Confirm:$false
$log = $Devices | export-csv $Filepath\Devices_$date.csv -NoTypeInformation
Write-Host "Done" -ForegroundColor Cyan
Delete