Windows 10: UIAutomation Events on Powershell

Discus and support UIAutomation Events on Powershell in Windows 10 BSOD Crashes and Debugging to solve the problem; I'm trying to listen UIAutomation events using Powershell, and wrote somethings like this. $propChangeHandler=... Discussion in 'Windows 10 BSOD Crashes and Debugging' started by richardchung, May 20, 2020.

  1. UIAutomation Events on Powershell


    I'm trying to listen UIAutomation events using Powershell, and wrote somethings like this.



    $propChangeHandler= [System.Windows.Automation.AutomationPropertyChangedEventHandler]# <summary># Adds a handler for property-changed event in particular, a change in the enabled state.# </summary># <param name="element">The UI Automation element whose state is being monitored.</param>function Subscribe-PropertyChange{param[System.Windows.Automation.AutomationElement]$element[System.Windows.Automation.Automation]::AddAutomationPropertyChangedEventHandler$element, [System.Windows.Automation.TreeScope]::Element, $propChangeHandler$OnPropertyChange, [System.Windows.Automation]::AutomationElement.IsEnabledProperty}# <summary># Handler for property changes.# </summary># <param name="src">The source whose properties changed.</param># <param name="e">Event arguments.</param>$OnPropertyChange={param[System.Object]$src, [System.Windows.Automation.AutomationPropertyChangedEventArgs]$e [System.Windows.Automation.AutomationElement]$sourceElement = $src -as [System.Windows.Automation.AutomationElement] if $e.Property -eq [System.Windows.Automation.AutomationElement]::IsEnabledProperty { [System.Boolean]$enabled = $e.NewValue -as [System.Boolean] # TODO: Do something with the new value. # The element that raised the event can be identified by its runtime ID property. Write-Host"{0} is Enable" -f $sourceElement.Current.Name } else { # TODO: Handle other property-changed events. }}function Unsubscribe-PropertyChange{param[System.Windows.Automation.AutomationElement]$element if $propChangeHandler -ne $null { [System.Windows.Automation.Automation]::RemoveAutomationPropertyChangedEventHandler$element, $propChangeHandler }}



    But I got a problem.

    The AddautomationPropertyChangedEventHandlermethod will need a AutomationPropertyChangedEventHandler with an eventHandler as parameter as parameter, but both AutomationPropertyChangedEventHandler and eventHandler are functions.

    That means functionfunctionfunction

    Please find the $propChangeHandler$OnPropertyChange from the above code.

    Obviously writing it as $propChangeHandler$OnPropertyChange is not correct. How can I revise?

    :)
     
    richardchung, May 20, 2020
    #1
  2. ddelo Win User

    Export All Administrative Events to Excel

    To analyze events, from the Windows Event Viewer, there is a simple way to export all Administrative Events to Excel, with PowerShell.

    Exporting all Administrative Events to Excel is a simple two Step process, as described here:

    Step 1 - Create the Administrative Events View .xml file
    1. Open Eventviewer (%windir%\system32\eventvwr.msc)
    2. Navigate to: Event Viewer (Local) > Custom Views > Administrative Events
    3. In the “Actions” pane select “Filter Current Custom View”.
    4. Select the the XML tab.
    5. Press Ctrl+A to select all the XML code of the Custom View.
    6. Open a notepad, paste the selected code and save the file to your Desktop as AdmEvtView.xml


    Step 2 - Create the csv file with the events
    1. Download the ExportEvtCSV.zip file, which contains the script ExportEvtCSV.ps1 and unzip it, on your Desktop.
      It's not a fancy script, just basic PowerShell commands to create a csv file on the Desktop.
    2. In Windows Search, type “ISE” (without the quotes) to open “Windows PowerShell ISE” and Run as administrator
    3. To allow running the script, change the ExecutionPolicy, for this session. To do that, in the Console pane type:
      Code:
    4. In the Windows PowerShell ISE, open and run the script: ExportEvtCSV.ps1
      The script will create a csv file with a name YYYYMMDD.HHMM.csv on the Desktop
    5. When done, open the newly created .csv file, format the columns as needed and optionally save it as .xlsx, if you wish.
    That’s it! You now have all the Administrative Events in Excel for filtering and further analysis. UIAutomation Events on Powershell :)

    Now to the more technical hard stuff... *Confused

    There is a reason for running the script from within PowerShell ISE!

    It would be great if everything was also working perfectly, when running the script from an elevated PowerShell too.

    We can run it from an elevated PowerShell, which means that you just follow the Step 1, as above but for the Step 2 instead of the ISE you run the script from an elevated PowerShell.

    The problem is that it will work only for anybody who has en-US format for the dates. Everyone else, who has another format (i.e. en-GB, fr-FR, el-GR etc.), the dates are not translated properly by Excel (although the script uses the –UseCulture switch) and remain as text in the en-US format.

    I'm not sure if this a bug of the "export-csv" cmdlet, but although it runs the way it supposed to from within the ISE, from PowerShell there is a problem with the dates format.
    As I haven’t found a way to overcome this obstacle, any suggestion from the PowerShell gurus of the forum (like my good friend Shawn @Brink, for instance), is welcome.
     
    ddelo, May 20, 2020
    #2
  3. angstar Win User
    angstar, May 20, 2020
    #3
  4. Drone Win User

    UIAutomation Events on Powershell

    PowerShell is open sourced and is available on Linux/macOS

    Little bit late .. PowerShell's 10th anniversary (Nov. 14)
     
    Drone, May 20, 2020
    #4
Thema:

UIAutomation Events on Powershell

Loading...
  1. UIAutomation Events on Powershell - Similar Threads - UIAutomation Events Powershell

  2. Please Help- PowerShell Events in Event Viewer That Haven't Really Happened Before

    in Windows 10 Gaming
    Please Help- PowerShell Events in Event Viewer That Haven't Really Happened Before: in Event Viewer, under Applications and Services > Windows PowerShell, there are some events that took place a little after I logged on this morning I logged on around 8:55am, and these events happened at 8:58am there are 7 instances of each 'Provider [x] is started';...
  3. Please Help- PowerShell Events in Event Viewer That Haven't Really Happened Before

    in Windows 10 Software and Apps
    Please Help- PowerShell Events in Event Viewer That Haven't Really Happened Before: in Event Viewer, under Applications and Services > Windows PowerShell, there are some events that took place a little after I logged on this morning I logged on around 8:55am, and these events happened at 8:58am there are 7 instances of each 'Provider [x] is started';...
  4. Please Help- PowerShell Events in Event Viewer That Haven't Really Happened Before

    in AntiVirus, Firewalls and System Security
    Please Help- PowerShell Events in Event Viewer That Haven't Really Happened Before: in Event Viewer, under Applications and Services > Windows PowerShell, there are some events that took place a little after I logged on this morning I logged on around 8:55am, and these events happened at 8:58am there are 7 instances of each 'Provider [x] is started';...
  5. Azure AD sync information in Powershell/Event Viewer

    in Windows 10 Software and Apps
    Azure AD sync information in Powershell/Event Viewer: Hello CommunityWhen you search for "Access Work or School" in windows start menu you get list of all AzureAD links tied to account, clicking on entry in list shows Info button under which you can find bunch of information like enforced policies, timedate of last sync and...
  6. PowerShell event log that happens every month.

    in Windows 10 Gaming
    PowerShell event log that happens every month.: Why is this event log happening every month?Should I be worried?My os is Windows 10 Home It happens in PowerShell/operational logTask Category: Execute a remote commandCreating Scriptblock text 1 of 1:# Copyright © 2008, Microsoft Corporation. All rights reserved.#Common...
  7. PowerShell event log that happens every month.

    in Windows 10 Software and Apps
    PowerShell event log that happens every month.: Why is this event log happening every month?Should I be worried?My os is Windows 10 Home It happens in PowerShell/operational logTask Category: Execute a remote commandCreating Scriptblock text 1 of 1:# Copyright © 2008, Microsoft Corporation. All rights reserved.#Common...
  8. PowerShell event log that happens every month.

    in AntiVirus, Firewalls and System Security
    PowerShell event log that happens every month.: Why is this event log happening every month?Should I be worried?My os is Windows 10 Home It happens in PowerShell/operational logTask Category: Execute a remote commandCreating Scriptblock text 1 of 1:# Copyright © 2008, Microsoft Corporation. All rights reserved.#Common...
  9. Powershell event log

    in AntiVirus, Firewalls and System Security
    Powershell event log: I have many of these in my event logs : POWERSHELL...task category execute a remote command :Creating Scriptblock text 1 of 1:# Copyright © 2008, Microsoft Corporation. All rights reserved.#Common utility functionsImport-LocalizedData -BindingVariable localizationString...
  10. Multiple "Powershell has stopped working" events

    in Windows 10 Support
    Multiple "Powershell has stopped working" events: A friend is getting many Powershell errors [img] Often 20 or more interruptions per session. The Application Event log shows many sets of 4 events Error 22/03/2018 13:05:08 Application Error 1000 (100) Error 22/03/2018 13:05:08 Application Error 1000 (100) Error...