PowerShell - Export all Devices and their details to .CSV

Export all Devices and their details to .CSV

Written by Ines

Last published at: May 30th, 2024

Script Events:

  1. Connect to the server
  2. Discover all devices
  3. Create a Thinscale folder in C:\Temp unless specified otherwise
  4. 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:

Delete

Info

  • the Import-Module should contain the location of the Export-DeviceData.ps1 file
  • The parameter -URI is the server URI. FQDN and IP's are allowed
  • The parameter -Destination is the destination where the exported .csv file will be created. The script creates a Folder if a non-existent one is provided in this parameter.


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