Problem running the powershell script in windows server 2008

Posted on 2011-09-09
Last Modified: 2012-05-12
I can able to run the following script in localmachine, but when i execute this in windows server 2008 i get the following error. Powershell v2.0 has been installed in both local as well as in server. Please help me in solving this issue.

Error Message:

The expression after '&' in a pipeline element produced an invalid object. It must result in a command name, script blo
ck or CommandInfo object.
At E:\archive.ps1:8 char:3
+  & <<<< $WinRar a -ep2 -m5 -r -t "$ArchivePath\$ArchiveFileName" "$Path"
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : BadExpression


$DateFolder = (Get-Date).AddDays(-$Days).tostring('yyyyMMdd')
&$WinRar a -ep2 -m5 -r -t "$ArchivePath\$ArchiveFileName" "$Path"

Open in new window

Question by:SQLM_M
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

Assisted Solution

krf1963 earned 500 total points
ID: 36511337
Do you have WinRAR installed on the Windows 2008 Server?

Author Comment

ID: 36515191
Yes, Winrar has been installed.

Accepted Solution

SQLM_M earned 0 total points
ID: 36516076
I got the solution. Should refer the path of rar.exe to $WinRar. Here's the modified code


$DateFolder = (Get-Date).AddDays(-$Days).tostring('yyyyMMdd')

$WinRar= "C:\programfiles\winrar\rar.exe"

&$WinRar a -ep2 -m5 -r -t "$ArchivePath\$ArchiveFileName" "$Path"

Open in new window


Author Closing Comment

ID: 36541396
I identified the issue and modified the code.

Featured Post

What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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