Solved

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

Posted on 2014-04-15
5
1,429 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

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Question has a verified solution.

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

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Resolve DNS query failed errors for Exchange
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now