Solved

Powershell script will not run using the ' -command ' to start it from task manager

Posted on 2014-04-15
5
1,448 Views
Last Modified: 2014-04-23
Experts,

I have to setup a re occurring task that utilizes the Exchange management shell for 2010. I have set the Execution Policy to remote signed and the script is local ( C drive). I have tried to test the cmdlet by itself in Powershell but i receive the following error :

missing expression after unary operator '-'. At Line:1 Char:2

here is the whole cmlet :

-command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\scripts\Update-Recipients.ps1"

thanks,

Russ
0
Comment
Question by:JBfan
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40002440
Taking a look, it looks like it might be how the command line is reading your input
0
 

Author Comment

by:JBfan
ID: 40002496
Becraig  thanks for guessing but that needs to be there. It is the dot operator, its used for dot sourcing a script. This runs a script so that the items in the script are part of the calling scope. For example, inside the RemoteExchange.ps1 script are several functions. Dotting this script first allows you to later call these functions.

Russ
0
 
LVL 29

Expert Comment

by:becraig
ID: 40002509
powershell -command ". 'c:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\scripts\Update-Recipients.ps1"

With the exception of the absence of the script ran perfectly for me.
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40002722
I ran this as a scheduled task wrapping only the first command in single quotes and had no issues.

Of course I created empty scripts to make sure they were called but it all worked.
Did you copy and paste the command into the task scheduler  ?

The only thing I can see possible here might be encoding (hidden characters)
Try typing in the command manually as see if you still get the failure.

Also it might be worth it to run the scripts individually to see if they error in the PS window.
0
 

Author Comment

by:JBfan
ID: 40013420
Becraig - still hammering away at this . should be resolved by the end of the week.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question