Hi All,
Apologies if the title is a bit confusing, not sure which one it is.
I’m having issues with output on a Get-DAMultiSite script I’m writing. It part works, the first part of the script before creating the array does the output I want, but if I want a count of users, it only outputs the users on the last server, not all servers. I’m getting weird results
$UserSummary = @()
$Servers = Get-DAMultiSite | Select -ExpandProperty DAEntryPoints | Select -ExpandProperty Servers | Sort
Foreach ($Server in $Servers)
{$Users = Get-RemoteAccessConnectionStatistics -ComputerName $Server | Where { $.HostName -like “ABC*” } | Select @{ Label = “Server”; Expression = { ( $Server ).ToString() }},UserName,HostName,ConnectionStartTime,@{ Label = “ConnectionDuration”; Expression = { ( New-TimeSpan -Seconds $.ConnectionDuration ).ToString() }} | Sort Server,UserName }
Foreach ($User in $Users) {
$UserObject = New-Object PSObject
$UserObject | Add-Member -MemberType NoteProperty -Name “Server” -Value $User.Server
$UserObject | Add-Member -MemberType NoteProperty -Name “UserName” -Value $User.Username
$UserObject | Add-Member -MemberType NoteProperty -Name “HostName” -Value $Users.HostName
$UserObject | Add-Member -MemberType NoteProperty -Name “Connection Start Time” -Value $User.ConnectionStartTime
$UserObject | Add-Member -MemberType NoteProperty -Name “Connection Duration” -Value $User.ConnectionDuration
$UserSummary += $UserObject
}
$UserSummary | ft
Could do with some pointers to gather the whole lot.
This bit delivers what I want to see,
$Servers = Get-DAMultiSite | Select -ExpandProperty DAEntryPoints | Select -ExpandProperty Servers | Sort
Foreach ($Server in $Servers)
{$Users = Get-RemoteAccessConnectionStatistics -ComputerName $Server | Where { $.HostName -like “ABC*” } | Select @{ Label = “Server”; Expression = { ( $Server ).ToString() }},UserName,HostName,ConnectionStartTime,@{ Label = “ConnectionDuration”; Expression = { ( New-TimeSpan -Seconds $.ConnectionDuration ).ToString() }} | Sort Server,UserName }
but I can’t get it all in a variable, say $UserSummary.Count and only shows for the last server queried.
Thank you all