Private/Get-CmXMLFile.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Get-CmXMLFile {
    param (
        [parameter(Mandatory=$True, HelpMessage="Path to file")]
            [ValidateNotNullOrEmpty()]
            [string] $Path,
        [parameter(Mandatory=$True, HelpMessage="File name")]
            [ValidateNotNullOrEmpty()]
            [string] $FileName
    )
    $xfile = Join-Path -Path $Path -ChildPath $FileName
    Write-Log -Message "(Get-CmXMLFile): $xfile" -LogFile $logfile
    try {
        $result = Import-CliXml -Path $xfile
    }
    catch {
        Write-Log -Message "File $xfile not found. No further action taken" -LogFile $logfile -Severity 3 -ShowMsg
        Write-Log -Message "Typical reasons are: interrupted data collection, permissions into SQL instance or host OS on remote systems." -LogFile $logfile -Severity 3 -ShowMsg
        Write-Log -Message "Recommend: Review Get-CMHealthCheck.log for more information." -LogFile $logfile -Severity 3 -ShowMsg
        break
    }
    Write-Output $result
}