About80Ninjas icon

Get-VDARegistration

About80Ninjas | PRO | 01/08/16 01:57:32 PM UTC | 0 ⭐ | 381 👁️ | Never ⏰ | []
PowerShell |

1.96 KB

|

None

|

0 👍

/

0 👎

#requires -Version 2
Function Get-VDARegistration{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [String[]]
        $ComputerName,
        
        [switch]
        $ShowMessage
    )
    process{
        foreach($Computer in $ComputerName){
            $VDAEvent = Get-WinEvent -ErrorAction SilentlyContinue -MaxEvents 100 -ComputerName $Computer -FilterHashtable @{
                logname = 'application'
                id      = 1012
            } | Sort-Object -Property eventID
            
            If ($VDAEvent){
                $VDAMessage = $VDAEvent.Message|
                Select-String -Pattern 'registered'|
                Select-Object -First 1
                
                If(($VDAMessage | Select-String -Pattern 'successfully')){
                    if($ShowMessage.IsPresent){
                        $props = @{
                            'Message'  = $VDAMessage
                            'Registered' = $true
                        }
                        $obj = New-Object -TypeName PSObject -Property $props
                        Write-Output -InputObject $obj
                    }
                    else{
                        Write-Output -InputObject $true
                    }
                }#end if VDALog.Message
                else{
                    if($ShowMessage.IsPresent){
                        $props = @{
                            'Message'  = $VDAMessage
                            'Registered' = $false
                        }
                        $obj = New-Object -TypeName PSObject -Property $props
                        Write-Output -InputObject $obj
                    }
                    else{
                        Write-Output -InputObject $false
                    }
                }#end else VDALog.Message
            }#end if VDALog
        }#end foreach Computer
    }#end process
}#end function Get-VDARegistration

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎