Powershell Function return array -
i have problem when i'm trying return array powershell function.
my function:
function filter-swcluster { param($path, $folderlist) $oldswcluster = new-object system.collections.arraylist foreach ($y in $folderlist) { get-childitem -path $path -filter $y* | sort { [version]($_.name -replace '^.*_(\d+(\.\d+){1,3})$', '$1') } -descending | select-object -skip 3 | foreach-object { $oldswcluster.add($path + "\" + $_) } } write-output $oldswcluster }
the function call:
$filerswcluster = filter-swcluster $networkpath $swcluster
the output get:
0 1 \\server.domain\c$\temp\folders\testcluster_1.0.2 \\server.domain\c$\temp\folders\testcluster_1.0.1
the output want , need be:
\\server.domain\c$\temp\folders\testcluster_1.0.2 \\server.domain\c$\temp\folders\testcluster_1.0.1
i need paths. know there solutions, please excuse me don't found 1 working me or dumb use right (could be).
i hope of can me.
thanks
you wrap add method [void] class accelerator, hide output, this:
function filter-swcluster { param($path, $folderlist) $oldswcluster = new-object system.collections.arraylist foreach ($y in $folderlist) { get-childitem -path $path -filter $y* | sort { [version]($_.name -replace '^.*_(\d+(\.\d+){1,3})$', '$1') } -descending | select-object -skip 3 | foreach-object { [void]$oldswcluster.add($path + "\" + $_) } } write-output $oldswcluster }
Comments
Post a Comment