Thank You Cruisader. I updated post per recommendation of a co-worker. I am reposting script with your suggested updates. I am now receiving
cmdlet ForEach-Object at command pipeline postion 1
Supply values for the following parameters:
Process[0]:
$_.trim().ToUpper()
Any suggestions?
########################
#Functions
########################
$arrExclude = "NT AUTHORITY\LocalService",
"NT AUTHORITY\Local Service",
"NT AUTHORITY\NETWORK SERVICE",
"NT AUTHORITY\NetworkService",
"LocalSystem",
".\ASPNET"
function checkExclusions([string]$strval)
{
foreach ($val in $arrExclude)
{if ($val.ToLower() -eq $strval){return $true} }
return $false
}
function Ping ( [string] $strComputer )
{
$timeout=120;
trap { continue; }
$ping = new-object System.Net.NetworkInformation.Ping
$reply = new-object System.Net.NetworkInformation.PingReply
$reply = $ping.Send($strComputer, $timeout);
if( $reply.Status -eq "Success" )
{
return $true;
}
return $false;
}
########################
#Script
########################
$pathFolder = "D:\ServerBiYearlyScan\CRL\Group"
$computersList = get-content "$pathFolder\CRLServerList.txt"
$ArrayUser = @()
$ArrayGroup = @()
$ArrayKey = @()
$ArrayService = @()
$ArrayShare = @()
$ArrayAccess = @()
foreach($computer in $computersList)
{
#################################################################################################
$retPing = Ping $computer
if($retPing -eq $true)
{
#Disabling the error on the screen
$errorActionPreference="SilentlyContinue"
$testAccss = get-wmiobject Win32_OperatingSystem -computername $computer -ErrorVariable ERR
If($ERR)
{$Access = $false}
else{$Access = $true}
}
else{$Access = $false}
if($Access -eq $false)
{
#Srv not ping or denied
$obj=New-Object PSObject
$obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
$obj | Add-Member Noteproperty -Name "PING" -Value $retPing
$obj | Add-Member Noteproperty -Name "ACCESS" -Value $Access
$ArrayAccess += $obj
}
else{
#Working on it
#################################################################################################
$namespace = "root\CIMV2"
$results = Get-WmiObject -class Win32_Group -computername $computer -namespace $namespace -filter "localaccount=true"
foreach($result in $results)
{
$GroupName = $result.name
$group =[ADSI]"WinNT://$computer/$GroupName"
$members = @($group.psbase.Invoke("Members"))
$list = $members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
if($list -ne $null)
{
$members = $list | ForEach-Object
{
$_.trim().ToUpper()
}
$obj=New-Object PSObject
$obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
$obj | Add-Member Noteproperty -Name "GroupName" -Value (($result.name).trim()).ToUpper()
$obj | Add-Member Noteproperty -Name "Member" -Value $members
$ArrayGroup += $obj
}
}
#################################################################################################
}
}
$ArrayGroup | select ServerName, GroupName, Member | Export-Csv "$pathFolder\CRLLocalGroups.csv"