PowerShell is an automation platform and scripting language for Windows and Windows Server that allows you to simplify the management of your systems. We can automate lot of tasks with PowerShell and get usefull info from PC'S in your company. If you don't have a Monitoring System to check Info like Ram, Cpu ,Disk , Free Space from your PC in your Enviromet how can get these usefull info? If you use PowerShell with Wmi you can query every PC in your enviroment and get your info that you want.
Today i will explain how can get RAM, cpu and Local Disk Space from a Remote PC with Simple Commands.
Let's Start
Open PowerShell
- We can start with Local Disk C Size of a PC. Type
Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" -Computer ktzouvaras
- Now we can identify what CPU has.
Get-WmiObject Win32_processor -ComputerName ktzouvaras
- What about Physical Memory
Get-WmiObject Win32_physicalmemory -ComputerName ktzouvaras
- Lot of informations? Type
Get-WmiObject Win32_physicalmemory -ComputerName ktzouvaras | Select capacity
- Find the Operating System
Get-WmiObject win32_OperatingSystem -ComputerName ktzouvaras
But how can have all these info in one command?
Now we must create a Powershell Object to run all these commands.
- Create a notepad and type the following lines
$bios = Get-WmiObject win32_OperatingSystem -ComputerName localhost | Select PSComputername
$Proc = Get-WmiObject Win32_processor -ComputerName localhost | Select-Object -First 1
$memory = Get-WmiObject Win32_physicalmemory -ComputerName localhost
$system= Get-WmiObject Win32_ComputerSystem -ComputerName localhost
$localdisk=Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" -ComputerName localhost
$Object = New-Object PSObject -Property @{
ComputerName = $proc.SystemName
Model = $system.Model
'Processor Number' = $system.NumberOfProcessors
'Processor Name' = $proc.name
'Logical Processeur' = $system.NumberOfLogicalProcessors
'RAM (GB)' = $system.TotalPhysicalMemory / 1GB -as [int]
'Used RAM slot' = $memory.count
'Local Disk c' = $localdisk.size / 1GB -as [int]
}
Write-Output $Object
- Change the extension from txt to ps1.
- Open Powershell go in the path that you have save the file and type
.\report.ps1 - Can you see the results?
If you want you can use an Export-Csv Command to get the Report in CSV.
You can get these info from all your PC in your company with only one command and use it every time that you need it.
It's amazing how can automate tasks!!!
Do you have any comment? Are you intresting for the script and want to share any thought? Write your comments here to share it.