Created
January 23, 2018 17:21
-
-
Save wpietrzakpl/a3754aad04658351e95675c0f3360fbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Iron Scripter Challenge v2 | |
.DESCRIPTION | |
Iron Scripter v2 | |
.EXAMPLE | |
PS C:\Users\Wojtek\Documents\WindowsPowerShell> . .\Iron-Scripter_2.ps1 | |
PS C:\Users\Wojtek\Documents\WindowsPowerShell> Iron-Scripter | |
cmdlet Iron-Scripter at command pipeline position 1 | |
Supply values for the following parameters: | |
ComputerName: localhost | |
OSName : Microsoft Windows 7 Professional |C:\Windows|\Device\Harddisk0\Partition2 | |
Version : 6.1.7601 | |
ServicePackMajor : 1 | |
ServicePackMinor : 0 | |
OSManufacturer : Microsoft Corporation | |
WindowsDirectory : C:\Windows | |
Locale : 0415 | |
AvailablePhysicalMemory : 1 | |
TotalVirtualMemory : 12 | |
AvailableVirtualMemory : 7 | |
Drive : C: | |
DriveType : 3 | |
Size : 111,69 | |
FreeSpace : 12,87 | |
Compressed : False | |
Drive : D: | |
DriveType : 2 | |
Size : 1,81 | |
FreeSpace : 0,43 | |
Compressed : False | |
.INPUTS | |
None | |
.OUTPUTS | |
None | |
.NOTES | |
Wojtek o1|2o18 | |
#> | |
function Iron-Scripter { | |
[cmdletbinding()] | |
param ( | |
[parameter(Mandatory = $true)] | |
[AllowEmptyString()] | |
[String] | |
$ComputerName | |
) | |
begin { | |
} | |
process { | |
try { | |
$objOperatingSystem = Get-CimInstance -Query 'SELECT * FROM Win32_OperatingSystem' -ComputerName $ComputerName -ErrorAction Stop | |
$PSObject = [PSCustomObject]@{ | |
OSName = $objOperatingSystem.Name | |
Version = $objOperatingSystem.Version | |
ServicePackMajor = $objOperatingSystem.ServicePackMajorVersion | |
ServicePackMinor = $objOperatingSystem.ServicePackMinorVersion | |
OSManufacturer = $objOperatingSystem.Manufacturer | |
WindowsDirectory = $objOperatingSystem.WindowsDirectory | |
Locale = $objOperatingSystem.Locale | |
AvailablePhysicalMemory = ([math]::Round($objOperatingSystem.FreePhysicalMemory / 1MB)) | |
TotalVirtualMemory = ([math]::Round($objOperatingSystem.TotalVirtualMemorySize / 1MB)) | |
AvailableVirtualMemory = ([math]::Round($objOperatingSystem.FreeVirtualMemory / 1MB)) | |
} | |
$PSObject | |
} | |
catch { | |
Write-Host "Check ComputerName to use Win32_OperatingSystem CIM Query" -foreground red | |
} | |
try { | |
$disks = Get-CimInstance -Query 'SELECT * FROM Win32_LogicalDisk' -ComputerName $ComputerName -ErrorAction Stop | |
foreach ($objDisk in $disks ) { | |
$PSObject = [PSCustomObject]@{ | |
Drive = $objDisk.DeviceID | |
DriveType = $objDisk.DriveType | |
Size = ([math]::Round($objDisk.Size / 1GB, 2)) | |
FreeSpace = ([math]::Round($objDisk.FreeSpace / 1GB, 2)) | |
Compressed = $objDisk.Compressed | |
} | |
$PSObject | |
} | |
} | |
catch { | |
Write-Host "Check ComputerName to use Win32_LogicalDisk CIM Query " -foreground red | |
} | |
} | |
end { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment