<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'sectionid:201' matching tag 'Array'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=sectionid%3A201&amp;tag=Array&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'sectionid:201' matching tag 'Array'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Powershell - Data put into an array goes away after exiting  ForEach-Object loops</title><link>http://powershell.com/cs/forums/thread/21260.aspx</link><pubDate>Fri, 25 Jan 2013 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:21260</guid><dc:creator>sdillinger1</dc:creator><description>&lt;p&gt;Originally I ran into this while trying to combine AD groups and user members into an array of objects&amp;nbsp;to process and export into a csv file but the following script fragment does the same thing. I am using Powershell ISE&amp;nbsp; Versiion 3 &lt;/p&gt;
&lt;p&gt;Clear-Host&lt;br /&gt;$Groups = &amp;#39;Group1&amp;#39;, &amp;#39;Group2&amp;#39;&lt;br /&gt;$Users = &amp;#39;User1&amp;#39;, &amp;#39;User2&amp;#39;&lt;br /&gt;[array]$GroupUsers=$null&lt;/p&gt;
&lt;p&gt;$OneGroupUsers = New-Object PSCustomObject&lt;br /&gt;Add-Member -InputObject $OneGroupUsers -MemberType NoteProperty -Name OneGroup -Value &amp;quot;&amp;quot;&lt;br /&gt;Add-Member -InputObject $OneGroupUsers -MemberType NoteProperty -Name OneUser -Value &amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt;$Groups | ForEach-Object {&lt;br /&gt;&amp;nbsp; $OneGroup = $_&amp;nbsp; #.SamAccountName&lt;br /&gt;&amp;nbsp; ######&amp;nbsp; Get-ADGroupMember -Identity $OneGroup -Recursive&lt;br /&gt;&amp;nbsp; $Users | ForEach-Object {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $OneUser = $_ #.SamAccountName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $OneGroupUsers.OneGroup =$OneGroup&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $OneGroupUsers.OneUser = $OneUser&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $GroupUsers += $OneGroupUsers&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;Inside the loops I seem to have the right data $($GroupUsers[-1]) &amp;quot;&lt;br /&gt;&amp;nbsp; } # End ForEach-Object&lt;br /&gt;}# End ForEach-Object&lt;/p&gt;
&lt;p&gt;Write-Host &amp;quot; what happened to the data once I exit the loops.&amp;quot;&lt;br /&gt;$GroupUsers.count&lt;/p&gt;
&lt;p&gt;$GroupUsers&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The results &lt;/p&gt;
&lt;p&gt;Inside the loops I seem to have the right data @{OneGroup=Group1; OneUser=User1}&lt;br /&gt;Inside the loops I seem to have the right data @{OneGroup=Group1; OneUser=User2}&lt;br /&gt;Inside the loops I seem to have the right data @{OneGroup=Group2; OneUser=User1}&lt;br /&gt;Inside the loops I seem to have the right data @{OneGroup=Group2; OneUser=User2}&lt;br /&gt;&amp;nbsp;what happened to the data once I exit the loops.&lt;br /&gt;4&lt;/p&gt;
&lt;p&gt;OneGroup&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OneUser&lt;br /&gt;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -------&lt;br /&gt;Group2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; User2&lt;br /&gt;Group2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; User2&lt;br /&gt;Group2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; User2&lt;br /&gt;Group2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; User2&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;What am I doing wrong??&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Invoke-Command -Args doesn't pass $myArray correctly</title><link>http://powershell.com/cs/forums/thread/10522.aspx</link><pubDate>Tue, 24 May 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:10522</guid><dc:creator>roswald72</dc:creator><description>&lt;p&gt;I&amp;#39;m looking the best way to pass an ascii file to $myArray, and then pass $myArray to a remote script using Invoke-Command -Args.&lt;/p&gt;
&lt;p&gt;Part of my problem is the content of the strings, part is the different types of $myArray, part is the limited environment of a remote session.&lt;/p&gt;
&lt;p&gt;First off, I&amp;#39;m finding that Invoke-Command using the -file option can only pass an argument through the -Args list? I got the -Args to work, but had no luck with adding a param() statement at the top of the remote script. can a param() statement be used in place of -Args? I found -Args and param() to be interchangeable except for the Invoke-Command... is this correct? It would save me lots of time if I know this to start.&lt;/p&gt;
&lt;p&gt;The results that I&amp;#39;m getting in the remote environment show the array delineation is not there. Using the GC or Get-Content works just fine with $myArray in every way until I try to work remotely and pass it through Invoke-Command -Args. &lt;/p&gt;
&lt;p&gt;I can pass a simple hash table through the Invoke-Command -Args and it works. I can pass a simple array through the Invoke-Command and it works, showing that the Invoke-Command -Args can pass arrays, hash tables and strings... it&amp;#39;s just $myArray that does not work.&lt;/p&gt;
&lt;p&gt;I am reading the array in with a Get-Content call, so I&amp;#39;m assuming it has line feeds and carriage returns, and the array delineation is the end of the line, not a hard comma or semicolon.&lt;/p&gt;
&lt;p&gt;Here is $myArray... The syntax of the ascii.txt makes for another difficultly in choosing escape characters and delineators, thankfully, it does not have commas or semicolons.&lt;/p&gt;
&lt;p&gt;contents of ascii.txt&lt;/p&gt;
&lt;p&gt;1&amp;quot; = 1&amp;#39;&lt;br /&gt;1&amp;quot; = 100&amp;#39;&lt;br /&gt;1&amp;quot; = 200&amp;#39;&lt;br /&gt;1&amp;quot; = 300&amp;#39;&lt;br /&gt;1&amp;quot; = 400&amp;#39;&lt;br /&gt;1&amp;quot; = 500&amp;#39;&lt;br /&gt;1&amp;quot; = 800&amp;#39;&lt;br /&gt;1&amp;quot; = 1000&amp;#39;&lt;br /&gt;1&amp;quot; = 2000&amp;#39;&lt;br /&gt;3/8&amp;quot; = 1&amp;#39;-0&amp;quot;&lt;br /&gt;1/2&amp;quot; = 1&amp;#39;-0&amp;quot;&lt;br /&gt;3/4&amp;quot; = 1&amp;#39;-0&amp;quot;&lt;br /&gt;1&amp;quot; = 1&amp;#39;-0&amp;quot;&lt;br /&gt;1 1/2&amp;quot; = 1&amp;#39;-0&amp;quot;&lt;/p&gt;
&lt;p&gt;Actually, I&amp;#39;m considering converting the ascii.txt file to hex just to escape all these escape characters. The foot mark at the end jams most array commands, the &amp;quot; jams it again, and / and = and spaces and so on...&lt;/p&gt;
&lt;p&gt;So my big question here is how do I create a strongly typed array to get this ascii.txt contents through the Invoke-Command -Args in a way to show the values correctly in a remote session.&lt;/p&gt;
&lt;p&gt;Currently, in the remote session, I get the first few characters like this:&lt;/p&gt;
&lt;p&gt;1&lt;br /&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;=&lt;/p&gt;
&lt;p&gt;1&lt;/p&gt;
&lt;p&gt;and then it just stops... &lt;/p&gt;
&lt;p&gt;So it appears that the array delineation is not there to keep these strings together... something goes wrong with $myArray in the Invoke-Command -Args list.&lt;/p&gt;
&lt;p&gt;Can you help with my $myArray?&lt;/p&gt;
&lt;p&gt;Could hex coding and decoding be worth looking into in this situation?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m currently tring to make the above ascii.txt into one long string, seperated by commas, and then feed that into an $array variable and then see if it&amp;#39;s different in the Invoke-Command -Args&lt;/p&gt;
&lt;p&gt;Any help would be greatly appreciated.&lt;/p&gt;
&lt;p&gt;Rich Oswald&lt;br /&gt;&lt;a href="mailto:roswald72@hotmail.com"&gt;roswald72@hotmail.com&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Value Not Found in Array</title><link>http://powershell.com/cs/forums/thread/9959.aspx</link><pubDate>Tue, 12 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9959</guid><dc:creator>ntxdba</dc:creator><description>&lt;p&gt;I am new to powershell and am working with a script to dump data from a MSSQL table.&amp;nbsp; CodePlex mssqldump.ps1 is the script location.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The table has columns that return datatype of System.String, System.DateTime and System.Int32.&amp;nbsp; I created an array that contains System.String and System.DateTime.&lt;/p&gt;
&lt;p&gt;when I use -contains to check for existence of those two values I only find System.DateTime. using $column.DataType.&amp;nbsp; When I display the value it shows as System.String.&amp;nbsp; If I hardcode System.String into the check it is found but not when using the DataType property.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Below is a snippet of the code, any help would be appreciated.&lt;/p&gt;
&lt;p&gt;$typeArray = &amp;quot;System.Boolean&amp;quot; ,&amp;quot;System.Datetime&amp;quot; ,&amp;quot;System.Char&amp;quot;, &amp;quot;System.Guid&amp;quot;, &amp;quot;System.String&amp;quot;&lt;br /&gt;&amp;nbsp;if ($typeArray -contains $column.Datatype)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { $quote = &amp;quot;&amp;#39;&amp;quot;}&lt;br /&gt;&amp;nbsp;else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {$quote = &amp;quot;&amp;quot;}&lt;/p&gt;</description></item></channel></rss>