Search code examples
powershellget-eventlog

Powershell Get-EventLog how to strip out Caller Computer Name into a variable


I want to grab the value listed under "Caller Computer Name" and put it in a variable so that I can use it to get the IP address of the computer in another command.

This is the code I am using to pull the data:

$event= Get-EventLog -LogName Security -ComputerName $DC -InstanceId 4740 -Newest 1

Solution

  • You can access the property MachineName directly like this:

    $machine_name= (Get-EventLog -LogName Security -ComputerName $DC -InstanceId 4674 -Newest 1).MachineName