header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Inserting an element into an array after a certain element
Last Post 05 Feb 2008 12:39 PM by smurawski. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
DannyUser is Offline
New Member
New Member
Posts:10
Avatar

--
05 Feb 2008 07:31 AM  

Hello,

at the moment i am trying to insert an element into an existing array. I already found this example:

$Names = @("Susan","Phil","Bob")

$Names = $Names[1] + "Sara" + $Names[2..3]

My current problem is that i try to insert an integer value into an array full of integers like:

get-process | sort-object ID | select-object CPU, Name, Description, ID | ForEach-Object {$StartCPU += ,$_.CPU; $StartID += ,$_.id}

#$i  and $ end are just variables for an integer value

$StartID = $StartID[$i]+ '0' +$StartID[($+1)..($end-$i)]

 

I always get the message: Cannot convert "System.Object[]" to "System.Int32".

Is there a workaround for?

Thanks and greetz

Danny

 

I hope the software doesnt destroy the code this time ;)

 

smurawskiUser is Offline
New Member
New Member
Posts:46

--
05 Feb 2008 12:39 PM  
Danny,

When you assign your $StartID to ,$_.id, you are adding an array to $StartID, not an integer value.

You might want to try..

get-process | sort-object ID | select-object CPU, Name, Description, ID | ForEach-Object {$StartCPU = @(); $StartID = @()}{$StartCPU += $_.CPU; $StartID += $_.id}
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer