Add modules from WinAPI

This commit is contained in:
Alex Kup 2023-12-19 00:06:14 +03:00 committed by GitHub
parent bbfdb5d61f
commit 27a1568d53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 9 deletions

9
Scripts/Get-CPUse.psm1 Normal file
View file

@ -0,0 +1,9 @@
function Get-CPUse {
$CPU_Use_Proc = [string]((Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor -ErrorAction Ignore |
Where-Object name -eq "_Total").PercentProcessorTime)+" %"
$CollectionCPU = New-Object System.Collections.Generic.List[System.Object]
$CollectionCPU.Add([PSCustomObject]@{
CPU = $CPU_Use_Proc
})
$CollectionCPU
}

30
Scripts/Get-Files.psm1 Normal file
View file

@ -0,0 +1,30 @@
function Get-Files {
param (
[Parameter(Mandatory)][string]$Path
)
$files = Get-ChildItem $Path
$Collection_Files = New-Object System.Collections.Generic.List[System.Object]
foreach ($file in $files) {
if ($file.Length -eq 1) {
$type = "Directory"
$size = (Get-ChildItem -Path $file.FullName -Recurse -ErrorAction Ignore | Measure-Object -Property Length -Sum).Sum/1gb
$size = [string]([double]::Round($size, 3))+" GB"
} else {
$type = "File"
$size = $file.Length / 1gb
$size = [string]([double]::Round($size, 3))+" GB"
}
$Collection_Files.Add([PSCustomObject]@{
Name = $file.Name
FullName = $file.FullName
Type = $type
Size = $size
CreationTime = Get-Date -Date $file.CreationTime -Format "dd/MM/yyyy hh:mm:ss"
LastAccessTime = Get-Date -Date $file.LastAccessTime -Format "dd/MM/yyyy hh:mm:ss"
LastWriteTime = Get-Date -Date $file.LastWriteTime -Format "dd/MM/yyyy hh:mm:ss"
})
}
$Collection_Files
}
# Get-Files -Path "C:/"
# Get-Files -Path "C:/Program Files/"

View file

@ -26,6 +26,7 @@ function Get-Hardware {
$pm = ((($GetProcess).PM | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB")
$Memory = Get-CimInstance Win32_OperatingSystem
$MemUse = $Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory
$MemUserProc = ($MemUse / $Memory.TotalVisibleMemorySize) * 100
$MEM = Get-CimInstance Win32_PhysicalMemory | Select-Object Manufacturer,PartNumber,
ConfiguredClockSpeed,@{Label="Memory"; Expression={[string]($_.Capacity/1Mb)}}
$MEMs = $MEM.Memory | Measure-Object -Sum
@ -65,6 +66,7 @@ function Get-Hardware {
HandlesCount = $Handles_Count
MemoryAll = [string]$($MEMs.Sum/1Kb)+" GB"
MemoryUse = ($MemUse/1mb).ToString("0.00 GB")
MemoryUseProc = [string]([int]$MemUserProc)+" %"
WorkingSet = $ws
PageMemory = $pm
MemorySlots = $MEMs.Count

View file

@ -3,14 +3,16 @@ function Get-LD {
Label="Value"; Expression={$_.DeviceID}}, @{Label="AllSize"; Expression={
([int]($_.Size/1Gb))}},@{Label="FreeSize"; Expression={
([int]($_.FreeSpace/1Gb))}}, @{Label="Free%"; Expression={
[string]([int]($_.FreeSpace/$_.Size*100))+" %"}}
[string]([int]($_.FreeSpace/$_.Size*100))+" %"}},FileSystem,VolumeName
$CollectionLD = New-Object System.Collections.Generic.List[System.Object]
$LogicalDisk | ForEach-Object {
$CollectionLD.Add([PSCustomObject]@{
Logical_Disk = $_.Value
AllSize = [string]$_.AllSize+" Gb"
FreeSize = [string]$_.FreeSize+" Gb"
Free = $_."Free%"
FileSystem = $_.FileSystem
VolumeName = $_.VolumeName
AllSize = [string]$_.AllSize+" Gb"
FreeSize = [string]$_.FreeSize+" Gb"
Free = $_."Free%"
})
}
$CollectionLD

View file

@ -1,15 +1,17 @@
function Get-MemorySize {
$Memory = Get-CimInstance Win32_OperatingSystem
$MemUse = $Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory
$MemUserProc = ($MemUse / $Memory.TotalVisibleMemorySize) * 100
$GetProcess = Get-Process
$ws = ((($GetProcess).WorkingSet | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB")
$pm = ((($GetProcess).PM | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB")
$CollectionMemory = New-Object System.Collections.Generic.List[System.Object]
$CollectionMemory.Add([PSCustomObject]@{
MemoryAll = ($memory.TotalVisibleMemorySize/1mb).ToString("0.00 GB")
MemoryUse = ($MemUse/1mb).ToString("0.00 GB")
WorkingSet = $ws
PageMemory = $pm
MemoryAll = ($memory.TotalVisibleMemorySize/1mb).ToString("0.00 GB")
MemoryUse = ($MemUse/1mb).ToString("0.00 GB")
MemoryUseProc = [string]([int]$MemUserProc)+" %"
WorkingSet = $ws
PageMemory = $pm
})
$CollectionMemory
}