Advertisement
About80Ninjas

Get-VDARegistration

Jan 8th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #requires -Version 2
  2. Function Get-VDARegistration{
  3.     [CmdletBinding()]
  4.     param(
  5.         [Parameter(Mandatory = $true)]
  6.         [String[]]
  7.         $ComputerName,
  8.        
  9.         [switch]
  10.         $ShowMessage
  11.     )
  12.     process{
  13.         foreach($Computer in $ComputerName){
  14.             $VDAEvent = Get-WinEvent -ErrorAction SilentlyContinue -MaxEvents 100 -ComputerName $Computer -FilterHashtable @{
  15.                 logname = 'application'
  16.                 id      = 1012
  17.             } | Sort-Object -Property eventID
  18.            
  19.             If ($VDAEvent){
  20.                 $VDAMessage = $VDAEvent.Message|
  21.                 Select-String -Pattern 'registered'|
  22.                 Select-Object -First 1
  23.                
  24.                 If(($VDAMessage | Select-String -Pattern 'successfully')){
  25.                     if($ShowMessage.IsPresent){
  26.                         $props = @{
  27.                             'Message'  = $VDAMessage
  28.                             'Registered' = $true
  29.                         }
  30.                         $obj = New-Object -TypeName PSObject -Property $props
  31.                         Write-Output -InputObject $obj
  32.                     }
  33.                     else{
  34.                         Write-Output -InputObject $true
  35.                     }
  36.                 }#end if VDALog.Message
  37.                 else{
  38.                     if($ShowMessage.IsPresent){
  39.                         $props = @{
  40.                             'Message'  = $VDAMessage
  41.                             'Registered' = $false
  42.                         }
  43.                         $obj = New-Object -TypeName PSObject -Property $props
  44.                         Write-Output -InputObject $obj
  45.                     }
  46.                     else{
  47.                         Write-Output -InputObject $false
  48.                     }
  49.                 }#end else VDALog.Message
  50.             }#end if VDALog
  51.         }#end foreach Computer
  52.     }#end process
  53. }#end function Get-VDARegistration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement