THANK YOU!

Well that was a frustrating learning experience. The server is running PS 2.0. 
I wasn't qualifying my 'foreach' loops with If() statements. So even if the 
variable was $null, it tried running my foreach loops, and within my foreach 
loops there is a parameter to pass "$Directory\$File". Since $file was $null, 
it was copying/moving the entire directory. I couldn't reproduce it on my side 
because I'm running PS 4.0, and this is my first run in with PS 2.0. I also 
didn't properly test with an empty \PDF directory on the server.

Thank you again.

If I may ask a follow up question, when you say UR8 changed that, are you 
saying from UR8 on, PowerShell code will execute with the latest PS version 
available to the host? (Just want to 100% confirm I understand your statement)

From: [email protected] [mailto:[email protected]] On 
Behalf Of Henrik Andersen
Sent: Friday, November 06, 2015 10:12 AM
To: [email protected]
Subject: RE: [msmom] PowerShell Script Inconsistent Behavior

Hi!

I haven't yet looked at your code, but beware that SCOM might be executing the 
powershell code with a different version of powershell, than when you execute 
it 'online'.  That is something that has changed with scom 2012 UR8

/Henrik


-------- Oprindelig meddelelse --------
Fra: "Orlebeck, Geoffrey" 
<[email protected]<mailto:[email protected]>>
Dato: 06/11/2015 18.54 (GMT+01:00)
Til: "'[email protected]'" 
<[email protected]<mailto:[email protected]>>
Emne: [msmom] PowerShell Script Inconsistent Behavior
I'm having an issue that I have not run into before.

I have one MP where I have a module setup to run a PowerShell script every 
5mins. The script is supposed to grab all PDFs in a folder and depending on 
size/age/matching XML, be copied/moved to several directories. I've now run it 
dozens of times manually without a single issue. However, when I wrap it up in 
a SCOM monitor, it sometimes (but not always)copies the actual PDF directory 
into the target directory for the move. I setup some logging inside the 
PowerShell script and it appears to not match the script criteria (or the 
parameters are being mangled). I'm wondering if anyone has run into a similar 
issue? Here are the two log entries.

Manual Execution:
========================================================================
11/06/2015 09:26:41 | Processing Started: Good_File.pdf
11/06/2015 09:26:41 | Good_File.pdf is 209KB
11/06/2015 09:26:41 | XML pair found: Good_File.xml
11/06/2015 09:26:41 | Good_File.pdf copy to C:\Folder\Prod\PDF\Archive success
11/06/2015 09:26:41 | Good_File.pdf move to C:\Program Files 
(x86)\Acme\Outbound success
11/06/2015 09:26:41 | Processing Complete: Good_File.pdf
11/06/2015 09:26:41 | Good_File.xml copy to C:\Folder\Prod\PDF\Archive success
11/06/2015 09:26:41 | Good_File.xml move to C:\Program Files 
(x86)\Acme\Outbound success
11/06/2015 09:26:41 | Processing Complete: Good_File.xml
========================================================================

SCOM Execution:
========================================================================
11/05/2015 21:26:59 | Processing Started:
11/05/2015 21:26:59 |  is 0KB
11/05/2015 21:26:59 | XML pair found: .xml
11/05/2015 21:26:59 | Processing Complete:
11/05/2015 21:26:59 | .xml copy to C:\Folder\Prod\PDF\Archive failed
11/05/2015 21:26:59 | .xml move to C:\Program Files (x86)\Acme\Outbound failed
11/05/2015 21:26:59 | Processing Complete: .xml
========================================================================

When executing via SCOM there are random instances where the PDF folder in 
C:\Folder\Prod is being moved to C:\Program Files (x86)\Acme\Outbound:
[cid:[email protected]]

I cannot reproduce this when executing my script manually; I only see it when 
run via SCOM. The difference with manual is I am defining the variables within 
my PS session ($directory, $errordir, etc.) prior to running the script. With 
SCOM, the parameters are supposed to be passed in so I don't have to hard code 
them in the PowerShell script (per Brian Wren's training videos). I am 
attaching the test MP I am using for this. If there are any insight, I'm really 
interested to know if there is an issue/limitation related to PowerShell/SCOM I 
need to account for or if it's a problem with my MP authoring.

Thank you very much.

Geoff

Confidentiality Notice: This is a transmission from Community Hospital of the 
Monterey Peninsula. This message and any attached documents may be confidential 
and contain information protected by state and federal medical privacy 
statutes. They are intended only for the use of the addressee. If you are not 
the intended recipient, any disclosure, copying, or distribution of this 
information is strictly prohibited. If you received this transmission in error, 
please accept our apologies and notify the sender. Thank you.

Confidentiality Notice: This is a transmission from Community Hospital of the 
Monterey Peninsula. This message and any attached documents may be confidential 
and contain information protected by state and federal medical privacy 
statutes. They are intended only for the use of the addressee. If you are not 
the intended recipient, any disclosure, copying, or distribution of this 
information is strictly prohibited. If you received this transmission in error, 
please accept our apologies and notify the sender. Thank you.



Reply via email to