![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Why version with redirection output run with error? Please, I am very confused why this script run OK: /------------------------------------8<----------------------------------\ Start-Transcript C:\Temp\PowerShell-Transcript.log [string[]]$ComputerNamesList = @("PC061","PC062","PC063","PC064") for ($I=0;$I -le 4;$I++) { $S = $ComputerNamesList[$I] schtasks.exe /Query /FO LIST /V /S $S } Stop-Transcript \------------------------------------8<----------------------------------/ but this NO: /------------------------------------8<----------------------------------\ Start-Transcript C:\Temp\PowerShell-Transcript.log [string[]]$ComputerNamesList = @("PC061","PC062","PC063","PC064") for ($I=0;$I -le 4;$I++) { $S = $ComputerNamesList[$I] schtasks.exe /Query /FO LIST /V /S $S > Tasks.log } Stop-Transcript \------------------------------------8<----------------------------------/ PS show this output: /------------------------------------8<----------------------------------\ PS D:\W> .\Sch.ps1 Transcript started, output file is C:\Temp\PowerShell-Transcript.log ERROR: Invalid syntax. Value expected for '/S'. Type "SCHTASKS /QUERY /?" for usage. Transcript stopped, output file is C:\Temp\PowerShell-Transcript.log \------------------------------------8<----------------------------------/ In file C:\Temp\PowerShell-Transcript.log is: /------------------------------------8<----------------------------------\ ********************** Windows PowerShell Transcript Start Start time: 20080704174742 Username : CCV\admindavid Machine : SRV-SIEMENS (Microsoft Windows NT 5.2.3790 Service Pack 2) ********************** Transcript started, output file is C:\Temp\PowerShell-Transcript.log ********************** Windows PowerShell Transcript End End time: 20080704174745 ********************** \------------------------------------8<----------------------------------/ |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Why version with redirection output run with error? Hi David, I agree with Shay. The script you have is processing 5 computer names when you only have 4. So when the last one get's processed, $S is null and you get an error on your call. You don't need to use the for statement and indexing at all. You could do this instead: Start-Transcript C:\Temp\PowerShell-Transcript.log [string[]]$ComputerNamesList = @("PC061","PC062","PC063","PC064") foreach ($computer in $ComputerNamesList) { schtasks.exe /Query /FO LIST /V /S $computer > Tasks.log } Stop-Transcript That way it doesn't matter how many computers you put in your list. -- Kirk Munro [MVP] Poshoholic http://poshoholic.com |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Folder Redirection Error | John Whites | Vista General | 0 | 08-11-2008 01:43 PM |
| Redirection of output | gurbao | PowerShell | 4 | 01-28-2008 08:29 AM |
| ansi versus unicode output with redirection operators? | klumsy@xtra.co.nz | PowerShell | 10 | 12-02-2006 11:25 PM |
| Problem with output redirection of nslookup | =?Utf-8?B?ZHJlZXNjaGtpbmQ=?= | PowerShell | 8 | 08-24-2006 04:04 AM |
| Why output redirection opens file with read lock? | Andrew Savinykh | PowerShell | 10 | 08-21-2006 07:41 AM |