![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| Guest | Re: Error: "Cannot convert "System.Object[]" to "System.Int32"." Your for loop syntax is incorrect: Quote: > for ($i=0, $i -lt $NoOfComputers, $i++) .. Replace commas with semicolons for ($i=0; $i -lt $NoOfComputers; $i++) .. ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > 1) I created this script: > > [string[]]$Computers = "Server1", "Server2", "Server3", "Server4", > "Server5", "Server6", "Server7", "Server8", "Server9" > [int]$NoOfComputers = $Computers.length > $NoOfComputers.gettype() > [int32]$i = 0 > $I.gettype() > if ($args.length -gt 1) { > "I am copying "+$args[0]+" to PC:" > if (Test-Path $args[0]) { > for ($i=0, $i -lt $NoOfComputers, $i++) { > $Computers[$I] > Copy-Item $args[0] "\\$Computers[$I]\$Args[1]" > } > } > } > 2) I run it: > PS C:\Aplikace\CCV> .\CopyToAllPc.ps1 WakeOnLAN.bat C$\Aplikace\CCV > 3) It shows this error: > > IsPublic IsSerial Name BaseType > -------- -------- ---- -------- > True True Int32 > System.ValueType > True True Int32 > System.ValueType > I am copying WakeOnLAN.bat to PC: > The '-lt' operator failed: Could not compare "0" to "System.Object[]". > Error: "Cannot convert "System.Object[]" to "Sys > tem.Int32".". > At C:\Aplikace\CCV\CopyToAllPc.ps1:31 char:22 > + for ($i=0, $i -lt <<<< $NoOfComputers, $i++) { > 4) Please, where is problem? > |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Error: "Cannot convert "System.Object[]" to "System.Int32"." 1) I created this script: [string[]]$Computers = "Server1", "Server2", "Server3", "Server4", "Server5", "Server6", "Server7", "Server8", "Server9" [int]$NoOfComputers = $Computers.length $NoOfComputers.gettype() [int32]$i = 0 $I.gettype() if ($args.length -gt 1) { "I am copying "+$args[0]+" to PC:" if (Test-Path $args[0]) { for ($i=0, $i -lt $NoOfComputers, $i++) { $Computers[$I] Copy-Item $args[0] "\\$Computers[$I]\$Args[1]" } } } 2) I run it: PS C:\Aplikace\CCV> .\CopyToAllPc.ps1 WakeOnLAN.bat C$\Aplikace\CCV 3) It shows this error: IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType True True Int32 System.ValueType I am copying WakeOnLAN.bat to PC: The '-lt' operator failed: Could not compare "0" to "System.Object[]". Error: "Cannot convert "System.Object[]" to "Sys tem.Int32".". At C:\Aplikace\CCV\CopyToAllPc.ps1:31 char:22 + for ($i=0, $i -lt <<<< $NoOfComputers, $i++) { 4) Please, where is problem? |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Error: "Cannot convert "System.Object[]" to "System.Int32"." This won't work either: Copy-Item $args[0] "\\$Computers[$I]\$Args[1]" You need to put each expression in a subexpression notation if you want it to be expanded inside a string: Copy-Item $args[0] "\\$($Computers[$I])\$($Args[1])" ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > 1) I created this script: > > [string[]]$Computers = "Server1", "Server2", "Server3", "Server4", > "Server5", "Server6", "Server7", "Server8", "Server9" > [int]$NoOfComputers = $Computers.length > $NoOfComputers.gettype() > [int32]$i = 0 > $I.gettype() > if ($args.length -gt 1) { > "I am copying "+$args[0]+" to PC:" > if (Test-Path $args[0]) { > for ($i=0, $i -lt $NoOfComputers, $i++) { > $Computers[$I] > Copy-Item $args[0] "\\$Computers[$I]\$Args[1]" > } > } > } > 2) I run it: > PS C:\Aplikace\CCV> .\CopyToAllPc.ps1 WakeOnLAN.bat C$\Aplikace\CCV > 3) It shows this error: > > IsPublic IsSerial Name BaseType > -------- -------- ---- -------- > True True Int32 > System.ValueType > True True Int32 > System.ValueType > I am copying WakeOnLAN.bat to PC: > The '-lt' operator failed: Could not compare "0" to "System.Object[]". > Error: "Cannot convert "System.Object[]" to "Sys > tem.Int32".". > At C:\Aplikace\CCV\CopyToAllPc.ps1:31 char:22 > + for ($i=0, $i -lt <<<< $NoOfComputers, $i++) { > 4) Please, where is problem? > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Error: "Cannot convert "System.Object[]" to "System.Int32"." Thank you very much! Shay Levi wrote: Quote: > This won't work either: > > Copy-Item $args[0] "\\$Computers[$I]\$Args[1]" > > > You need to put each expression in a subexpression notation if you want > it to be expanded inside a string: > > Copy-Item $args[0] "\\$($Computers[$I])\$($Args[1])" > > > > > ----- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > Quote: >> 1) I created this script: >> >> [string[]]$Computers = "Server1", "Server2", "Server3", "Server4", >> "Server5", "Server6", "Server7", "Server8", "Server9" >> [int]$NoOfComputers = $Computers.length >> $NoOfComputers.gettype() >> [int32]$i = 0 >> $I.gettype() >> if ($args.length -gt 1) { >> "I am copying "+$args[0]+" to PC:" >> if (Test-Path $args[0]) { >> for ($i=0, $i -lt $NoOfComputers, $i++) { >> $Computers[$I] >> Copy-Item $args[0] "\\$Computers[$I]\$Args[1]" >> } >> } >> } >> 2) I run it: >> PS C:\Aplikace\CCV> .\CopyToAllPc.ps1 WakeOnLAN.bat C$\Aplikace\CCV >> 3) It shows this error: >> >> IsPublic IsSerial Name BaseType >> -------- -------- ---- -------- >> True True Int32 >> System.ValueType >> True True Int32 >> System.ValueType >> I am copying WakeOnLAN.bat to PC: >> The '-lt' operator failed: Could not compare "0" to "System.Object[]". >> Error: "Cannot convert "System.Object[]" to "Sys >> tem.Int32".". >> At C:\Aplikace\CCV\CopyToAllPc.ps1:31 char:22 >> + for ($i=0, $i -lt <<<< $NoOfComputers, $i++) { >> 4) Please, where is problem? >> > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| "Extensible Authentication Protocol" service gives "The system cannot find the file specified" error | Vista networking & sharing | |||
| What do "Windows Update" and "system restore" have in common? | Vista General | |||
| Unwanted Multiple contacts in "To","CC","BCC" of email send catago | Vista mail | |||
| Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" | Vista General | |||
| WM5 Sync with Vista "Windows Calender", "Contacts", and "Mail" | Vista General | |||