From b709d7e96b37fdd6299599380d1b3e3cac23cf17 Mon Sep 17 00:00:00 2001 From: Lifailon Date: Mon, 29 Jan 2024 23:41:19 +0300 Subject: [PATCH] Added modules from WinAPI --- Scripts/Find-Process.psm1 | 20 ++- Scripts/Get-CPU.psm1 | 12 ++ Scripts/Get-CPUse.psm1 | 9 -- Scripts/{Get-LD.psm1 => Get-DiskLogical.psm1} | 39 ++--- Scripts/Get-DiskPartition.psm1 | 13 ++ Scripts/Get-DiskPhysical.psm1 | 23 +++ Scripts/Get-Driver.psm1 | 7 + Scripts/Get-Event.psm1 | 21 +++ Scripts/Get-Hardware.psm1 | 122 ++++++++++---- Scripts/Get-HardwareNoJob.psm1 | 126 +++++++++++++++ Scripts/Get-HardwareRSJob.psm1 | 149 ++++++++++++++++++ Scripts/Get-IOps.psm1 | 16 +- Scripts/Get-MemorySize.psm1 | 25 ++- Scripts/Get-MemorySlots.psm1 | 10 +- Scripts/Get-NetInterfaceStat.psm1 | 40 +++++ Scripts/Get-NetIpConfig.psm1 | 13 ++ Scripts/Get-Netstat.psm1 | 41 ++--- Scripts/Get-NetstatRemote.psm1 | 30 ++++ Scripts/Get-PD.psm1 | 14 -- Scripts/Get-Smart.psm1 | 22 +++ Scripts/Get-Software.psm1 | 8 + Scripts/Get-Temperature.psm1 | 11 ++ Scripts/Get-VideoCard.psm1 | 2 +- Scripts/Get-WinUpdate.psm1 | 9 ++ 24 files changed, 657 insertions(+), 125 deletions(-) create mode 100644 Scripts/Get-CPU.psm1 delete mode 100644 Scripts/Get-CPUse.psm1 rename Scripts/{Get-LD.psm1 => Get-DiskLogical.psm1} (58%) create mode 100644 Scripts/Get-DiskPartition.psm1 create mode 100644 Scripts/Get-DiskPhysical.psm1 create mode 100644 Scripts/Get-Driver.psm1 create mode 100644 Scripts/Get-Event.psm1 create mode 100644 Scripts/Get-HardwareNoJob.psm1 create mode 100644 Scripts/Get-HardwareRSJob.psm1 create mode 100644 Scripts/Get-NetInterfaceStat.psm1 create mode 100644 Scripts/Get-NetIpConfig.psm1 create mode 100644 Scripts/Get-NetstatRemote.psm1 delete mode 100644 Scripts/Get-PD.psm1 create mode 100644 Scripts/Get-Smart.psm1 create mode 100644 Scripts/Get-Software.psm1 create mode 100644 Scripts/Get-Temperature.psm1 create mode 100644 Scripts/Get-WinUpdate.psm1 diff --git a/Scripts/Find-Process.psm1 b/Scripts/Find-Process.psm1 index 770e89e..cef1c28 100644 --- a/Scripts/Find-Process.psm1 +++ b/Scripts/Find-Process.psm1 @@ -2,17 +2,23 @@ function Find-Process { param ( $ProcessName ) - $ProcessPath = (Get-ChildItem "C:\Program Files" | Where-Object Name -match $ProcessName).FullName - if ($null -eq $ProcessPath) { - $ProcessPath = (Get-ChildItem "C:\Program Files (x86)" | Where-Object Name -match $ProcessName).FullName + $PathSearchArray = @( + "$env:SystemDrive\Program Files", + "$env:SystemDrive\Program Files (x86)", + "$env:HOMEPATH\AppData\Roaming", + "$env:HOMEPATH\Documents" + ) + foreach ($PathSearch in $PathSearchArray) { + $ProcessPath = (Get-ChildItem $PathSearch | Where-Object Name -match $ProcessName).FullName + if ($null -ne $ProcessPath) { + break + } } - if ($null -eq $ProcessPath) { - $ProcessPath = (Get-ChildItem "C:\Users\lifailon\AppData\Roaming" | Where-Object Name -match $ProcessName).FullName - } - $ProcessNameExec = "$ProcessName"+".exe" + $ProcessNameExec = "$($ProcessName).exe" (Get-ChildItem $ProcessPath -Recurse | Where-Object Name -eq $ProcessNameExec).FullName } +# Find-Process OpenHardwareMonitor # C:\Users\lifailon\Documents\OpenHardwareMonitor-0.9.6\OpenHardwareMonitor-0.9.6\OpenHardwareMonitor.exe # Find-Process qbittorrent # C:\Program Files\qBittorrent\qbittorrent.exe # Find-Process nmap # C:\Program Files (x86)\Nmap\nmap.exe # Find-Process telegram # C:\Users\lifailon\AppData\Roaming\Telegram Desktop\Telegram.exe \ No newline at end of file diff --git a/Scripts/Get-CPU.psm1 b/Scripts/Get-CPU.psm1 new file mode 100644 index 0000000..1d4f120 --- /dev/null +++ b/Scripts/Get-CPU.psm1 @@ -0,0 +1,12 @@ +function Get-CPU { + $CPU_Perf = Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor + $CPU_Cores = $CPU_Perf | Where-Object Name -ne "_Total" | Sort-Object {[int]$_.Name} + $CPU_Total = $CPU_Perf | Where-Object Name -eq "_Total" + $CPU_All = $CPU_Cores + $CPU_Total + $CPU_All | Select-Object Name, + @{Label="ProcessorTime"; Expression={[String]$_.PercentProcessorTime+" %"}}, + @{Label="PrivilegedTime"; Expression={[String]$_.PercentPrivilegedTime+" %"}}, + @{Label="UserTime"; Expression={[String]$_.PercentUserTime+" %"}}, + @{Label="InterruptTime"; Expression={[String]$_.PercentInterruptTime+" %"}}, + @{Label="IdleTime"; Expression={[String]$_.PercentIdleTime+" %"}} +} diff --git a/Scripts/Get-CPUse.psm1 b/Scripts/Get-CPUse.psm1 deleted file mode 100644 index dd34c01..0000000 --- a/Scripts/Get-CPUse.psm1 +++ /dev/null @@ -1,9 +0,0 @@ -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 -} \ No newline at end of file diff --git a/Scripts/Get-LD.psm1 b/Scripts/Get-DiskLogical.psm1 similarity index 58% rename from Scripts/Get-LD.psm1 rename to Scripts/Get-DiskLogical.psm1 index ebf00ab..8f4ffc7 100644 --- a/Scripts/Get-LD.psm1 +++ b/Scripts/Get-DiskLogical.psm1 @@ -1,19 +1,22 @@ -function Get-LD { - $LogicalDisk = Get-CimInstance Win32_logicalDisk | Where-Object {$null -ne $_.Size} | Select-Object @{ - Label="Value"; Expression={$_.DeviceID}}, @{Label="AllSize"; Expression={ - ([int]($_.Size/1Gb))}},@{Label="FreeSize"; Expression={ - ([int]($_.FreeSpace/1Gb))}}, @{Label="Free%"; Expression={ - [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 - FileSystem = $_.FileSystem - VolumeName = $_.VolumeName - AllSize = [string]$_.AllSize+" Gb" - FreeSize = [string]$_.FreeSize+" Gb" - Free = $_."Free%" - }) - } - $CollectionLD +function Get-DiskLogical { + $LogicalDisk = Get-CimInstance Win32_logicalDisk | Where-Object {$null -ne $_.Size} | + Select-Object @{Label="Value"; Expression={$_.DeviceID}}, + @{Label="AllSize"; Expression={([int]($_.Size/1Gb))}}, + @{Label="FreeSize"; Expression={([int]($_.FreeSpace/1Gb))}}, + @{Label="Free%"; Expression={ + [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 + FileSystem = $_.FileSystem + VolumeName = $_.VolumeName + AllSize = [string]$_.AllSize+" Gb" + FreeSize = [string]$_.FreeSize+" Gb" + Free = $_."Free%" + }) + } + $CollectionLD } \ No newline at end of file diff --git a/Scripts/Get-DiskPartition.psm1 b/Scripts/Get-DiskPartition.psm1 new file mode 100644 index 0000000..7edae84 --- /dev/null +++ b/Scripts/Get-DiskPartition.psm1 @@ -0,0 +1,13 @@ +function Get-DiskPartition { + $PhysicalDisk = Get-CimInstance -Namespace root/Microsoft/Windows/Storage -ClassName MSFT_PhysicalDisk + $Partition = Get-CimInstance -Namespace root/Microsoft/Windows/Storage -ClassName MSFT_Partition | + Select-Object @{Label="Disk"; Expression={$PhysicalDisk | Where-Object DeviceId -eq $_.DiskNumber | Select-Object -ExpandProperty FriendlyName}}, + IsBoot, + IsSystem, + IsHidden, + IsReadOnly, + IsShadowCopy, + @{Label="OffSet"; Expression={($_.OffSet/1Gb).ToString("0.00 Gb")}}, + @{Label="Size"; Expression={($_.Size/1Gb).ToString("0.00 Gb")}} + $Partition | Sort-Object Disk,OffSet +} \ No newline at end of file diff --git a/Scripts/Get-DiskPhysical.psm1 b/Scripts/Get-DiskPhysical.psm1 new file mode 100644 index 0000000..0c08b8a --- /dev/null +++ b/Scripts/Get-DiskPhysical.psm1 @@ -0,0 +1,23 @@ +function Get-DiskPhysical { + $PhysicalDisk = Get-CimInstance Win32_DiskDrive | + Select-Object Model, + @{Label="Size"; Expression={[int]($_.Size/1Gb)}}, + Partitions, + InterfaceType, + Status, + ConfigManagerErrorCode, + LastErrorCode + $CollectionPD = New-Object System.Collections.Generic.List[System.Object] + $PhysicalDisk | ForEach-Object { + $CollectionPD.Add([PSCustomObject]@{ + Model = $_.Model + Size = [string]$_.Size+" Gb" + PartitionCount = $_.Partitions + Interface = $_.InterfaceType + Status = $_.Status + ConfigManagerErrorCode = $_.ConfigManagerErrorCode + LastErrorCode = $_.LastErrorCode + }) + } + $CollectionPD +} \ No newline at end of file diff --git a/Scripts/Get-Driver.psm1 b/Scripts/Get-Driver.psm1 new file mode 100644 index 0000000..6b0f376 --- /dev/null +++ b/Scripts/Get-Driver.psm1 @@ -0,0 +1,7 @@ +function Get-Driver { + Get-CimInstance -Class Win32_PnPSignedDriver | Select-Object DriverProviderName, + FriendlyName, + Description, + DriverVersion, + DriverDate +} \ No newline at end of file diff --git a/Scripts/Get-Event.psm1 b/Scripts/Get-Event.psm1 new file mode 100644 index 0000000..3f5882c --- /dev/null +++ b/Scripts/Get-Event.psm1 @@ -0,0 +1,21 @@ +function Get-Event { + param ( + [string]$LogName, + [switch]$List + ) + if ($List) { + Get-WinEvent -ListLog * | Where-Object RecordCount -gt 0 | + Select-Object RecordCount, + @{Name="LastWriteTime"; Expression={Get-Date -Date $($_.LastWriteTime) -UFormat "%d.%m.%Y %T"}}, + @{Name="FileSize"; Expression={($_.FileSize / 1024kb).ToString("0.00 Mb")}}, + LogIsolation, + LogType, + LogName | Sort-Object LogIsolation + } + else { + Get-WinEvent -LogName $LogName | Select-Object @{Name="TimeCreated"; Expression={Get-Date -Date $($_.TimeCreated) -UFormat "%d.%m.%Y %T"}}, + LevelDisplayName, + Level, + Message + } +} \ No newline at end of file diff --git a/Scripts/Get-Hardware.psm1 b/Scripts/Get-Hardware.psm1 index 5ea4ab4..be3700a 100644 --- a/Scripts/Get-Hardware.psm1 +++ b/Scripts/Get-Hardware.psm1 @@ -1,3 +1,8 @@ +Import-Module ThreadJob -ErrorAction Ignore +if (!(Get-Module ThreadJob)) { + Install-Module ThreadJob -Scope CurrentUser -Force +} + function Get-Hardware { param ( $ComputerName, @@ -6,51 +11,89 @@ function Get-Hardware { $Pass = "api" ) if ($null -eq $ComputerName) { - $Collection = New-Object System.Collections.Generic.List[System.Object] - $SYS = Get-CimInstance Win32_ComputerSystem - $BootTime = Get-CimInstance -ComputerName $srv Win32_OperatingSystem | Select-Object LocalDateTime,LastBootUpTime - $Uptime = ([string]($BootTime.LocalDateTime - $BootTime.LastBootUpTime) -split ":")[0,1] -join ":" - $BootDate = Get-Date -Date $BootTime.LastBootUpTime -Format "dd/MM/yyyy hh:mm:ss" - $OS = Get-CimInstance Win32_OperatingSystem - $BB = Get-CimInstance Win32_BaseBoard + # Creat jobs + Start-ThreadJob -Name SYS -ScriptBlock {Get-CimInstance Win32_ComputerSystem} | Out-Null + Start-ThreadJob -Name OS -ScriptBlock {Get-CimInstance Win32_OperatingSystem} | Out-Null + Start-ThreadJob -Name BB -ScriptBlock {Get-CimInstance Win32_BaseBoard} | Out-Null + Start-ThreadJob -Name CPU -ScriptBlock {Get-CimInstance Win32_Processor} | Out-Null + Start-ThreadJob -Name CPU_Use -ScriptBlock {Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor} | Out-Null + Start-ThreadJob -Name GetProcess -ScriptBlock {Get-Process} | Out-Null + Start-ThreadJob -Name MEM -ScriptBlock {Get-CimInstance Win32_PhysicalMemory} | Out-Null + Start-ThreadJob -Name PhysicalDisk -ScriptBlock {Get-CimInstance Win32_DiskDrive} | Out-Null + Start-ThreadJob -Name LogicalDisk -ScriptBlock {Get-CimInstance Win32_logicalDisk} | Out-Null + Start-ThreadJob -Name IOps -ScriptBlock {Get-CimInstance Win32_PerfFormattedData_PerfDisk_PhysicalDisk} | Out-Null + Start-ThreadJob -Name VideoCard -ScriptBlock {Get-CimInstance Win32_VideoController} | Out-Null + Start-ThreadJob -Name NetworkAdapter -ScriptBlock {Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true} | Out-Null + Start-ThreadJob -Name InterfaceStatCurrent -ScriptBlock {Get-CimInstance -ClassName Win32_PerfFormattedData_Tcpip_NetworkInterface} | Out-Null + Start-ThreadJob -Name InterfaceStatAll -ScriptBlock {Get-CimInstance -ClassName Win32_PerfRawData_Tcpip_NetworkInterface} | Out-Null + # Get data from jobs + Start-Sleep -Milliseconds 100 + while ($(Get-Job).State -contains "Running") { + Start-Sleep -Milliseconds 100 + } + $SYS = Get-Job -Name SYS | Receive-Job + $OS = Get-Job -Name OS | Receive-Job + $BB = Get-Job -Name BB | Receive-Job + $CPU = Get-Job -Name CPU | Receive-Job + $CPU_Use = Get-Job -Name CPU_Use | Receive-Job + $GetProcess = Get-Job -Name GetProcess | Receive-Job + $MEM = Get-Job -Name MEM | Receive-Job + $PhysicalDisk = Get-Job -Name PhysicalDisk | Receive-Job + $LogicalDisk = Get-Job -Name LogicalDisk | Receive-Job + $IOps = Get-Job -Name IOps | Receive-Job + $VideoCard = Get-Job -Name VideoCard | Receive-Job + $NetworkAdapter = Get-Job -Name NetworkAdapter | Receive-Job + $InterfaceStatCurrent = Get-Job -Name InterfaceStatCurrent | Receive-Job + $InterfaceStatAll = Get-Job -Name InterfaceStatAll | Receive-Job + Get-Job | Remove-Job -Force + # Select data + $Uptime = ([string]($OS.LocalDateTime - $OS.LastBootUpTime) -split ":")[0,1] -join ":" + $BootDate = Get-Date -Date $($OS).LastBootUpTime -Format "dd/MM/yyyy hh:mm:ss" $BBv = $BB.Manufacturer+" "+$BB.Product+" "+$BB.Version - $CPU = Get-CimInstance Win32_Processor | Select-Object Name, - @{Label="Core"; Expression={$_.NumberOfCores}}, - @{Label="Thread"; Expression={$_.NumberOfLogicalProcessors}} - $CPU_Use_Proc = [string]((Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor -ErrorAction Ignore | - Where-Object name -eq "_Total").PercentProcessorTime)+" %" - $GetProcess = Get-Process + $CPU = $CPU | Select-Object Name, + @{Label="Core"; Expression={$_.NumberOfCores}}, + @{Label="Thread"; Expression={$_.NumberOfLogicalProcessors}} + $CPU_Use_Proc = [string](($CPU_Use | Where-Object name -eq "_Total").PercentProcessorTime)+" %" $Process_Count = $GetProcess.Count $Threads_Count = $GetProcess.Threads.Count $Handles_Count = ($GetProcess.Handles | Measure-Object -Sum).Sum $ws = ((($GetProcess).WorkingSet | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB") $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)}} + $MemUse = $OS.TotalVisibleMemorySize - $OS.FreePhysicalMemory + $MemUserProc = ($MemUse / $OS.TotalVisibleMemorySize) * 100 + $MEM = $MEM | Select-Object Manufacturer,PartNumber,ConfiguredClockSpeed, + @{Label="Memory"; Expression={[string]($_.Capacity/1Mb)}} $MEMs = $MEM.Memory | Measure-Object -Sum - $PhysicalDisk = Get-CimInstance Win32_DiskDrive | Select-Object Model, - @{Label="Size"; Expression={[int]($_.Size/1Gb)}} + $PhysicalDisk = $PhysicalDisk | Select-Object Model, + @{Label="Size"; Expression={[int]($_.Size/1Gb)}} $PDs = $PhysicalDisk.Size | Measure-Object -Sum - $LogicalDisk = Get-CimInstance Win32_logicalDisk | Where-Object {$null -ne $_.Size} | Select-Object @{ - Label="Value"; Expression={$_.DeviceID}}, @{Label="AllSize"; Expression={ - ([int]($_.Size/1Gb))}},@{Label="FreeSize"; Expression={ - ([int]($_.FreeSpace/1Gb))}}, @{Label="Free%"; Expression={ - [string]([int]($_.FreeSpace/$_.Size*100))+" %"}} + $LogicalDisk = $LogicalDisk | Where-Object {$null -ne $_.Size} | + Select-Object @{Label="Value"; Expression={$_.DeviceID}}, + @{Label="AllSize"; Expression={([int]($_.Size/1Gb))}}, + @{Label="FreeSize"; Expression={([int]($_.FreeSpace/1Gb))}}, + @{Label="Free%"; Expression={[string]([int]($_.FreeSpace/$_.Size*100))+" %"}} $LDs = $LogicalDisk.AllSize | Measure-Object -Sum - $IOps = Get-CimInstance Win32_PerfFormattedData_PerfDisk_PhysicalDisk -ErrorAction Ignore | - Where-Object { $_.Name -eq "_Total" } | Select-Object Name,PercentDiskTime,PercentIdleTime, - PercentDiskWriteTime,PercentDiskReadTime,CurrentDiskQueueLength,DiskBytesPersec,DiskReadBytesPersec, - DiskReadsPersec,DiskTransfersPersec,DiskWriteBytesPersec,DiskWritesPersec - $VideoCard = Get-CimInstance Win32_VideoController | Select-Object @{ - Label="VideoCard"; Expression={$_.Name}}, @{Label="Display"; Expression={ - [string]$_.CurrentHorizontalResolution+"x"+[string]$_.CurrentVerticalResolution}}, - @{Label="vRAM"; Expression={($_.AdapterRAM/1Gb)}} + $IOps = $IOps | Where-Object { $_.Name -eq "_Total" } | Select-Object Name, + @{name="TotalTime";expression={"$($_.PercentDiskTime) %"}}, + @{name="IOps";expression={$_.DiskTransfersPersec}}, + @{name="ReadBytesPersec";expression={$($_.DiskReadBytesPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="WriteBytesPersec";expression={$($_.DiskWriteBytesPersec/1mb).ToString("0.000 MByte/Sec")}} + $VideoCard = $VideoCard | Select-Object @{Label="VideoCard"; Expression={$_.Name}}, + @{Label="Display"; Expression={[string]$_.CurrentHorizontalResolution+"x"+[string]$_.CurrentVerticalResolution}}, + @{Label="vRAM"; Expression={([int]$($_.AdapterRAM/1Gb))}} $VCs = $VideoCard.vRAM | Measure-Object -Sum - $NetworkAdapter = Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true $NAs = $NetworkAdapter | Measure-Object + $InterfaceStatCurrent = $InterfaceStatCurrent | Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1mb).ToString("0.000 MByte/Sec")}} + $InterfaceStatAll = $InterfaceStatAll | Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1gb).ToString("0.00 GByte")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1gb).ToString("0.00 GByte")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1gb).ToString("0.00 GByte")}} + $PortListenCount = $(Get-NetTCPConnection -State Listen).Count + $PortEstablishedCount = $(Get-NetTCPConnection -State Established).Count + $Collection = New-Object System.Collections.Generic.List[System.Object] $Collection.Add([PSCustomObject]@{ Host = $SYS.Name Uptime = $uptime @@ -75,10 +118,19 @@ function Get-Hardware { PhysicalDiskAllSize = [string]$PDs.Sum+" Gb" LogicalDiskCount = $LDs.Count LogicalDiskAllSize = [string]$LDs.Sum+" Gb" - DiskTotalTime = [string]$IOps.PercentDiskTime+" %" + DiskTotalTime = $IOps.TotalTime + DiskTotalIOps = $IOps.IOps + DiskTotalRead = $IOps.ReadBytesPersec + DiskTotalWrite = $IOps.WriteBytesPersec VideoCardCount = $VCs.Count VideoCardAllSize = [string]$VCs.Sum+" Gb" NetworkAdapterEnableCount = $NAs.Count + NetworkReceivedCurrent = $InterfaceStatCurrent.Received + NetworkSentCurrent = $InterfaceStatCurrent.Sent + NetworkReceivedTotal = $InterfaceStatAll.Received + NetworkSentTotal = $InterfaceStatAll.Sent + PortListenCount = $PortListenCount + PortEstablishedCount = $PortEstablishedCount }) $Collection } diff --git a/Scripts/Get-HardwareNoJob.psm1 b/Scripts/Get-HardwareNoJob.psm1 new file mode 100644 index 0000000..faba659 --- /dev/null +++ b/Scripts/Get-HardwareNoJob.psm1 @@ -0,0 +1,126 @@ +function Get-HardwareNoJob { + param ( + $ComputerName, + $Port = 8443, + $User = "rest", + $Pass = "api" + ) + if ($null -eq $ComputerName) { + $Collection = New-Object System.Collections.Generic.List[System.Object] + $SYS = Get-CimInstance Win32_ComputerSystem + $BootTime = Get-CimInstance -ComputerName $srv Win32_OperatingSystem | + Select-Object LocalDateTime, + LastBootUpTime + $Uptime = ([string]($BootTime.LocalDateTime - $BootTime.LastBootUpTime) -split ":")[0,1] -join ":" + $BootDate = Get-Date -Date $BootTime.LastBootUpTime -Format "dd/MM/yyyy hh:mm:ss" + $OS = Get-CimInstance Win32_OperatingSystem + $BB = Get-CimInstance Win32_BaseBoard + $BBv = $BB.Manufacturer+" "+$BB.Product+" "+$BB.Version + $CPU = Get-CimInstance Win32_Processor | + Select-Object Name, + @{Label="Core"; Expression={$_.NumberOfCores}}, + @{Label="Thread"; Expression={$_.NumberOfLogicalProcessors}} + $CPU_Use_Proc = [string]((Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor -ErrorAction Ignore | + Where-Object name -eq "_Total").PercentProcessorTime)+" %" + $GetProcess = Get-Process + $Process_Count = $GetProcess.Count + $Threads_Count = $GetProcess.Threads.Count + $Handles_Count = ($GetProcess.Handles | Measure-Object -Sum).Sum + $ws = ((($GetProcess).WorkingSet | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB") + $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 + $PhysicalDisk = Get-CimInstance Win32_DiskDrive | + Select-Object Model, + @{Label="Size"; Expression={[int]($_.Size/1Gb)}} + $PDs = $PhysicalDisk.Size | Measure-Object -Sum + $LogicalDisk = Get-CimInstance Win32_logicalDisk | Where-Object {$null -ne $_.Size} | + Select-Object @{Label="Value"; Expression={$_.DeviceID}}, + @{Label="AllSize"; Expression={([int]($_.Size/1Gb))}}, + @{Label="FreeSize"; Expression={([int]($_.FreeSpace/1Gb))}}, + @{Label="Free%"; Expression={[string]([int]($_.FreeSpace/$_.Size*100))+" %"}} + $LDs = $LogicalDisk.AllSize | Measure-Object -Sum + $IOps = Get-CimInstance Win32_PerfFormattedData_PerfDisk_PhysicalDisk -ErrorAction Ignore | + Where-Object { $_.Name -eq "_Total" } | + Select-Object Name, + @{name="TotalTime";expression={"$($_.PercentDiskTime) %"}}, + @{name="IOps";expression={$_.DiskTransfersPersec}}, + @{name="ReadBytesPersec";expression={$($_.DiskReadBytesPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="WriteBytesPersec";expression={$($_.DiskWriteBytesPersec/1mb).ToString("0.000 MByte/Sec")}} + $VideoCard = Get-CimInstance Win32_VideoController | + Select-Object @{Label="VideoCard"; Expression={$_.Name}}, + @{Label="Display"; Expression={[string]$_.CurrentHorizontalResolution+"x"+[string]$_.CurrentVerticalResolution}}, + @{Label="vRAM"; Expression={([int]$($_.AdapterRAM/1Gb))}} + $VCs = $VideoCard.vRAM | Measure-Object -Sum + $NetworkAdapter = Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true + $NAs = $NetworkAdapter | Measure-Object + $InterfaceStatCurrent = Get-CimInstance -ClassName Win32_PerfFormattedData_Tcpip_NetworkInterface | + Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1mb).ToString("0.000 MByte/Sec")}} + $InterfaceStatAll = Get-CimInstance -ClassName Win32_PerfRawData_Tcpip_NetworkInterface | + Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1gb).ToString("0.00 GByte")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1gb).ToString("0.00 GByte")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1gb).ToString("0.00 GByte")}} + $PortListenCount = $(Get-NetTCPConnection -State Listen).Count + $PortEstablishedCount = $(Get-NetTCPConnection -State Established).Count + $Collection.Add([PSCustomObject]@{ + Host = $SYS.Name + Uptime = $uptime + BootDate = $BootDate + Owner = $SYS.PrimaryOwnerName + OS = $OS.Caption + Motherboard = $BBv + Processor = $CPU[0].Name + Core = $CPU[0].Core + Thread = $CPU[0].Thread + CPU = $CPU_Use_Proc + ProcessCount = $Process_Count + ThreadsCount = $Threads_Count + HandlesCount = [int]$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 + PhysicalDiskCount = $PDs.Count + PhysicalDiskAllSize = [string]$PDs.Sum+" Gb" + LogicalDiskCount = $LDs.Count + LogicalDiskAllSize = [string]$LDs.Sum+" Gb" + DiskTotalTime = $IOps.TotalTime + DiskTotalIOps = $IOps.IOps + DiskTotalRead = $IOps.ReadBytesPersec + DiskTotalWrite = $IOps.WriteBytesPersec + VideoCardCount = $VCs.Count + VideoCardAllSize = [string]$VCs.Sum+" Gb" + NetworkAdapterEnableCount = $NAs.Count + NetworkReceivedCurrent = $InterfaceStatCurrent.Received + NetworkSentCurrent = $InterfaceStatCurrent.Sent + NetworkReceivedTotal = $InterfaceStatAll.Received + NetworkSentTotal = $InterfaceStatAll.Sent + PortListenCount = $PortListenCount + PortEstablishedCount = $PortEstablishedCount + }) + $Collection + } + else { + $url = "http://$ComputerName"+":$Port/api/hardware" + $EncodingCred = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("${User}:${Pass}")) + $Headers = @{"Authorization" = "Basic ${EncodingCred}"} + try { + Invoke-RestMethod -Headers $Headers -Uri $url + } + catch { + Write-Error "Error connection" + } + } +} \ No newline at end of file diff --git a/Scripts/Get-HardwareRSJob.psm1 b/Scripts/Get-HardwareRSJob.psm1 new file mode 100644 index 0000000..6016fbb --- /dev/null +++ b/Scripts/Get-HardwareRSJob.psm1 @@ -0,0 +1,149 @@ +Import-Module PoshRSJob -ErrorAction Ignore +if (!(Get-Module PoshRSJob)) { + Install-Module PoshRSJob -Scope CurrentUser -Force +} + +function Get-HardwareRSJob { + param ( + $ComputerName, + $Port = 8443, + $User = "rest", + $Pass = "api" + ) + i + f ($null -eq $ComputerName) { + # Creat jobs + Start-RSJob -Name SYS -ScriptBlock {Get-CimInstance Win32_ComputerSystem} | Out-Null + Start-RSJob -Name OS -ScriptBlock {Get-CimInstance Win32_OperatingSystem} | Out-Null + Start-RSJob -Name BB -ScriptBlock {Get-CimInstance Win32_BaseBoard} | Out-Null + Start-RSJob -Name CPU -ScriptBlock {Get-CimInstance Win32_Processor} | Out-Null + Start-RSJob -Name CPU_Use -ScriptBlock {Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor} | Out-Null + Start-RSJob -Name GetProcess -ScriptBlock {Get-Process} | Out-Null + Start-RSJob -Name MEM -ScriptBlock {Get-CimInstance Win32_PhysicalMemory} | Out-Null + Start-RSJob -Name PhysicalDisk -ScriptBlock {Get-CimInstance Win32_DiskDrive} | Out-Null + Start-RSJob -Name LogicalDisk -ScriptBlock {Get-CimInstance Win32_logicalDisk} | Out-Null + Start-RSJob -Name IOps -ScriptBlock {Get-CimInstance Win32_PerfFormattedData_PerfDisk_PhysicalDisk} | Out-Null + Start-RSJob -Name VideoCard -ScriptBlock {Get-CimInstance Win32_VideoController} | Out-Null + Start-RSJob -Name NetworkAdapter -ScriptBlock {Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true} | Out-Null + Start-RSJob -Name InterfaceStatCurrent -ScriptBlock {Get-CimInstance -ClassName Win32_PerfFormattedData_Tcpip_NetworkInterface} | Out-Null + Start-RSJob -Name InterfaceStatAll -ScriptBlock {Get-CimInstance -ClassName Win32_PerfRawData_Tcpip_NetworkInterface} | Out-Null + # Get data from jobs + Start-Sleep -Milliseconds 100 + while ($(Get-RSJob).State -contains "Running") { + Start-Sleep -Milliseconds 100 + } + $SYS = Get-RSJob -Name SYS | Receive-RSJob + $OS = Get-RSJob -Name OS | Receive-RSJob + $BB = Get-RSJob -Name BB | Receive-RSJob + $CPU = Get-RSJob -Name CPU | Receive-RSJob + $CPU_Use = Get-RSJob -Name CPU_Use | Receive-RSJob + $GetProcess = Get-RSJob -Name GetProcess | Receive-RSJob + $MEM = Get-RSJob -Name MEM | Receive-RSJob + $PhysicalDisk = Get-RSJob -Name PhysicalDisk | Receive-RSJob + $LogicalDisk = Get-RSJob -Name LogicalDisk | Receive-RSJob + $IOps = Get-RSJob -Name IOps | Receive-RSJob + $VideoCard = Get-RSJob -Name VideoCard | Receive-RSJob + $NetworkAdapter = Get-RSJob -Name NetworkAdapter | Receive-RSJob + $InterfaceStatCurrent = Get-RSJob -Name InterfaceStatCurrent | Receive-RSJob + $InterfaceStatAll = Get-RSJob -Name InterfaceStatAll | Receive-RSJob + Get-RSJob | Remove-RSJob -Force + # Select data + $Uptime = ([string]($OS.LocalDateTime - $OS.LastBootUpTime) -split ":")[0,1] -join ":" + $BootDate = Get-Date -Date $($OS).LastBootUpTime -Format "dd/MM/yyyy hh:mm:ss" + $BBv = $BB.Manufacturer+" "+$BB.Product+" "+$BB.Version + $CPU = $CPU | Select-Object Name, + @{Label="Core"; Expression={$_.NumberOfCores}}, + @{Label="Thread"; Expression={$_.NumberOfLogicalProcessors}} + $CPU_Use_Proc = [string](($CPU_Use | Where-Object name -eq "_Total").PercentProcessorTime)+" %" + $Process_Count = $GetProcess.Count + $Threads_Count = $GetProcess.Threads.Count + $Handles_Count = ($GetProcess.Handles | Measure-Object -Sum).Sum + $ws = ((($GetProcess).WorkingSet | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB") + $pm = ((($GetProcess).PM | Measure-Object -Sum).Sum/1gb).ToString("0.00 GB") + $MemUse = $OS.TotalVisibleMemorySize - $OS.FreePhysicalMemory + $MemUserProc = ($MemUse / $OS.TotalVisibleMemorySize) * 100 + $MEM = $MEM | Select-Object Manufacturer,PartNumber,ConfiguredClockSpeed, + @{Label="Memory"; Expression={[string]($_.Capacity/1Mb)}} + $MEMs = $MEM.Memory | Measure-Object -Sum + $PhysicalDisk = $PhysicalDisk | Select-Object Model, + @{Label="Size"; Expression={[int]($_.Size/1Gb)}} + $PDs = $PhysicalDisk.Size | Measure-Object -Sum + $LogicalDisk = $LogicalDisk | Where-Object {$null -ne $_.Size} | + Select-Object @{Label="Value"; Expression={$_.DeviceID}}, + @{Label="AllSize"; Expression={([int]($_.Size/1Gb))}}, + @{Label="FreeSize"; Expression={([int]($_.FreeSpace/1Gb))}}, + @{Label="Free%"; Expression={[string]([int]($_.FreeSpace/$_.Size*100))+" %"}} + $LDs = $LogicalDisk.AllSize | Measure-Object -Sum + $IOps = $IOps | Where-Object { $_.Name -eq "_Total" } | Select-Object Name, + @{name="TotalTime";expression={"$($_.PercentDiskTime) %"}}, + @{name="IOps";expression={$_.DiskTransfersPersec}}, + @{name="ReadBytesPersec";expression={$($_.DiskReadBytesPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="WriteBytesPersec";expression={$($_.DiskWriteBytesPersec/1mb).ToString("0.000 MByte/Sec")}} + $VideoCard = $VideoCard | Select-Object @{Label="VideoCard"; Expression={$_.Name}}, + @{Label="Display"; Expression={[string]$_.CurrentHorizontalResolution+"x"+[string]$_.CurrentVerticalResolution}}, + @{Label="vRAM"; Expression={([int]$($_.AdapterRAM/1Gb))}} + $VCs = $VideoCard.vRAM | Measure-Object -Sum + $NAs = $NetworkAdapter | Measure-Object + $InterfaceStatCurrent = $InterfaceStatCurrent | Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1mb).ToString("0.000 MByte/Sec")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1mb).ToString("0.000 MByte/Sec")}} + $InterfaceStatAll = $InterfaceStatAll | Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1gb).ToString("0.00 GByte")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1gb).ToString("0.00 GByte")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1gb).ToString("0.00 GByte")}} + $PortListenCount = $(Get-NetTCPConnection -State Listen).Count + $PortEstablishedCount = $(Get-NetTCPConnection -State Established).Count + $Collection = New-Object System.Collections.Generic.List[System.Object] + $Collection.Add([PSCustomObject]@{ + Host = $SYS.Name + Uptime = $uptime + BootDate = $BootDate + Owner = $SYS.PrimaryOwnerName + OS = $OS.Caption + Motherboard = $BBv + Processor = $CPU[0].Name + Core = $CPU[0].Core + Thread = $CPU[0].Thread + CPU = $CPU_Use_Proc + ProcessCount = $Process_Count + ThreadsCount = $Threads_Count + HandlesCount = [int]$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 + PhysicalDiskCount = $PDs.Count + PhysicalDiskAllSize = [string]$PDs.Sum+" Gb" + LogicalDiskCount = $LDs.Count + LogicalDiskAllSize = [string]$LDs.Sum+" Gb" + DiskTotalTime = $IOps.TotalTime + DiskTotalIOps = $IOps.IOps + DiskTotalRead = $IOps.ReadBytesPersec + DiskTotalWrite = $IOps.WriteBytesPersec + VideoCardCount = $VCs.Count + VideoCardAllSize = [string]$VCs.Sum+" Gb" + NetworkAdapterEnableCount = $NAs.Count + NetworkReceivedCurrent = $InterfaceStatCurrent.Received + NetworkSentCurrent = $InterfaceStatCurrent.Sent + NetworkReceivedTotal = $InterfaceStatAll.Received + NetworkSentTotal = $InterfaceStatAll.Sent + PortListenCount = $PortListenCount + PortEstablishedCount = $PortEstablishedCount + }) + $Collection + } + else { + $url = "http://$ComputerName"+":$Port/api/hardware" + $EncodingCred = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("${User}:${Pass}")) + $Headers = @{"Authorization" = "Basic ${EncodingCred}"} + try { + Invoke-RestMethod -Headers $Headers -Uri $url + } + catch { + Write-Error "Error connection" + } + } +} \ No newline at end of file diff --git a/Scripts/Get-IOps.psm1 b/Scripts/Get-IOps.psm1 index 1adb6a1..988e88e 100644 --- a/Scripts/Get-IOps.psm1 +++ b/Scripts/Get-IOps.psm1 @@ -1,6 +1,14 @@ function Get-IOps { - Get-CimInstance Win32_PerfFormattedData_PerfDisk_PhysicalDisk -ErrorAction Ignore | - Where-Object { $_.Name -ne "_Total" } | Select-Object Name,PercentDiskTime,PercentIdleTime, - PercentDiskWriteTime,PercentDiskReadTime,CurrentDiskQueueLength,DiskBytesPersec,DiskReadBytesPersec, - DiskReadsPersec,DiskTransfersPersec,DiskWriteBytesPersec,DiskWritesPersec + Get-CimInstance Win32_PerfFormattedData_PerfDisk_PhysicalDisk | Select-Object Name, + @{name="ReadWriteTime";expression={"$($_.PercentDiskTime) %"}}, # Процент времени, в течение которого физический диск занят обработкой запросов ввода-вывода + @{name="ReadTime";expression={"$($_.PercentDiskReadTime) %"}}, # Процент времени, в течение которого физический диск занят чтением данных + @{name="WriteTime";expression={"$($_.PercentDiskWriteTime) %"}}, # Процент времени, в течение которого физический диск занят записью данных + @{name="IdleTime";expression={"$($_.PercentIdleTime) %"}}, # Процент времени, в течение которого физический диск не занят (находится в режиме простоя) + @{name="QueueLength";expression={$_.CurrentDiskQueueLength}}, # Текущая длина очереди диска (количество запросов, которые ожидают обработки диском) + @{name="BytesPersec";expression={$($_.DiskBytesPersec/1mb).ToString("0.000 MByte/Sec")}}, # Скорость передачи данных через диск в байтах в секунду (объединенное значение для чтения и записи) + @{name="ReadBytesPersec";expression={$($_.DiskReadBytesPersec/1mb).ToString("0.000 MByte/Sec")}}, # Скорость чтения данных с диска в байтах в секунду + @{name="WriteBytesPersec";expression={$($_.DiskWriteBytesPersec/1mb).ToString("0.000 MByte/Sec")}}, # Скорость записи данных на диск в байтах в секунду + @{name="IOps";expression={$_.DiskTransfersPersec}}, # Общее количество операций ввода-вывода (чтение и запись) с диска в секунду + @{name="ReadsIOps";expression={$_.DiskReadsPersec}}, # Количество операций чтения с диска в секунду + @{name="WriteIOps";expression={$_.DiskWritesPersec}} # Количество операций записи на диск в секунду } \ No newline at end of file diff --git a/Scripts/Get-MemorySize.psm1 b/Scripts/Get-MemorySize.psm1 index 2a09f60..c89f931 100644 --- a/Scripts/Get-MemorySize.psm1 +++ b/Scripts/Get-MemorySize.psm1 @@ -2,16 +2,31 @@ function Get-MemorySize { $Memory = Get-CimInstance Win32_OperatingSystem $MemUse = $Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory $MemUserProc = ($MemUse / $Memory.TotalVisibleMemorySize) * 100 + $PageSize = $Memory.TotalVirtualMemorySize - $Memory.TotalVisibleMemorySize + $PageFree = $Memory.FreeVirtualMemory - $Memory.FreePhysicalMemory + $PageUse = $PageSize - $PageFree + $PageUseProc = ($PageUse / $PageSize) * 100 + $PageFile = Get-CimInstance Win32_PageFileUsage + $PagePath = [string]$($PageFile).Description + $MemVirtUse = $Memory.TotalVirtualMemorySize - $Memory.FreeVirtualMemory + $MemVirtUseProc = ($MemVirtUse / $Memory.TotalVirtualMemorySize) * 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") - MemoryUseProc = [string]([int]$MemUserProc)+" %" - WorkingSet = $ws - PageMemory = $pm + MemoryAll = ($memory.TotalVisibleMemorySize/1mb).ToString("0.00 GB") + MemoryUse = ($MemUse/1mb).ToString("0.00 GB") + MemoryUseProc = [string]([int]$MemUserProc)+" %" + PageSize = ($PageSize/1mb).ToString("0.00 GB") + PageUse = ($PageUse/1mb).ToString("0.00 GB") + PageUseProc = [string]([int]$PageUseProc)+" %" + PagePath = $PagePath + MemoryVirtAll = ($memory.TotalVirtualMemorySize/1mb).ToString("0.00 GB") + MemoryVirtUse = ($MemVirtUse/1mb).ToString("0.00 GB") + MemoryVirtUseProc = [string]([int]$MemVirtUseProc)+" %" + ProcWorkingSet = $ws + ProcPageMemory = $pm }) $CollectionMemory } \ No newline at end of file diff --git a/Scripts/Get-MemorySlots.psm1 b/Scripts/Get-MemorySlots.psm1 index 435d195..a1c3603 100644 --- a/Scripts/Get-MemorySlots.psm1 +++ b/Scripts/Get-MemorySlots.psm1 @@ -1,7 +1,11 @@ function Get-MemorySlots { - $Memory = Get-CimInstance Win32_PhysicalMemory | Select-Object Manufacturer,PartNumber, - ConfiguredClockSpeed,@{Label="Memory"; Expression={[string]($_.Capacity/1Mb)}}, - Tag,DeviceLocator,BankLabel + $Memory = Get-CimInstance Win32_PhysicalMemory | + Select-Object Manufacturer, + PartNumber, + ConfiguredClockSpeed, + @{Label="Memory"; Expression={[string]($_.Capacity/1Mb)}}, + Tag,DeviceLocator, + BankLabel $CollectionMemory = New-Object System.Collections.Generic.List[System.Object] $Memory | ForEach-Object { $CollectionMemory.Add([PSCustomObject]@{ diff --git a/Scripts/Get-NetInterfaceStat.psm1 b/Scripts/Get-NetInterfaceStat.psm1 new file mode 100644 index 0000000..2c5c40f --- /dev/null +++ b/Scripts/Get-NetInterfaceStat.psm1 @@ -0,0 +1,40 @@ +function Get-NetInterfaceStat { + param ( + [switch]$Current + ) + if ($Current) { + Get-CimInstance -ClassName Win32_PerfFormattedData_Tcpip_NetworkInterface | + Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1mb).ToString("0.000 MByte/Sec")}}, # Сумма полученных и отправленных байт за секунду + @{name="Received";expression={$($_.BytesReceivedPersec/1mb).ToString("0.000 MByte/Sec")}}, # Количество байт, полученных за секунду + @{name="Sent";expression={$($_.BytesSentPersec/1mb).ToString("0.000 MByte/Sec")}}, # Количество байт, отправленных за секунду + PacketsPersec, # Общее количество пакетов в секунду (включает все виды пакетов) + PacketsReceivedPersec, # Количество пакетов, полученных за секунду + PacketsReceivedUnicastPersec, # Количество уникальных (unicast) пакетов, полученных за секунду, включает в себя широковещательные (broadcast) и групповые (multicast) пакеты + PacketsReceivedNonUnicastPersec, # Количество не уникальных (non-unicast) пакетов, полученных за секунду + PacketsReceivedDiscarded, # Количество отброшенных пакетов при получении + PacketsReceivedErrors, # Количество пакетов с ошибками при получении + PacketsSentPersec, # Количество пакетов, отправленных за секунду + PacketsSentUnicastPersec, # Количество уникальных (unicast) пакетов, отправленных за секунду + PacketsSentNonUnicastPersec # Количество не уникальных (non-unicast) пакетов, отправленных за секунду + } + else { + Get-CimInstance -ClassName Win32_PerfRawData_Tcpip_NetworkInterface | + Select-Object Name, + @{name="Total";expression={$($_.BytesTotalPersec/1gb).ToString("0.00 GByte")}}, + @{name="Received";expression={$($_.BytesReceivedPersec/1gb).ToString("0.00 GByte")}}, + @{name="Sent";expression={$($_.BytesSentPersec/1gb).ToString("0.00 GByte")}}, + PacketsPersec, + PacketsReceivedPersec, + PacketsReceivedUnicastPersec, + PacketsReceivedNonUnicastPersec, + PacketsReceivedDiscarded, + PacketsReceivedErrors, + PacketsSentPersec, + PacketsSentUnicastPersec, + PacketsSentNonUnicastPersec + } +} + +# Get-NetInterfaceStat -Current +# Get-NetInterfaceStat \ No newline at end of file diff --git a/Scripts/Get-NetIpConfig.psm1 b/Scripts/Get-NetIpConfig.psm1 new file mode 100644 index 0000000..5c463d2 --- /dev/null +++ b/Scripts/Get-NetIpConfig.psm1 @@ -0,0 +1,13 @@ +function Get-NetIpConfig { + Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true | + Select-Object Description, + @{Label="IPAddress"; Expression={[string]($_.IPAddress)}}, + @{Label="GatewayDefault"; Expression={[string]($_.DefaultIPGateway)}}, + @{Label="Subnet"; Expression={[string]($_.IPSubnet)}}, + @{Label="DNSServer"; Expression={[string]($_.DNSServerSearchOrder)}}, + MACAddress, + DHCPEnabled, + DHCPServer, + DHCPLeaseObtained, + DHCPLeaseExpires +} \ No newline at end of file diff --git a/Scripts/Get-Netstat.psm1 b/Scripts/Get-Netstat.psm1 index fc4d365..ff78fe8 100644 --- a/Scripts/Get-Netstat.psm1 +++ b/Scripts/Get-Netstat.psm1 @@ -1,30 +1,13 @@ -function Get-Netstat { -<# -.SYNOPSIS -Remote and local view network tcp connections statistics and his used process -Using Get-NetTCPConnection, ps, nslookup and Invoke-Command via WinRM -.DESCRIPTION -Example: -Get-Netstat localhost # default -Get-Netstat server-01 # remote host -.LINK -https://github.com/Lifailon -#> -Param ( -$srv="localhost" -) -if ($srv -like "localhost") { -Get-NetTCPConnection -State Established,Listen | sort -Descending State | select CreationTime,LocalAddress,LocalPort,RemotePort, -@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}},RemoteAddress, -State,@{name="ProcessName";expression={(ps -Id $_.OwningProcess).ProcessName}}, -@{name="ProcessPath";expression={(ps -Id $_.OwningProcess).Path}} | Out-GridView -Title "Local netstat" -} -else { -icm $srv {Get-NetTCPConnection -State Established,Listen | sort -Descending State | select CreationTime,LocalAddress,LocalPort, -RemotePort,RemoteAddress, -State,@{name="ProcessName";expression={(ps -Id $_.OwningProcess).ProcessName}}, -@{name="ProcessPath";expression={(ps -Id $_.OwningProcess).Path}}} | select CreationTime,LocalAddress,LocalPort,RemotePort, -@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}}, -RemoteAddress,State,ProcessName,ProcessPath | Out-GridView -Title "Remote netstat to server: $srv" -} +function Get-NetStat { + Get-NetTCPConnection -State Established,Listen | Sort-Object -Descending State | + Select-Object @{name="ProcessName";expression={(Get-Process -Id $_.OwningProcess).ProcessName}}, + LocalAddress, + LocalPort, + RemotePort, + @{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}}, + RemoteAddress, + State, + CreationTime, + @{Name="RunTime"; Expression={((Get-Date) - $_.CreationTime) -replace "\.\d+$"}}, + @{name="ProcessPath";expression={(Get-Process -Id $_.OwningProcess).Path}} } \ No newline at end of file diff --git a/Scripts/Get-NetstatRemote.psm1 b/Scripts/Get-NetstatRemote.psm1 new file mode 100644 index 0000000..b7bde65 --- /dev/null +++ b/Scripts/Get-NetstatRemote.psm1 @@ -0,0 +1,30 @@ +function Get-Netstat { +<# +.SYNOPSIS +Remote and local view network tcp connections statistics and his used process +Using Get-NetTCPConnection, ps, nslookup and Invoke-Command via WinRM +.DESCRIPTION +Example: +Get-Netstat localhost # default +Get-Netstat server-01 # remote host +.LINK +https://github.com/Lifailon +#> +Param ( +$srv="localhost" +) +if ($srv -like "localhost") { +Get-NetTCPConnection -State Established,Listen | sort -Descending State | select CreationTime,LocalAddress,LocalPort,RemotePort, +@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}},RemoteAddress, +State,@{name="ProcessName";expression={(ps -Id $_.OwningProcess).ProcessName}}, +@{name="ProcessPath";expression={(ps -Id $_.OwningProcess).Path}} | Out-GridView -Title "Local netstat" +} +else { +icm $srv {Get-NetTCPConnection -State Established,Listen | sort -Descending State | select CreationTime,LocalAddress,LocalPort, +RemotePort,RemoteAddress, +State,@{name="ProcessName";expression={(ps -Id $_.OwningProcess).ProcessName}}, +@{name="ProcessPath";expression={(ps -Id $_.OwningProcess).Path}}} | select CreationTime,LocalAddress,LocalPort,RemotePort, +@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}}, +RemoteAddress,State,ProcessName,ProcessPath | Out-GridView -Title "Remote netstat to server: $srv" +} +} \ No newline at end of file diff --git a/Scripts/Get-PD.psm1 b/Scripts/Get-PD.psm1 deleted file mode 100644 index 7365fad..0000000 --- a/Scripts/Get-PD.psm1 +++ /dev/null @@ -1,14 +0,0 @@ -function Get-PD { - $PhysicalDisk = Get-CimInstance Win32_DiskDrive | Select-Object Model, - @{Label="Size"; Expression={[int]($_.Size/1Gb)}},Partitions,InterfaceType - $CollectionPD = New-Object System.Collections.Generic.List[System.Object] - $PhysicalDisk | ForEach-Object { - $CollectionPD.Add([PSCustomObject]@{ - Model = $_.Model - Size = [string]$_.Size+" Gb" - PartitionCount = $_.Partitions - Interface = $_.InterfaceType - }) - } - $CollectionPD -} \ No newline at end of file diff --git a/Scripts/Get-Smart.psm1 b/Scripts/Get-Smart.psm1 new file mode 100644 index 0000000..ac42c67 --- /dev/null +++ b/Scripts/Get-Smart.psm1 @@ -0,0 +1,22 @@ +function Get-Smart { + $PhysicalDisk = Get-CimInstance -Namespace root/Microsoft/Windows/Storage -ClassName MSFT_PhysicalDisk + $DiskSensor = $PhysicalDisk | Get-StorageReliabilityCounter + $DiskSensor | Select-Object @{Label="DiskName"; Expression={$PhysicalDisk | Where-Object DeviceId -eq $_.DeviceId | Select-Object -ExpandProperty FriendlyName}}, + Temperature, + @{Label="HealthStatus"; Expression={$PhysicalDisk | Where-Object DeviceId -eq $_.DeviceId | Select-Object -ExpandProperty HealthStatus}}, + @{Label="OperationalStatus"; Expression={$PhysicalDisk | Where-Object DeviceId -eq $_.DeviceId | Select-Object -ExpandProperty OperationalStatus}}, + @{Label="MediaType"; Expression={$PhysicalDisk | Where-Object DeviceId -eq $_.DeviceId | Select-Object -ExpandProperty MediaType}}, + @{Label="BusType"; Expression={$PhysicalDisk | Where-Object DeviceId -eq $_.DeviceId | Select-Object -ExpandProperty BusType}}, + PowerOnHours, # Количество часов, в течение которых жесткий диск был во включенном состоянии + StartStopCycleCount, # Количество циклов включения и выключения жесткого диска (каждый цикл выключения и последующего включения считается за один раз) + FlushLatencyMax, # Максимальное время задержки (латентность) для операций очистки кэша на диске (сброса кеша на диск). + LoadUnloadCycleCount, # Количество циклов загрузки/выгрузки механизма парковки головок на жёстких дисках с перемещающимися головками (не относится к SSD) + ReadErrorsTotal, # Общее количество ошибок чтения данных с диска + ReadErrorsCorrected, # Количество ошибок чтения, которые были исправлены системой коррекции ошибок + ReadErrorsUncorrected, # Количество ошибок чтения, которые не удалось исправить + ReadLatencyMax, # Максимальная задержка (латентность) при чтении данных с диска + WriteErrorsTotal, + WriteErrorsCorrected, + WriteErrorsUncorrected, + WriteLatencyMax +} \ No newline at end of file diff --git a/Scripts/Get-Software.psm1 b/Scripts/Get-Software.psm1 new file mode 100644 index 0000000..20a6ceb --- /dev/null +++ b/Scripts/Get-Software.psm1 @@ -0,0 +1,8 @@ +function Get-Software { + Get-CimInstance Win32_Product | Select-Object Name, + Version, + Vendor, + InstallDate, + InstallLocation, + InstallSource +} \ No newline at end of file diff --git a/Scripts/Get-Temperature.psm1 b/Scripts/Get-Temperature.psm1 new file mode 100644 index 0000000..8d2efc4 --- /dev/null +++ b/Scripts/Get-Temperature.psm1 @@ -0,0 +1,11 @@ +# Get-CimInstance CIM_TemperatureSensor +# Get-CimInstance Win32_TemperatureProbe +# Get-CimInstance Win32_PerfFormattedData_Counters_ThermalZoneInformation +# Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace root/WMI +# Get-CimInstance CIM_Fan +# Get-CimInstance CIM_CoolingDevice + +function Get-Temperature { + $ThermalZoneTemperature = Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace root/WMI + $ThermalZoneTemperature.CurrentTemperature / 10 - 273.15 +} \ No newline at end of file diff --git a/Scripts/Get-VideoCard.psm1 b/Scripts/Get-VideoCard.psm1 index b92a772..3e66177 100644 --- a/Scripts/Get-VideoCard.psm1 +++ b/Scripts/Get-VideoCard.psm1 @@ -8,7 +8,7 @@ function Get-VideoCard { $CollectionVC.Add([PSCustomObject]@{ Model = $_.VideoCard Display = $_.Display - VideoRAM = [string]$_.vRAM+" Gb" + VideoRAM = [string]$([int]$($_.vRAM))+" Gb" }) } $CollectionVC diff --git a/Scripts/Get-WinUpdate.psm1 b/Scripts/Get-WinUpdate.psm1 new file mode 100644 index 0000000..7cc9da3 --- /dev/null +++ b/Scripts/Get-WinUpdate.psm1 @@ -0,0 +1,9 @@ +function Get-WinUpdate { + Get-CimInstance Win32_QuickFixEngineering | Select-Object HotFixID, + Description, + InstalledBy, + InstalledOn + # wusa /uninstall /kb:123456 + # dism /Online /Get-Packages /format:table + # dism /Online /Remove-Package /PackageName:Package_for_DotNetRollup_481~31bf3856ad364e35~amd64~~10.0.9206.1 /quiet /norestart +} \ No newline at end of file