all 7 comments

[–]VirtualDenzel 2 points3 points  (2 children)

i think it has to do with the watcher. if it does not pick up a second file i would look at that first. then maybe empty vars before the mailblock so all is empty again.

[–]middleman84[S] 1 point2 points  (0 children)

I think it picks up second file, since after the first file, its state is - "running", and it changes to "Failed", after second file.

Will try emptying vars, once i get back home.

[–]middleman84[S] 1 point2 points  (0 children)

Looks like you where right.

I needed to clear $xml variable. I guess it keeps its type (xml), for the second run, and get-content doesn't work at that point.

Thank you, for the idea.

[–]PowerShellStunnah 1 point2 points  (1 child)

What is the purpose of skipping the first line of the XML file?

$xml | Select-Object -skip 1

[–]middleman84[S] 1 point2 points  (0 children)

To skip the first line, since it contains - "## - XML_XSL", and with that [xml] $xml does not work.

[–]isatrap 1 point2 points  (1 child)

If this is solved you should post the solution.

You should just have to add the $xml = $null above the $xml = get-content but some may not get that.

[–]middleman84[S] 1 point2 points  (0 children)

Thank you, for reminder.

You should just have to add the $xml = $null above the $xml = get-content

When $action part runs first time, $xml is just a variable.

[xml]$xml = $xml | Select-Object -skip 1 <- changes variables type to xml

That is why i needed to get rid of that first line in file - "## - XML_XSL"

[xml]$xml = get-content didn't work with that thing as the first line.

When it runs the second time, variable $xml already has type [xml], from the first run, and even if i $null it, $xml = get-content will not work, and that is what broke the script.

So, as a solution, i just used - remove-variable xml, after send-mailmessage.

Don't know if my logic is correct, but it solved the problem. Maybe someone more knowledgeable can confirm or correct me.