I am automating health check for some of the windows servers. I am very new to PowerShell (started today).
I want the CPU and Memory utilization of a windows server at an instant to be recorded in an Excel workbook in different sheets. After googling and following the documents, I have found the commands to retrieve this data using Win32_processor and win32_operatingsystem classes.
I am using Export-CSV cmdlet which directly copies the output to the excel.
I am using New-Object cmdlet and created a psobject to get both the outputs added to the property and then pasted in excel.
$Memory = gwmi win32_operatingsystem | Select-Object @{Name = "MemoryUsage"; Expression = {"{0:N2}" -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$CPU = gwmi win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
$Props = @{"Memory"= $Memory ; "CPU Utilization" = $CPU}
$Mydata = New-Object -TypeName psobject -Property $Props
$MYdata | Export-Csv C:\Users\Mitu\Desktop\output-excel.csv -nti
Any other way to get this things done?
Also, I want to send this csv to our email id. What things are required to achieve this via powershell?