?
Solved

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

Posted on 2014-04-15
5
Medium Priority
?
1,537 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:Russ Wrightson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Russ Wrightson
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 2000 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:Russ Wrightson
ID: 40013420
Becraig - still hammering away at this . should be resolved by the end of the week.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
Suggested Courses

770 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