![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | > $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 Specs![]() |
| | #2 (permalink) |
| | 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 ? Powershell is reading that as you trying to insert a variable called $s_defrag. |
My System Specs![]() |
| | #3 (permalink) |
| | 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 ? Powershell is reading that as you trying to insert a variable called $s_defrag. |
My System Specs![]() |
| | #4 (permalink) |
| | 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. I think cmd is what handles the bracket operator. cmd /c defrag.exe c: -a > somefile.txt |
My System Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 ? 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 $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 Specs![]() |
| | #9 (permalink) |
| | 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 $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 Specs![]() |