Hi guys, I have a starting script for system info, that needs to be exported to a csv. If I export the $Disk info only, this saves correctly, but as part of the script (see below) just returns as SYSTEM Object? I need to record capacity, used space and %free per disk, and export as part of a wider script:
[pre]
$Disk = Get-WmiObject -Class Win32_LogicalDisk -Filter “DriveType=3” | Sort-Object -Property Name | Select-Object Name, `
@{“Label”=“DiskSize(GB)”;“Expression”={“{0:N2}” -f ($.Size/1GB) -as [float]}}, `
@{“Label”=“FreeSpace(GB)”;“Expression”={“{0:N2}” -f ($.FreeSpace/1GB) -as [float]}}, `
@{“Label”=“% Free”;“Expression”={“{0:N}” -f ($.FreeSpace/$.Size*100) -as [float]}}
$H = $Env:Computername
$Path = “C:\Test”
$OS = (Get-WMIObject win32_operatingsystem)
$OSName = $OS.caption
$Serial = (Get-WMIObject win32_Bios).Serialnumber
$ipV4 = (Test-Connection -ComputerName ($H) -Count 1 | Select -ExpandProperty IPV4Address).IPAddressToString
#Memory Info:
$Mem = Get-WMIObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum | Foreach {“{0:N2}” -f ([math]::round(($_.Sum / 1GB),2))}
$PctFree = [math]::Round(($OS.FreePhysicalMemory/$OS.TotalVisibleMemorySize)*100,2)
$PCTFree = $PctFree = " %"
$Free = [math]::Round($OS.FreePhysicalMemory/1mb,2)
$Used = ($Mem - $Free)
$Mem = $Mem + " GB"
$Page = (Get-Counter “\$H\Memory\Pool Paged Bytes”).Countersamples | Select-Object -ExpandProperty cookedvalue
$Page = (“{0:N2}” -f ([math]::Round($Page/1mb)))
$Page = “Page File Size : " +$Page + " Mb”
#CPU Info:
$CPUInfo = ((get-counter -Counter “\Processor(_Total)% Processor Time” -SampleInterval 1 -MaxSamples 10 |
select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average)
$CPU = (“{0:N2}” -f ($CPUInfo))
$CPU = “CPU Used: " + $CPU + " %”
$Output = [pscustomobject]@{
ServerName = $H
OperatingSystem = $OSName
SerialNumber = $Serial
Memory = $Mem
Used = $Used
PercentFree = $PctFree
Paged = $Page
CPU = $CPU
Disks = $Disk
}
$Output | Export-CSV -Path $Path$H.csv -NoTypeInformation
[/pre]
Is there a better way to do this, and so it actually shows the information? If I run the following separately, this creates a csv with the relevant information:
[pre]
$DISK = “C:\Test\2-Disks.csv”
Get-WmiObject -Class Win32_LogicalDisk |
Where-Object {$.DriveType -ne 5} |
Sort-Object -Property Name |
Select-Object Name, VolumeName, VolumeSerialNumber, FileSystem, Description, `
@{“Label”=“DiskSize(GB)”;“Expression”={“{0:N}” -f ($.Size/1GB) -as [float]}}, `
@{“Label”=“FreeSpace(GB)”;“Expression”={“{0:N}” -f ($.FreeSpace/1GB) -as [float]}}, `
@{“Label”=“%Free”;“Expression”={“{0:N}” -f ($.FreeSpace/$_.Size*100) -as [float]}} | Export-CSV $DISK -noTypeInformation
[/pre]
I need to combine this with other information.
Many thanks
Jason