How to reject the return value for a function in PowerShell?

I have an interesting problem for a while. Let them say that I have a function

function GetAllFiles($creds, $fld){
   $newFiles = New-Object "system.collections.generic.list[string]"
   ... other stuff which adds entires
   return $newFiles
}

On the call side when I perform

$files = GetAllFiles $creds $fld
$files.Remove("AnExistingEntry")

I get

dir-ls.ps1: the method call failed because [System.Object []] does not contain an od method named Delete.

When I $ NewFiles.GetType ()

IsPublic IsSerial Name                                     BaseType                
-------- -------- ----                                     --------                
True     True     Object[]                                 System.Array 

How can I do this "system.collections.generic.list [string]" back?

thank

+3
source share
1 answer

This type of object does not have a delete method. I think you are looking at the elements of an element:

$ files | gm will provide you with the elements of the first element of the array (the pipeline expands the array, and you end up executing gm for the first element.

gm -inputobject $files , "remove" .

return , , .

return, $newFiles

+2

All Articles