Welcome to ServerForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Passing a Monad (powershell) variable as command parameter

 
   Windows Server (Home) -> Windows Server Scripting RSS
Next:  Problem with "List All the Members of a Grou..  
Author Message
crosby.tim

External


Since: Jun 05, 2006
Posts: 1



(Msg. 1) Posted: Mon Jun 05, 2006 12:58 pm
Post subject: Passing a Monad (powershell) variable as command parameter
Archived from groups: microsoft>public>windows>server>scripting (more info?)

I'm trying to accomplish something that I thought would be very simple.
I guess I'm just missing something but here goes.

I want to simply call an executable from within my Monad script and
send that executable a parameter in the form of a variable set earlier
in the script. More specifically, I'm trying to call the command line
version of WINRAR and give it a date so it will zip anything older than
that date.

If I type either of these commands into powershell, it works as
expected:

.. 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
or
& 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip

What I want to do is use a $variable to replace the 20060504. I first
verify that my variable resolves to 20060504 So I try:

& 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
or
.. 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip

I don't get any errors, but with both of those commands winrar zips
everything and ignores the date variable. What is the proper syntax to
pass a variable as a parameter to an external command?

 >> Stay informed about: Passing a Monad (powershell) variable as command parameter 
Back to top
Login to vote
Tim

External


Since: Jun 05, 2006
Posts: 1



(Msg. 2) Posted: Mon Jun 05, 2006 1:50 pm
Post subject: Re: Passing a Monad (powershell) variable as command parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Excellent! Thank you very much!

/\/\o\/\/ wrote:
> crosby.tim.DeleteThis@gmail.com wrote:
> > I'm trying to accomplish something that I thought would be very simple.
> > I guess I'm just missing something but here goes.
> >
> > I want to simply call an executable from within my Monad script and
> > send that executable a parameter in the form of a variable set earlier
> > in the script. More specifically, I'm trying to call the command line
> > version of WINRAR and give it a date so it will zip anything older than
> > that date.
> >
> > If I type either of these commands into powershell, it works as
> > expected:
> >
> > .. 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
> > or
> > & 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
> >
> > What I want to do is use a $variable to replace the 20060504. I first
> > verify that my variable resolves to 20060504 So I try:
> >
> > & 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
> > or
> > .. 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
> >
> > I don't get any errors, but with both of those commands winrar zips
> > everything and ignores the date variable. What is the proper syntax to
> > pass a variable as a parameter to an external command?
> >
>
> you need to use quotes around the parameter as winrar wants them
> connected (no space) and powershell thinks the $ is part of the parameter.
>
> . 'C:\Program Files\WinRAR\rar.exe' a "-tb$variable" -m5 ziplogs.zip
>
> see this resolving :
>
> MowPS>echo 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
> C:\Program Files\WinRAR\rar.exe
> a
> -tb$variable
> -m5
> ziplogs.zip
>
> MowPS>echo 'C:\Program Files\WinRAR\rar.exe' a "-tb$variable" -m5
> ziplogs.zip
> C:\Program Files\WinRAR\rar.exe
> a
> -tb20060504
> -m5
> ziplogs.zip
>
> greetings /\/\o\/\/

 >> Stay informed about: Passing a Monad (powershell) variable as command parameter 
Back to top
Login to vote
/\/\o\/\/

External


Since: Feb 09, 2006
Posts: 137



(Msg. 3) Posted: Mon Jun 05, 2006 10:30 pm
Post subject: Re: Passing a Monad (powershell) variable as command parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

crosby.tim.TakeThisOut@gmail.com wrote:
> I'm trying to accomplish something that I thought would be very simple.
> I guess I'm just missing something but here goes.
>
> I want to simply call an executable from within my Monad script and
> send that executable a parameter in the form of a variable set earlier
> in the script. More specifically, I'm trying to call the command line
> version of WINRAR and give it a date so it will zip anything older than
> that date.
>
> If I type either of these commands into powershell, it works as
> expected:
>
> .. 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
> or
> & 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
>
> What I want to do is use a $variable to replace the 20060504. I first
> verify that my variable resolves to 20060504 So I try:
>
> & 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
> or
> .. 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
>
> I don't get any errors, but with both of those commands winrar zips
> everything and ignores the date variable. What is the proper syntax to
> pass a variable as a parameter to an external command?
>

you need to use quotes around the parameter as winrar wants them
connected (no space) and powershell thinks the $ is part of the parameter.

.. 'C:\Program Files\WinRAR\rar.exe' a "-tb$variable" -m5 ziplogs.zip

see this resolving :

MowPS>echo 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
C:\Program Files\WinRAR\rar.exe
a
-tb$variable
-m5
ziplogs.zip

MowPS>echo 'C:\Program Files\WinRAR\rar.exe' a "-tb$variable" -m5
ziplogs.zip
C:\Program Files\WinRAR\rar.exe
a
-tb20060504
-m5
ziplogs.zip

greetings /\/\o\/\/
 >> Stay informed about: Passing a Monad (powershell) variable as command parameter 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
[Monad] get-property -property parameter - I am using the HKLM registry drive. If I use get-property . -property ProductVersion I expected to get back the value for ProductVersion. Instead I get values for six properties including ProductVersion. Since I supplied only a single value for the..

[Monad] Version command? - How do I find from within Monad which version of Monad is running? I assume I am missing something obvious. Thanks Andrew Watt MVP

Can you add a user from the Monad command line ? - Is it possible to create a new user account using MSH (Monad) ? If so, how ? Regards, Patrick.

read variable value from command line - Hi How do we read a variable value from command line in wscript like we do in C? thanks

(msh) get-command does not work in variable provider - MSH>cd variable: MSH>get-command Get-Command : Dynamic parameters for the cmdlet cannot be retrieved. The NavigationCmdletProvider methods are not supported by this provide r. At line:1 char:11 + get-command <<<< Ok just give me my li...
   Windows Server (Home) -> Windows Server Scripting All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]