MyITGuy
11/25/2016 - 7:07 PM

PowerShell: Test-SMPSnapshotXMLType

PowerShell: Test-SMPSnapshotXMLType

#Test-SMPSnapshotXMLType
#clear; Get-ChildItem -Path "$env:WINDIR\Temp\*" | select Name,@{Name="SMPXMLType";Expression={.\Test-SMPSnapshotXMLType.ps1 $_.FullName}} | ? {$_.SMPXMLType -contains $true}
#clear; Get-ChildItem -Path "$env:WINDIR\Temp\*" | ? {(.\Test-SMPSnapshotXMLType.ps1 $_.FullName) -eq $true}
#clear; Get-ChildItem -Path "$env:WINDIR\Temp\*" -Include ?.tmp, ??.tmp, ???.tmp, ????.tmp | ? {(.\Test-SMPSnapshotXMLType.ps1 $_.FullName) -eq $true}
#clear; Get-ChildItem -Path "$env:WINDIR\Temp\*" -Include ?.tmp, ??.tmp, ???.tmp, ????.tmp | ? {(.\Test-SMPSnapshotXMLType.ps1 $_.FullName) -eq $true} | Remove-Item -WhatIf
[CmdletBinding(SupportsShouldProcess=$True,DefaultParameterSetName="None")]
PARAM(
	[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName="p1")]
	[string[]]$FullName
)

begin {
}

process {
    $FullName | % {
        $IsSMPSnapshotXmlType = $false
        if (Test-Path -Path $_ -PathType Leaf) {
            try {
                $Xml = [xml](Get-Content $_ -ErrorAction Stop)
                $SnapshotXmlType = $null
                $SnapshotXmlType = $Xml | gm -MemberType property -ErrorAction SilentlyContinue | select -ExpandProperty Name
                if (@('FolderSnapShot','SnapshotData') -contains $SnapshotXmlType) {
                    $IsSMPSnapshotXmlType = $true
                }
            } catch {
            }
        }
        if ($SnapshotXmlType) {
            @($IsSMPSnapshotXmlType, $SnapshotXmlType)
        } else {
            $IsSMPSnapshotXmlType
        }
    }
}

end {
}