Ack. Didn't edit far enough. powershell.exe -file " c:\scripts\myscripts.ps1"
From: Campbell, Rob [mailto:rob_campb...@centraltechnology.net] Sent: Friday, October 22, 2010 1:55 PM To: MS-Exchange Admin Issues Subject: RE: PS script in batch troubleshooting powershell.exe -command "&{ c:\scripts\myscripts.ps1 }" or: powershell.exe -file " c:\scripts\myscripts.ps1}" From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Friday, October 22, 2010 1:52 PM To: MS-Exchange Admin Issues Subject: RE: PS script in batch troubleshooting For Exchange 2007, you need to add this command: "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin". If you want to make it a "good" script, you'll do something like: ## the below code is Exchange 2007 specific Get-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -EA 0 if ($?) { ## snap-in already loaded, do nothing } else { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin } $date = Get-date $shortdate = $date.ToShortdateString() get-messagetrackinglog -messagesubject "NWEA password" -Start $shortdate | Select sender,messagesubject | ft -auto put all the above in a PS1 file. In the cmd/bat file: powershell.exe -command "&{ c:\scripts\myscripts.ps1 }" Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: David Lum [mailto:david....@nwea.org] Sent: Friday, October 22, 2010 2:44 PM To: MS-Exchange Admin Issues Subject: RE: PS script in batch troubleshooting Thanks. Exchange 2007. Can I have a .CMD call a PS1 file and call it good? Dave From: Campbell, Rob [mailto:rob_campb...@centraltechnology.net] Sent: Friday, October 22, 2010 11:27 AM To: MS-Exchange Admin Issues Subject: RE: PS script in batch troubleshooting Nope. I believe the problem is that when you run it from the PS command line, it's actually being run from an EMS command line. The EMS is a generic Powershell console, with the modules or snapins (depending on your Exchange version) installed that implement the exchange specific cmdlets. Since you're calling a generic Powershell instance from cmd, it doesn't have those cmdlets, so it doesn't understand "get-messagetrackinglog". What version of Exchange are you running? From: David Lum [mailto:david....@nwea.org] Sent: Friday, October 22, 2010 1:21 PM To: MS-Exchange Admin Issues Subject: PS script in batch troubleshooting This works at the PS command line: $date = Get-date ; $shortdate = $date.ToShortdateString() ; get-messagetrackinglog -messagesubject:"NWEA password" -Start $shortdate | Select sender,messagesubject | ft -auto This does NOT work in a .CMD file (simply adds "powershell.exe -command" to the front): powershell.exe -command "$date = Get-date ; $shortdate = $date.ToShortdateString() ; get-messagetrackinglog -messagesubject:"NWEA password" -Start $shortdate | Select sender,messagesubject | ft -auto Error message is "The term 'get-messagetrackinglog' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again." Is my date string in front messing it up? David Lum // SYSTEMS ENGINEER NORTHWEST EVALUATION ASSOCIATION (Desk) 971.222.1025 // (Cell) 503.267.9764 --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe exchangelist ************************************************************************************************** Note: The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. ************************************************************************************************** --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe exchangelist --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe exchangelist --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe exchangelist ************************************************************************************************** Note: The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. ************************************************************************************************** --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe exchangelist ************************************************************************************************** Note: The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. ************************************************************************************************** ************************************************************************************************** Note: The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. ************************************************************************************************** --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe exchangelist