This is the code I am using to generate Csv file which contains Columns ComputerName, Memory %, CPU %, RAM(GB), No.Of Processors, Connections in order. I am getting the same when I run in powershell.exe, but format changes when I export to CSV. Can someone modify this and help me. Thank you.
function Get-DA8Stats
{
[cmdletbinding()]
param
(
[parameter(mandatory=$True, ValueFromPipeline=$true, HelpMessage=“Computer name or IP address”)]
[ValidateCount(1,40)]
[ValidateNotNullOrEmpty()]
[string]$ComputerName
)
begin
{}
process
{
foreach ($computer in $ComputerName)
{
$memorysize = [math]::round((Get-WmiObject -ClassName Win32_OperatingSystem -ComputerName $computer).TotalVisibleMemorySize / 1mb)
$numberofprocessors = Get-WmiObject -ClassName Win32_computersystem -ComputerName $computer | select-object NumberOfLogicalProcessors
$daconnections = Get-RemoteAccessConnectionStatisticsSummary -ComputerName $computer | Select-Object totaldaconnections
$proc = Get-WmiObject -computername $computer win32_processor | Measure-Object -property LoadPercentage -Average | Select-Object Average
$mem = gwmi -Class win32_operatingsystem -computername $computer | Select-Object @{Name = “MemoryUsage”; Expression = {“{0:N2}” -f ((($.TotalVisibleMemorySize - $.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$paras = @{“RAM(GB)” = $memorysize;
“No.Of Processors” = $numberofprocessors.numberoflogicalprocessors;
“ComputerName” = $computer;
“Connections” = $daconnections.totaldaconnections;
“Memory %” = $mem.memoryusage;
“CPU %” = $proc.average
}
$obj = New-Object -TypeName psobject -Property $paras
$obj.psobject.typenames.insert(0, “DA.SystemInfo”)
Write-Output $obj
}
}
end {}
}
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString(‘MM-dd-yyyy_hh-mm-ss’)
Update-FormatData -PrependPath C:\scripts\DATest.format.ps1xml
Get-DA8Stats -ComputerName (Get-Content -Path C:\test\servers.txt) | Export-Csv -NoTypeInformation -Path “C:\DA8Data_$CurrentDate.csv”