Scheduled task parameter

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
obrienc
Posts: 59
Last visit: Wed Apr 20, 2022 5:43 am

Re: Scheduled task parameter

Post by obrienc »

That xml was from the collector in the ForwardedEvents log. I only forward ID 6101. Not sure if that's what you meant.

($xmlevent.Event.EventData.Data[1]) returns fqdn of the vm.

Code: Select all

get-scvirtualmachine -name $vm 
fails even though the vm is in the variable.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scheduled task parameter

Post by jvierra »

Which is why I asked you to post the XML from the collection server. What you posted does not have correct information.

This will only work if the VM computer name and the VM name are identical which is not always the case. Events are not tracked by VM name.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scheduled task parameter

Post by jvierra »

Also ntoe that this is where the sending computers name should be stored:

<Computer>myHyper-V.Node</Computer>

Which is here:

$xml.Events.Event[0].System.Computer
User avatar
obrienc
Posts: 59
Last visit: Wed Apr 20, 2022 5:43 am

Re: Scheduled task parameter

Post by obrienc »

The XML I posted was from the collector. The doubletake job event 6101 includes the vm name and node in the same element which is why I have to parse it to get he vm name. The node also has its own element so I can do this and it works.

Code: Select all

$string = Get-WinEvent -ComputerName $node -LogName $logname|where {$_.Id -eq $logid}|Select -First 1
$string = $string |Select -ExpandProperty Message

## get the vm name from the log message ## 
$arr = $string -split ('"')
$y = $arr[1]
$z = $y.Split(' ')
$vm = $z[0]
The idea is to get the vm name from the event and change settings to the vm hardware in vmm.

Parsing the same message from xml passing $vm to get-scvirtualmachine doesn't work even though $vm is holding the correct value.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scheduled task parameter

Post by jvierra »

The VM name is in the DATA elements. That is how it gets displayed in the message. The source computer name for the event is in the "COMPUTER" element of the SYSTEM elements in the XML. That is hw the event system works

SYSTEM
<EventID Qualifiers="16384">6101</EventID>
<Computer>myHyper-V.Node</Computer>


EVENTDATA

<Data>MyVM to myHyper-V.Node</Data>
<Data>10.83.72.138</Data>

$xmlevent.Event.EventData.Data[0] is the insert string for the message

<Message>The job "MyVM to myHyper-V.Node" (ID ....
User avatar
obrienc
Posts: 59
Last visit: Wed Apr 20, 2022 5:43 am

Re: Scheduled task parameter

Post by obrienc »

got it to work by adding .Trim(). Now get-scvirtualmachine takes the passed var.

Code: Select all

## parse xml from forwarded eventlog ##
$event = Get-WinEvent @{ LogName = 'ForwardedEvents'; ID = 6101 } -MaxEvents 1
[xml]$xmlEvent = $event.ToXml()
$ph = $xmlEvent.Event.EventData.Data[0] -split 'to '
$vm = $ph[0].Trim()
$node = $xmlEvent.Event.System.Computer
$vmfqdn = $xmlEvent.Event.EventData.Data[1]
This topic is 6 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked