Skip to content

Commit

Permalink
remoting
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejs4 committed Nov 25, 2021
1 parent ecc8f1e commit 2f76d81
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions INTUNE/ConvertFrom-MDMDiagReportXML.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Function for converting Intune XML report generated by MdmDiagnosticsTool.exe to a PowerShell object.
There is also option to generate HTML report instead.
.PARAMETER computerName
(optional) Computer name from which you want to get data from.
.PARAMETER MDMDiagReport
Path to MDMDiagReport.xml.
Expand Down Expand Up @@ -52,6 +55,8 @@

[CmdletBinding()]
param (
[string] $computerName,

[ValidateScript( {
if ($_ -match "\.xml$") {
$true
Expand Down Expand Up @@ -91,6 +96,10 @@
[Void][System.IO.Directory]::CreateDirectory((Split-Path $HTMLReportPath -Parent))
}

if ($computerName) {
$session = New-PSSession -ComputerName $computerName -ErrorAction Stop
}

if (!$MDMDiagReport) {
++$reportNotSpecified
$MDMDiagReport = "$env:PUBLIC\Documents\MDMDiagnostics\MDMDiagReport.xml"
Expand All @@ -100,8 +109,24 @@

# generate XML report if necessary
if ($reportNotSpecified) {
Write-Verbose "Generating '$MDMDiagReport'..."
Start-Process MdmDiagnosticsTool.exe -Wait -ArgumentList "-out `"$MDMDiagReportFolder`"" -NoNewWindow
if ($computerName) {
# XML report is on remote computer, transform to UNC path
$MDMDiagReport = "\\$computerName\$($MDMDiagReport -replace ":", "$")"
Write-Verbose "Generating '$MDMDiagReport'..."

try {
Invoke-Command -Session $session {
param ($MDMDiagReportFolder)

Start-Process MdmDiagnosticsTool.exe -Wait -ArgumentList "-out `"$MDMDiagReportFolder`"" -NoNewWindow -ErrorAction Stop
} -ArgumentList $MDMDiagReportFolder -ErrorAction Stop
} catch {
throw "Unable to generate XML report`nError: $($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)"
}
} else {
Write-Verbose "Generating '$MDMDiagReport'..."
Start-Process MdmDiagnosticsTool.exe -Wait -ArgumentList "-out `"$MDMDiagReportFolder`"" -NoNewWindow
}
}
if (!(Test-Path $MDMDiagReport -PathType Leaf)) {
Write-Verbose "'$MDMDiagReport' doesn't exist, generating..."
Expand Down Expand Up @@ -154,7 +179,20 @@
return 'Device'
} elseif ($id -match "^S-1-5-21") {
# it is local account
return ((New-Object System.Security.Principal.SecurityIdentifier($id)).Translate([System.Security.Principal.NTAccount])).Value
if ($computerName) {
Invoke-Command -Session $session {
param ($id)

$ErrorActionPreference = "Stop"
try {
return ((New-Object System.Security.Principal.SecurityIdentifier($id)).Translate([System.Security.Principal.NTAccount])).Value
} catch {
throw 1
}
} -ArgumentList $id
} else {
return ((New-Object System.Security.Principal.SecurityIdentifier($id)).Translate([System.Security.Principal.NTAccount])).Value
}
} else {
# it is AzureAD account
if ($getDataFromIntune) {
Expand Down Expand Up @@ -862,4 +900,8 @@
}
}
#endregion convert results to HTML and output

if ($computerName) {
Remove-PSSession $session
}
}

0 comments on commit 2f76d81

Please sign in to comment.