-
Notifications
You must be signed in to change notification settings - Fork 61
/
flancy-sys-info-ws.ps1
121 lines (112 loc) · 4.72 KB
/
flancy-sys-info-ws.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# This script starts a simple web service server that allows you to remotely manage your computer. It is mostly a proof of concept script, showing the potential of tools like flancy
# Flancy GitHub: https://github.com/toenuff/flancy
Import-Module "C:\path\to\flancy\module"
$head = @"
<title>flancy Web Services</title>
<style>
body {
background-color: #FFFFFF;
font-family: sans-serif;
}
h1 {
color: #1E87F0;
}
h2 {
color: #1E87F0;
}
table {
background-color: #1E87F0;
}
td {
background-color: #FFFFFF;
color: #666666;
padding: 3px;
}
th {
background-color: #1E87F0;
color: #FFFFFF;
text-align: left;
padding: 3px;
}
</style>
"@
# Set the port you want to run flancy on
$url = "http://localhost:8000"
New-Flancy -url $url -WebSchema @(
# Show the hostname at the root url
Get '/' { hostname }
# Start a process
Get '/startprocess/{exec}' {
$results = Start-Process -FilePath $parameters.exec
$results | ConvertTo-Json
}
# Start a service
Get '/startservice/{exec}' {
$results = Start-Service $parameters.exec
$results | ConvertTo-Json
}
# Install a package
Get '/install/{package}' {
$results = Install-Package -Name $parameters.package
$results | ConvertTo-Json
}
# Show system information
Get '/sysinfo' {
$name = Get-WmiObject Win32_ComputerSystem | Select -ExpandProperty Name
$boot = Get-WmiObject Win32_OperatingSystem | Select-Object @{Label="LastBootTime"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} | Select -ExpandProperty LastBootTime
$os = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty Caption
$arch = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty OSArchitecture
$processor = Get-WmiObject Win32_Processor | Select -ExpandProperty Name
$model = Get-WmiObject win32_ComputerSystemProduct | Select -ExpandProperty Name
$manufacturer = Get-WmiObject win32_ComputerSystemProduct | Select -ExpandProperty Vendor
$computerProps = @{
'Name'= $name;
'Operating System'= $os;
'Architecture'= $arch;
'Processor'= $processor;
'Model Name'=$model;
'Manufacturer'=$manufacturer;
'Last Boot'= $boot
}
$computerProps | ConvertTo-Html -Head $head
}
# Show performance information
Get '/perfmoninfo' {
$ram = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty TotalVisibleMemorySize)/1MB, 2)
$free = [math]::Round((Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty FreePhysicalMemory)/1MB, 2)
$numProcesses = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty NumberOfProcesses
$numUsers = Get-WmiObject Win32_OperatingSystem | Select -ExpandProperty NumberOfUsers
$perfmonProps = @{
'Free Memory (GB)'= $free;
'Total Memory (GB)'= $ram;
'Process Count'=$numProcesses;
'User Count'=$numUsers
}
$perfmonProps | ConvertTo-Html -Head $head
}
# Show network information
Get '/network' {
$ips = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } | Select-Object DNSHostName,Description,@{Label="IP Address"; Expression={($_.IPAddress[0])}},@{Label="Default Gateway"; Expression={($_.DefaultIPGateway[0])}},MACAddress
$ips | ConvertTo-Html -Head $head
}
# Show drive information
Get '/drives' {
$disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object @{Label="Drive Letter"; Expression={$_.DeviceID}},@{Label="Name"; Expression={$_.VolumeName}},@{Label="Free (GB)"; Expression={“{0:N2}” -f ($_.FreeSpace / 1GB)}},@{Label="Total (GB)"; Expression={“{0:N2}” -f ($_.Size / 1GB)}}
$disks | ConvertTo-Html -Head $head
}
# Show running processes
Get '/processes' {
$processes = Get-WmiObject Win32_Process | Where-Object {$_.WorkingSetSize -gt 52428800} | Sort-Object WorkingSetSize -Descending | Select-Object Name,ProcessId,@{Label="Memory Usage (MB)"; Expression={“{0:N2}” -f ($_.WorkingSetSize / 1MB)}} $ips | ConvertTo-Html -Head $head
$processes | ConvertTo-Html -Head $head
}
# Show running services
Get '/services' {
$services= Get-WmiObject Win32_Service | Where-Object {$_.State -eq "Running"} | Sort-Object DisplayName | Select-Object DisplayName,ProcessId,StartMode
$services | ConvertTo-Html -Head $head
}
# Show start up programs
Get '/startup' {
$startup = Get-WmiObject Win32_startupCommand | Sort-Object Caption | Select-Object Caption,User,Command
$startup | ConvertTo-Html -Head $head
}
)