Solved

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

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

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 28

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 28

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

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Join & Write a Comment

Import PST to Exchange using Power Shell new-mailboximportrequest command, you can simply import the PST file into Exchange mailbox or archived. To know How to import PST into Exchange  2013 read the complete article.
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
Viewers will learn the different options available in the Backstage view in Excel 2013.

707 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

18 Experts available now in Live!

Get 1:1 Help Now