Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - >

Reply
 
Old 08-26-2008   #1 (permalink)
IT Staff


 
 

>

$cmdline = "c:\windows\system32\defrag.exe c:\ -a > $s_defrag.txt"

where $s is in foreach($s in pc)

I run a win32_scheduledjob , the job created successfully. However in the
job, it appears as :


"c:\windows\system32\defrag.exe c:\ -a > .txt"

How can i append $s_defrag.txt ?



My System SpecsSystem Spec
Old 08-26-2008   #2 (permalink)
tojo2000


 
 

Re: >

On Aug 25, 9:45*pm, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> *$cmdline = "c:\windows\system32\defrag.exe c:\ -a > $s_defrag.txt"
>
> where $s is in foreach($s in pc)
>
> I run a win32_scheduledjob , the job created successfully. However in the
> job, it appears as :
>
> "c:\windows\system32\defrag.exe c:\ -a > .txt"
>
> How can i append $s_defrag.txt ?
I think you'll have to put a backtick before that underscore, because
Powershell is reading that as you trying to insert a variable called
$s_defrag.
My System SpecsSystem Spec
Old 08-26-2008   #3 (permalink)
IT Staff


 
 

Re: >

Don't think it work this way

Defrag.exe c:\ -a -v > `d:\results.txt ==> does not work too especially in
the Run job at scheduler




"tojo2000" <tojo2000@xxxxxx> wrote in message
news:65825c28-632e-44f0-b85f-dbe77c0d67ac@xxxxxx
On Aug 25, 9:45 pm, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> $cmdline = "c:\windows\system32\defrag.exe c:\ -a > $s_defrag.txt"
>
> where $s is in foreach($s in pc)
>
> I run a win32_scheduledjob , the job created successfully. However in the
> job, it appears as :
>
> "c:\windows\system32\defrag.exe c:\ -a > .txt"
>
> How can i append $s_defrag.txt ?
I think you'll have to put a backtick before that underscore, because
Powershell is reading that as you trying to insert a variable called
$s_defrag.


My System SpecsSystem Spec
Old 08-26-2008   #4 (permalink)
tojo2000


 
 

Re: >

On Aug 25, 10:21*pm, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> Don't think it work this way
>
> Defrag.exe c:\ -a -v > `d:\results.txt ==> does not work too especially in
> the Run job at scheduler
>
> "tojo2000" <tojo2...@xxxxxx> wrote in message
>
> news:65825c28-632e-44f0-b85f-dbe77c0d67ac@xxxxxx
> On Aug 25, 9:45 pm, "IT Staff" <jkk...@xxxxxx> wrote:
>
Quote:

> > $cmdline = "c:\windows\system32\defrag.exe c:\ -a > $s_defrag.txt"
>
Quote:

> > where $s is in foreach($s in pc)
>
Quote:

> > I run a win32_scheduledjob , the job created successfully. However in the
> > job, it appears as :
>
Quote:

> > "c:\windows\system32\defrag.exe c:\ -a > .txt"
>
Quote:

> > How can i append $s_defrag.txt ?
>
> I think you'll have to put a backtick before that underscore, because
> Powershell is reading that as you trying to insert a variable called
> $s_defrag.
For the redirect to work you might have to invoke cmd explicitly since
I think cmd is what handles the bracket operator.

cmd /c defrag.exe c: -a > somefile.txt

My System SpecsSystem Spec
Old 08-26-2008   #5 (permalink)
IT Staff


 
 

Re: >

cmd /c defrag.exe c: -a > %computername%_somefile.txt ==> this works


cmd /c defrag.exe c: -a > `$s_somefile.txt ==> this works synatically , but
$s was not capture as computer name even with a back tick ?


My System SpecsSystem Spec
Old 08-26-2008   #6 (permalink)
tojo2000


 
 

Re: >

On Aug 25, 11:55*pm, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> cmd /c defrag.exe c: -a > %computername%_somefile.txt ==> this works
>
> cmd /c defrag.exe c: -a > `$s_somefile.txt ==> this works synatically, but
> $s was not capture as computer name even with a back tick ?
Sorry, I wasn't specific enough. That should be

cmd /c defrag.exe c: -a > $s`_somefile.txt

The backtick is to keep PowerShell from thinking the underscore is
part of the variable name.
My System SpecsSystem Spec
Old 08-26-2008   #7 (permalink)
IT Staff


 
 

Re: >

I realised underscore shld not be used in the cmd line.

Here are the results

1. cmd /c c:\windows\system32\defrag.exe c:\ -a > c:\$s-defrag.txt
==> without a backtick at the $s, but put a dash, the text file can be
created with full computername-defrag.txt

2. $s_defrag.txt or $s`_defrag.txt
==> both created .txt without computer name.

I will use option 1 then


My System SpecsSystem Spec
Old 08-26-2008   #8 (permalink)
tojo2000


 
 

Re: >

On Aug 26, 2:28*am, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> I realised underscore shld not be used in the cmd line.
>
> Here are the results
>
> 1. cmd /c c:\windows\system32\defrag.exe c:\ -a > c:\$s-defrag.txt
> ==> without a backtick at the $s, but put a dash, the text file can be
> created with full computername-defrag.txt
>
> 2. $s_defrag.txt or $s`_defrag.txt
> ==> both created .txt without computer name.
>
> I will use option 1 then
So just to be clear, you tried this?

$cmdline = "c:\windows\system32\defrag.exe c:\ -a > $s`_defrag.txt"

and it didn't insert the computer name? Are you using PowerShell v1
or v2 CTP? I'm on v2. If this is an edge case that I need to keep in
mind I'd like to know.
My System SpecsSystem Spec
Old 08-26-2008   #9 (permalink)
IT STAFF


 
 

Re: >

Using Powershell 1.0


"tojo2000" <tojo2000@xxxxxx> wrote in message
news:b76eb22c-17f1-4170-a7c6-e0e01418e915@xxxxxx
On Aug 26, 2:28 am, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> I realised underscore shld not be used in the cmd line.
>
> Here are the results
>
> 1. cmd /c c:\windows\system32\defrag.exe c:\ -a > c:\$s-defrag.txt
> ==> without a backtick at the $s, but put a dash, the text file can be
> created with full computername-defrag.txt
>
> 2. $s_defrag.txt or $s`_defrag.txt
> ==> both created .txt without computer name.
>
> I will use option 1 then
So just to be clear, you tried this?

$cmdline = "c:\windows\system32\defrag.exe c:\ -a > $s`_defrag.txt"

and it didn't insert the computer name? Are you using PowerShell v1
or v2 CTP? I'm on v2. If this is an edge case that I need to keep in
mind I'd like to know.

My System SpecsSystem Spec
Reply

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46