Solved

Problem running the powershell script in windows server 2008

Posted on 2011-09-09
4
637 Views
Last Modified: 2012-05-12
Hi,
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

param($SourcePath,$ArchivePath,$Days)    

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

Open in new window

 
0
Comment
Question by:SQLM_M
  • 3
4 Comments
 
LVL 4

Assisted Solution

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

Author Comment

by:SQLM_M
ID: 36515191
Yes, Winrar has been installed.
0
 

Accepted Solution

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

param($SourcePath,$ArchivePath,$Days)    

$DateFolder = (Get-Date).AddDays(-$Days).tostring('yyyyMMdd')
$Path="$SourcePath\$DateFolder"
$ArchiveFileName="$DateFolder"+".rar"

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

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

Open in new window

0
 

Author Closing Comment

by:SQLM_M
ID: 36541396
I identified the issue and modified the code.
0

Featured Post

Are your AD admin tools letting you down?

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Set OWA language and time zone in Exchange for individuals, all users or per database.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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