To start with, you don't need this line any more, so remove it:
foreach ($poweruser in $Powermembers) { $powerlist = $powerlist + $poweruser + "," }
Your script isn't doing any error checking, it just adds everything it finds and if an error happens the results from the last computer have not been erased and get added again. When your script is doing something in a loop, start by erasing the values before you get started, like this:
$adminList = ""
$adminGroup = $null
$adminMembers = $null
There are many methods and places to add error checking, but to start with try this:
function get-localusers {
param(
[Parameter(Mandatory=$true,valuefrompipeline=$true)]
[string]$computerName
)
begin {}
Process {
$adminList = ""
$adminGroup = $null
$adminMembers = $null
$computer = [ADSI]("WinNT://" + $computerName + ",computer")
$resultsOutput = New-Object psobject
$resultsOutput | Add-Member noteproperty ComputerName $computerName
Write-Host "Contacting $computerName... " -NoNewline
$adminGroup = $computer.psbase.children.find("Administrators")
if ($? -eq $True) {
$adminMembers = $adminGroup.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
foreach ($adminName in $adminMembers) {$adminList = $adminList + $adminName + ","}
$resultsOutput | Add-Member noteproperty Administrators $adminList
Write-Host "Success."
}
Write-Output $resultsOutput
}
end {}
}
Get-Content D:\script.txt | get-localusers | Export-Csv D:\usersnow.txt -NoTypeInformation