[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-04-15
5
Medium Priority
?
1,573 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
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…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

656 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