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
  • 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

21 Experts available now in Live!

Get 1:1 Help Now