Are PowerShell arrays only .NET arrays?

I create an array of string objects in PowerShell , which must be passed to the Xceed method zip library, which expects the string [], but each time I get an error. This makes me wonder if the PowerShell array is anything other than a .NET array. Here is the code:

$string_list = @() foreach($f in $file_list) { $string_list += $f.FullName } [Xceed.Zip.QuickZip]::Zip("C:\new.zip", $true, $false, $false, $string_list) 

The error I get says: "Error adding files to zip file." If I hard code in such values, this works:

 [Xceed.Zip.QuickZip]::Zip("C:\new.zip", $true, $false, $false, "test.txt", "test2.txt", "test3.txt") 

Can someone help me figure this out? I don’t understand what the difference is ...

EDIT: I checked and confirmed that my $ string_list array consists of System.String objects

+4
source share
1 answer

When specifying:

 $string_list = @() 

You did not provide information about the PowerShell type, so it creates an array of System.Object, which is an array that can contain any object:

 PS> ,$string_list | Get-Member TypeName: System.Object[] 

Try specifying a specific type of array (string array) as follows:

 PS> [string[]]$string_list = @() PS> ,$string_list | Get-Member TypeName: System.String[] 
+15
source

All Articles