Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Error: "Cannot convert "System.Object[]" to "System.Int32"."

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-31-2008   #1 (permalink)
Shay Levi
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 SpecsSystem Spec
Old 01-31-2008   #2 (permalink)
David Kriz
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 SpecsSystem Spec
Old 01-31-2008   #3 (permalink)
Shay Levi
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 SpecsSystem Spec
Old 01-31-2008   #4 (permalink)
David Kriz
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 SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unwanted Multiple contacts in "To","CC","BCC" of email send catago xsailer Vista mail 1 07-26-2008 08:34 AM
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Platebanger Vista General 6 02-05-2008 08:54 AM
How can I add the icons "Delete", "Cut", "Copy" and "Paste" in Vis Moonwalker Vista file management 7 09-17-2007 05:55 PM
WM5 Sync with Vista "Windows Calender", "Contacts", and "Mail" Tony Vista General 1 02-16-2007 06:20 PM
Separate hashtable vs $alist | where-object { "key" = "value" } versus something else? ydroam PowerShell 2 12-12-2006 05:16 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com 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 2005-2008