-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathPoSh-R2.ps1
1245 lines (1067 loc) · 52.2 KB
/
PoSh-R2.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.SYNOPSIS
PoSH-R2 is a set of Windows Management Instrumentation interface (WMI) scripts that investigators and forensic analysts can use to retrieve information from a
compromised (or potentially compromised) Windows system. The scripts use WMI to pull this information from the operating system. Therefore, this script
will need to be executed with a user that has the necessary privileges.
PoSH-R2 will retrieve the following data from an individual machine or a group of systems:
- Autorun entries
- Disk info
- Environment variables
- Event logs (50 latest)
- Installed Software (Warning: https://gregramsey.net/2012/02/20/win32_product-is-evil/)
- Logon sessions
- List of drivers
- List of mapped network drives
- List of running processes
- Logged in user
- Local groups
- Local user accounts
- Network configuration
- Network connections
- Patches
- Scheduled tasks with AT command
- Shares
- Services
- System Information
.EXAMPLE
.\posh_r2.ps1
.NOTES
File Name : PoSH-R2.ps1
Version : v.0.2
Author : @WiredPulse
Prerequisite : PowerShell
Created : 10 Oct 16
#>
Clear-Host
Import-Module "$PSScriptRoot\PSSQLite\PSSQLite.psd1"
Function ListComputers{
$DN = ""
$Response = ""
$DNSName = ""
$DNSArray = ""
$objSearcher = ""
$colProplist = ""
$objComputer = ""
$objResults = ""
$colResults = ""
$Computer = ""
$comp = ""
New-Item -type file -force "$Script:Folder_Path\Computer_List_$Script:curDate.txt" | Out-Null
$Script:Compute = "$Script:Folder_Path\Computer_List_$Script:curDate.txt"
$strCategory = "(ObjectCategory=Computer)"
Write-Host "Would you like to automatically pull from your domain or provide your own domain?"
Write-Host "Auto pull uses the current domain you are on, if you need to select a different domain use manual."
$response = Read-Host = "[1] Auto Pull, [2] Manual Selection"
If($Response -eq "1") {
$DNSName = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
If($DNSName -ne $Null) {
$DNSArray = $DNSName.Split(".")
for ($x = 0; $x -lt $DNSArray.Length ; $x++) {
if ($x -eq ($DNSArray.Length - 1)){$Separator = ""}else{$Separator =","}
[string]$DN += "DC=" + $DNSArray[$x] + $Separator } }
$Script:Domain = $DN
echo "Pulled computers from: "$Script:Domain
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher("LDAP://$Script:Domain")
$objSearcher.Filter = $strCategory
$objSearcher.PageSize = 100000
$objSearcher.SearchScope = "SubTree"
$colProplist = "name"
foreach ($i in $colPropList) {
$objSearcher.propertiesToLoad.Add($i) }
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults) {
$objComputer = $objResult.Properties
$comp = $objComputer.name
echo $comp | Out-File $Script:Compute -Append }
$Script:Computers = (Get-Content $Script:Compute) | Sort-Object
}
elseif($Response -eq "2")
{
Write-Host "Would you like to automatically pull from your domain or provide your own domain?"
Write-Host "Auto pull uses the current domain you are on, if you need to select a different domain use manual."
$Script:Domain = Read-Host "Enter your Domain here: OU=West,DC=Company,DC=com"
If ($Script:Domain -eq $Null) {Write-Host "You did not provide a valid response."; . ListComputers}
echo "Pulled computers from: "$Script:Domain
$objOU = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$Script:Domain")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objOU
$objSearcher.Filter = $strCategory
$objSearcher.PageSize = 100000
$objSearcher.SearchScope = "SubTree"
$colProplist = "name"
foreach ($i in $colPropList) { $objSearcher.propertiesToLoad.Add($i) }
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults) {
$objComputer = $objResult.Properties
$comp = $objComputer.name
echo $comp | Out-File $Script:Compute -Append }
$Script:Computers = (Get-Content $Script:Compute) | Sort-Object
}
else {
Write-Host "You did not supply a correct response, Please select a response." -foregroundColor Red
. ListComputers }
}
Function ListTextFile{
$file_Dialog = ""
$file_Name = ""
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$file_Dialog = New-Object system.windows.forms.openfiledialog
$file_Dialog.InitialDirectory = "$env:USERPROFILE\Desktop"
$file_Dialog.MultiSelect = $false
$file_Dialog.showdialog()
$file_Name = $file_Dialog.filename
$Comps = Get-Content $file_Name
If ($Comps -eq $Null) {
Write-Host "Your file was empty. You must select a file with at least one computer in it." -Fore Red
. ListTextFile }
Else
{
$Script:Computers = @()
ForEach ($Comp in $Comps)
{
If ($Comp -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}")
{
$Temp = $Comp.Split("/")
$IP = $Temp[0]
$Mask = $Temp[1]
. Get-Subnet-Range $IP $Mask
$Script:Computers += $Script:IPList
}
Else
{
$Script:Computers += $Comp
}
}
}
}
Function Get-Subnet-Range {
Param(
[string]
$IP,
[string]
$netmask
)
Begin {
$IPs = New-Object System.Collections.ArrayList
Function Get-NetworkAddress {
Param (
[string]
$IP,
[string]
$Mask,
[switch]
$Binary
)
Begin {
$NetAdd = $null
}
Process {
$BinaryIP = ConvertTo-BinaryIP $IP
$BinaryMask = ConvertTo-BinaryIP $Mask
0..34 | %{
$IPBit = $BinaryIP.Substring($_,1)
$MaskBit = $BinaryMask.Substring($_,1)
IF ($IPBit -eq '1' -and $MaskBit -eq '1') {
$NetAdd = $NetAdd + "1"
} elseif ($IPBit -eq ".") {
$NetAdd = $NetAdd +'.'
} else {
$NetAdd = $NetAdd + "0"
}
}
if ($Binary) {
return $NetAdd
} else {
return ConvertFrom-BinaryIP $NetAdd
}
}
}
Function ConvertTo-BinaryIP {
Param (
[string]
$IP
)
Process {
$out = @()
Foreach ($octet in $IP.split('.')) {
$strout = $null
0..7|% {
IF (($octet - [math]::pow(2,(7-$_)))-ge 0) {
$octet = $octet - [math]::pow(2,(7-$_))
[string]$strout = $strout + "1"
} else {
[string]$strout = $strout + "0"
}
}
$out += $strout
}
return [string]::join('.',$out)
}
}
Function ConvertFrom-BinaryIP {
Param (
[string]
$IP
)
Process {
$out = @()
Foreach ($octet in $IP.split('.')) {
$strout = 0
0..7|% {
$bit = $octet.Substring(($_),1)
IF ($bit -eq 1) {
$strout = $strout + [math]::pow(2,(7-$_))
}
}
$out += $strout
}
return [string]::join('.',$out)
}
}
Function ConvertTo-MaskLength {
Param (
[string]
$mask
)
Process {
$out = 0
Foreach ($octet in $Mask.split('.')) {
$strout = 0
0..7|% {
IF (($octet - [math]::pow(2,(7-$_)))-ge 0) {
$octet = $octet - [math]::pow(2,(7-$_))
$out++
}
}
}
return $out
}
}
Function ConvertFrom-MaskLength {
Param (
[int]
$mask
)
Process {
$out = @()
[int]$wholeOctet = ($mask - ($mask % 8))/8
if ($wholeOctet -gt 0) {
1..$($wholeOctet) |%{
$out += "255"
}
}
$subnet = ($mask - ($wholeOctet * 8))
if ($subnet -gt 0) {
$octet = 0
0..($subnet - 1) | %{
$octet = $octet + [math]::pow(2,(7-$_))
}
$out += $octet
}
for ($i=$out.count;$i -lt 4; $I++) {
$out += 0
}
return [string]::join('.',$out)
}
}
Function Get-IPRange {
Param (
[string]
$IP,
[string]
$netmask
)
Process {
iF ($netMask.length -le 3) {
$masklength = $netmask.replace('/','')
$Subnet = ConvertFrom-MaskLength $masklength
} else {
$Subnet = $netmask
$masklength = ConvertTo-MaskLength -Mask $netmask
}
$network = Get-NetworkAddress -IP $IP -Mask $Subnet
[int]$FirstOctet,[int]$SecondOctet,[int]$ThirdOctet,[int]$FourthOctet = $network.split('.')
$TotalIPs = ([math]::pow(2,(32-$masklength)) -2)
$blocks = ($TotalIPs - ($TotalIPs % 256))/256
if ($Blocks -gt 0) {
1..$blocks | %{
0..255 |%{
if ($FourthOctet -eq 255) {
If ($ThirdOctet -eq 255) {
If ($SecondOctet -eq 255) {
$FirstOctet++
$secondOctet = 0
} else {
$SecondOctet++
$ThirdOctet = 0
}
} else {
$FourthOctet = 0
$ThirdOctet++
}
} else {
$FourthOctet++
}
Write-Output ("{0}.{1}.{2}.{3}" -f `
$FirstOctet,$SecondOctet,$ThirdOctet,$FourthOctet)
}
}
}
$sBlock = $TotalIPs - ($blocks * 256)
if ($sBlock -gt 0) {
1..$SBlock | %{
if ($FourthOctet -eq 255) {
If ($ThirdOctet -eq 255) {
If ($SecondOctet -eq 255) {
$FirstOctet++
$secondOctet = 0
} else {
$SecondOctet++
$ThirdOctet = 0
}
} else {
$FourthOctet = 0
$ThirdOctet++
}
} else {
$FourthOctet++
}
Write-Output ("{0}.{1}.{2}.{3}" -f `
$FirstOctet,$SecondOctet,$ThirdOctet,$FourthOctet)
}
}
}
}
}
Process {
Get-IPRange $IP $netmask | %{
[void]$IPs.Add($_)
}
$Script:IPList = $IPs
}
}
Function SingleEntry {
$Comp = Read-Host "Enter Computer Name or IP (1.1.1.1) or IP Subnet (1.1.1.1/24)"
If ($Comp -eq $Null) { . SingleEntry }
ElseIf ($Comp -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}")
{
$Temp = $Comp.Split("/")
$IP = $Temp[0]
$Mask = $Temp[1]
. Get-Subnet-Range $IP $Mask
$Script:Computers = $Script:IPList
}
Else
{ $Script:Computers = $Comp}
}
$script:poshDB = "$PSScriptRoot" + "\PoSh-R2_data\db\PoSh-R2.SQLite"
<#
$script:autorunDB = "$PSScriptRoot" + "\PoSh-R2_data\db\autorun.SQLite"
$script:logonDB = "$PSScriptRoot" + "\PoSh-R2_data\db\logon.SQLite"
$script:secEvtDB = "$PSScriptRoot" + "\PoSh-R2_data\db\secevt.SQLite"
$script:sysEvtDB = "$PSScriptRoot" + "\PoSh-R2_data\db\sysevt.SQLite"
$script:appEvtDB = "$PSScriptRoot" + "\PoSh-R2_data\db\appevt.SQLite"
$script:driverDB = "$PSScriptRoot" + "\PoSh-R2_data\db\driver.SQLite"
$script:mappedDB = "$PSScriptRoot" + "\PoSh-R2_data\db\mappeddrive.SQLite"
$script:processDB = "$PSScriptRoot" + "\PoSh-R2_data\db\process.SQLite"
$script:schedtasksDB = "$PSScriptRoot" + "\PoSh-R2_data\db\schedtasks.SQLite"
$script:servicesDB = "$PSScriptRoot" + "\PoSh-R2_data\db\services.SQLite"
$script:envDB = "$PSScriptRoot" + "\PoSh-R2_data\db\env.SQLite"
$script:userInfoDB = "$PSScriptRoot" + "\PoSh-R2_data\db\userinfo.SQLite"
$script:groupDB = "$PSScriptRoot" + "\PoSh-R2_data\db\groups.SQLite"
$script:loggedinDB = "$PSScriptRoot" + "\PoSh-R2_data\db\loggedin.SQLite"
$script:networkDB = "$PSScriptRoot" + "\PoSh-R2_data\db\network.SQLite"
$script:sharesDB = "$PSScriptRoot" + "\PoSh-R2_data\db\shares.SQLite"
$script:diskDB = "$PSScriptRoot" + "\PoSh-R2_data\db\disk.SQLite"
$script:sysinfoDB = "$PSScriptRoot" + "\PoSh-R2_data\db\sysinfo.SQLite"
$script:patchDB = "$PSScriptRoot" + "\PoSh-R2_data\db\patch.SQLite"
$script:softwareDB = "$PSScriptRoot" + "\PoSh-R2_data\db\software.SQLite"
$script:netstatDB = "$PSScriptRoot" + "\PoSh-R2_data\db\netstat.SQLite"
#>
Write-Host " ______ _______ __ ______ ___ " -ForegroundColor Green
Write-Host " | _ \ / | | | | _ \ |__ \ " -ForegroundColor Green
Write-Host " | |_) | ______ | (---- | |_____ ______ | |_) | ) | " -ForegroundColor Green
Write-Host " | ___/ / __ \ \ \ | __ | |______| | / / / " -ForegroundColor Green
Write-Host " | | | |__| | |----) | | | | | | |\ \-----/ /_ " -ForegroundColor Green
Write-Host " | _| \______/ |_______/ |__| |__| | _| \_____|_____| " -ForegroundColor Green
Write-Host ""
Write-Host "What systems do you get to interrogate?" -ForegroundColor yellow
$strResponse = Read-Host "`n[1] All Domain Computers (Must provide Domain) `n[2] Import Computer Names/ IPs from a File `n[3] Input Computer Names/ IPs Manually `n[4] Local System `n"
If($strResponse -eq "1"){. ListComputers | Sort-Object}
elseif($strResponse -eq "2"){. ListTextFile}
elseif($strResponse -eq "3"){. SingleEntry}
elseif($strResponse -eq "4"){$localhost = $computers = "localhost"}
else{Write-Host "You did not supply a correct response, `
Please run script again."; pause -foregroundColor Red}
Write-Host "Got computer list... Next task..." -ForegroundColor yellow
write-output " "
if (-not(test-path "$PSScriptRoot\PoSh-R2_Data")){
new-item -ItemType Directory -path "$PSScriptRoot" -name "PoSh-R2_Data" | out-null
}
if(-not(test-path "$PSScriptRoot\PoSh-R2_Data\db")){
new-item -ItemType directory -path "$PSScriptRoot\PoSh-R2_Data" -Name "db" | out-null
}
$dirDate = get-date -Format yyyy-MM-dd-HHmm
new-item -ItemType Directory -path "$PSScriptRoot\PoSh-R2_Data" -Name "$dirDate" | out-null
if(-not(test-path "$poshDB")){
$Query = 'CREATE TABLE autorun (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
location TEXT,
command TEXT,
user TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE disk (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
deviceid TEXT,
description TEXT,
providername TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE drivers (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
installdate TEXT,
displayname TEXT,
pathname TEXT,
state TEXT,
startmode TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE env (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
username TEXT,
name TEXT,
variablevalue TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE appevt (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
logfile TEXT,
eventcode TEXT,
timegenerated TEXT,
message TEXT,
type TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE secevt (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
logfile TEXT,
eventcode TEXT,
timegenerated TEXT,
message TEXT,
type TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE sysevt (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
logfile TEXT,
eventcode TEXT,
timegenerated TEXT,
message TEXT,
type TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE groups (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
caption TEXT,
domain TEXT,
name TEXT,
sid TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE netlogon (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
lastlogon TEXT,
lastlogoff TEXT,
numberoflogons TEXT,
passwordage TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE loggedinuser (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
username TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE mappeddrives (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
providername TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE process (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
path TEXT,
commandline TEXT,
description TEXT,
processid TEXT,
parentprocessid TEXT,
handle TEXT,
handlecount TEXT,
threadcount TEXT,
creationdate TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE schedtask (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
owner TEXT,
jobid TEXT,
command TEXT,
runrepeatedly TEXT,
interactwithdesktop TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE services (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
processid TEXT,
name TEXT,
description TEXT,
pathname TEXT,
started TEXT,
startmode TEXT,
startname TEXT,
state TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE useraccount (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
accounttype TEXT,
fullname TEXT,
domain TEXT,
disabled TEXT,
localaccount TEXT,
lockedout TEXT,
passwordchangeable TEXT,
passwordexpires TEXT,
sid TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE networks (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
ipaddress TEXT,
ipsubnet TEXT,
defaultipgateway TEXT,
dhcpserver TEXT,
dnshostname TEXT,
dnsserversearchorder TEXT,
macaddress TEXT,
description TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE shares (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
path TEXT,
description TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE computersystem (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
domain TEXT,
model TEXT,
manufacturer TEXT,
enabledaylightsavingstime TEXT,
partofdomain TEXT,
roles TEXT,
systemtype TEXT,
numberofprocessors TEXT,
totalphysicalmemory TEXT,
username TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE patch (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
hotfixid TEXT,
description TEXT,
installedby TEXT,
installedon TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE software (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
name TEXT,
packetcache TEXT,
vendor TEXT,
version TEXT,
identifyingnumber TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
$Query = 'CREATE TABLE connections (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
date DATETIME,
computername TEXT,
protocol TEXT,
version TEXT,
localaddress TEXT,
localport TEXT,
remoteaddress TEXT,
remoteport TEXT,
state TEXT,
processid TEXT,
processname TEXT,
processpath TEXT)'
Invoke-SqliteQuery -Query $Query -DataSource $poshDB | Out-Null
}
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving Autoruns information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_startupcommand -ComputerName $computers | select PSComputername, Name, Location, Command, User | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Autoruns.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving logon information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_networkloginprofile -ComputerName $computers | select PSComputername,Name, LastLogon,LastLogoff,NumberOfLogons,PasswordAge | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\NetLogon.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving event log information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_ntlogevent -ComputerName $computers -filter "logfile='security'" | select PSComputername, LogFile, EventCode, TimeGenerated, Message, Type | select -first 50 | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-Security.csv -NoTypeInformation
Get-WMIObject -Namespace root\cimv2 -Class win32_ntlogevent -ComputerName $computers -filter "logfile='system'" | select PSComputername, LogFile, EventCode, TimeGenerated, Message, Type | select -first 50 | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-System.csv -NoTypeInformation
Get-WMIObject -Namespace root\cimv2 -Class win32_ntlogevent -ComputerName $computers -filter "logfile='application'" | select PSComputername, LogFile, EventCode, TimeGenerated, Message, Type | select -first 50 | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-Application.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving driver information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_systemdriver -ComputerName $computers | select PSComputername, Name, InstallDate, DisplayName, PathName, State, StartMode | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Drivers.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving mapped drives information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_mappedlogicaldisk -ComputerName $computers | select PSComputername, Name, ProviderName | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Mapped_Drives.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving running processes information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_process -ComputerName $computers | select PSComputername, Name, path, Commandline, Description, ProcessID, ParentProcessID, Handle, HandleCount, ThreadCount, CreationDate | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Processes.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving scheduled tasks created by at.exe or Win32_ScheduledJob..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_scheduledjob -ComputerName $computers | select PSComputername, Name, Owner, JodID, Command, RunRepeatedly, InteractWithDesktop | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Scheduled_Tasks.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving service information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_service -ComputerName $computers | select PSComputername, ProcessID, Name, Description, PathName, Started, StartMode, StartName, State | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Services.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving environment variables information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_environment -ComputerName $computers | select PSComputername, UserName, Name, VariableValue | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Environment_Variables.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving user information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_useraccount -ComputerName $computers | select PSComputername, accounttype, name, fullname, domain, disabled, localaccount, lockout, passwordchangeable, passwordexpires, sid | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Users.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving group information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_group -ComputerName $computers |select PSComputername, Caption, Domain, Name, Sid | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Groups.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving loggedon user information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_computersystem -ComputerName $computers | select PSComputername, Username | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Logged_on_User.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving network configurations..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_networkadapterconfiguration -ComputerName $computers | select PSComputername, IPAddress, IPSubnet, DefaultIPGateway, DHCPServer, DNSHostname, DNSserversearchorder, MACAddress, description| Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Network_Configs.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving shares information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_share -ComputerName $computers |select PSComputername, Name, Path, Description | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Shares.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving disk information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_logicaldisk -ComputerName $computers | select PSComputername, DeviceID, Description, ProviderName | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Disk.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving system information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_computersystem -ComputerName $computers | select PSComputername, Domain, Model, Manufacturer, EnableDaylightSavingsTime, PartOfDomain, Roles, SystemType, NumberOfProcessors, TotalPhysicalMemory, Username | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\System_Info.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving installed patch information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_quickfixengineering -ComputerName $computers | select PSComputername, HotFixID, Description, InstalledBy, InstalledOn | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Patches.csv -NoTypeInformation
# Warning: https://gregramsey.net/2012/02/20/win32_product-is-evil/
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving installed software information..." -ForegroundColor yellow
Get-WMIObject -Namespace root\cimv2 -Class win32_product -ComputerName $computers | select PSComputername, Name, PackageCache, Vendor, Version, IdentifyingNumber | Export-CSV $PSScriptRoot\PoSh-R2_data\$dirDate\Software.csv -NoTypeInformation
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Retrieving network connections..." -ForegroundColor yellow
if($localhost -eq $null){
foreach($computer in $computers){
Invoke-WmiMethod -Class Win32_Process -Name Create -Computername $computer -ArgumentList "cmd /c netstat -ano > c:\$computer.txt" >$null 2>&1
copy-item \\$computer\c$\$computer.txt $PSScriptRoot\PoSh-R2_data\$dirDate
$connections = get-content $PSScriptRoot\PoSh-R2_data\$dirDate\$computer.txt
$NetStatRecords = @()
Start-Sleep 2
$Connections[4..$Connections.count] | foreach-object {
Write-Verbose "Parsing line: $_ "
$Fragments = ($_ -replace '\s+', ' ').Split(' ')
if ($Fragments[2].Contains('[')) {
$Version = 'IPv6'
$LocalAddress = $Fragments[2].Split(']')[0].Split('[')[1]
$LocalPort = $Fragments[2].Split(']')[1].Split(':')[1]
} else {
$Version = 'IPv4'
$LocalAddress = $Fragments[2].Split(':')[0]
$LocalPort = $Fragments[2].Split(':')[1]
}
if ($Fragments[3].Contains('[')) {
$RemoteAddress = $Fragments[3].Split(']')[0].Split('[')[1]
$RemotePort = $Fragments[3].Split(']')[1].Split(':')[1]
} else {
$RemoteAddress = $Fragments[3].Split(':')[0]
$RemotePort = $Fragments[3].Split(':')[1]
}
$ProcessID = $(if ($RemoteAddress -eq '*') {$Fragments[4]} else {$Fragments[5]})
$Props = [ordered]@{
ComputerName = $computer
Protocol = $Fragments[1]
Version = $Version
LocalAddress = $LocalAddress
LocalPort = $LocalPort
RemoteAddress = $RemoteAddress
RemotePort = $RemotePort
State = $(if ($RemoteAddress -eq '*') {''} else {$Fragments[4]})
ProcessID = $ProcessID
}
$Record = New-Object -TypeName PSObject -Property $Props
$NetStatRecords += $Record
}
$NetStatRecords | export-csv $PSScriptRoot\PoSh-R2_data\$dirDate\connections.csv -NoTypeInformation -Append
Remove-Variable NetStatRecords
Remove-item $PSScriptRoot\PoSh-R2_data\$dirDate\$computer.txt
}
Remove-item \\$computer\c$\$computer.txt
Remove-Variable localhost -ErrorAction SilentlyContinue
}
else{
$connections = netstat -ano
$NetStatRecords = @()
$Connections[4..$Connections.count] | foreach-object {
Write-Verbose "Parsing line: $_ "
$Fragments = ($_ -replace '\s+', ' ').Split(' ')
if ($Fragments[2].Contains('[')) {
$Version = 'IPv6'
$LocalAddress = $Fragments[2].Split(']')[0].Split('[')[1]
$LocalPort = $Fragments[2].Split(']')[1].Split(':')[1]
} else {
$Version = 'IPv4'
$LocalAddress = $Fragments[2].Split(':')[0]
$LocalPort = $Fragments[2].Split(':')[1]
}
if ($Fragments[3].Contains('[')) {
$RemoteAddress = $Fragments[3].Split(']')[0].Split('[')[1]
$RemotePort = $Fragments[3].Split(']')[1].Split(':')[1]
} else {
$RemoteAddress = $Fragments[3].Split(':')[0]
$RemotePort = $Fragments[3].Split(':')[1]
}
$ProcessID = $(if ($RemoteAddress -eq '*') {$Fragments[4]} else {$Fragments[5]})
$Props = [ordered]@{
ComputerName = $computer
Protocol = $Fragments[1]
Version = $Version
LocalAddress = $LocalAddress
LocalPort = $LocalPort
RemoteAddress = $RemoteAddress
RemotePort = $RemotePort
State = $(if ($RemoteAddress -eq '*') {''} else {$Fragments[4]})
ProcessID = $ProcessID
ProcessName = $((Get-Process -Id $ProcessID).Name)
ProcessPath = $((Get-Process -Id $ProcessID).Path)
}
$Record = New-Object -TypeName PSObject -Property $Props
$NetStatRecords += $Record
}
$NetStatRecords | export-csv $PSScriptRoot\PoSh-R2_data\$dirDate\connections.csv -NoTypeInformation -Append
Remove-Variable NetStatRecords
}
Write-Output " "
Write-Host "Done!"-ForegroundColor Cyan
Write-Output " "
Write-Host "[-] " -ForegroundColor Green -NoNewline; Write-Host "Importing data into database..." -ForegroundColor Yellow
Write-Output " "
$autorun = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Autoruns.csv
$disk = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Disk.csv
$drivers = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Drivers.csv
$envVar = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Environment_Variables.csv
$evtApp = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-Application.csv
$evtSec = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-Security.csv
$evtSys = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-System.csv
$groups = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Groups.csv
$loggedon = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Logged_on_User.csv
$mapped = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Mapped_Drives.csv
$netlogon = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\NetLogon.csv
$net = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Network_Configs.csv
$patch = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Patches.csv
$process = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Processes.csv
$sched = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Scheduled_Tasks.csv
$serv = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Services.csv
$shares = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Shares.csv
$software = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Software.csv
$sysInfo = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\System_Info.csv
$users = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\Users.csv
$connects = import-csv $PSScriptRoot\PoSh-R2_data\$dirDate\connections.csv
$autorunQuery = 'INSERT INTO autorun (date, computername, name, location, command, user)
VALUES (@date, @computername, @name, @location, @command, @user)'
$diskQuery = 'INSERT INTO disk (date, computername, deviceid, description, providername)
VALUES (@date, @computername, @deviceid, @description, @providername)'
$driversQuery = 'INSERT INTO drivers (date, computername, name, installdate, displayname, pathname, state, startmode)
VALUES (@date, @computername, @name, @installdate, @displayname, @pathname, @state, @startmode)'
$envQuery = 'INSERT INTO env (date, computername, username, name, variablevalue)
VALUES (@date, @computername, @username, @name, @variablevalue)'
$appevtQuery = 'INSERT INTO appevt (date, computername, logfile, eventcode, timegenerated, message, type)
VALUES (@date, @computername, @logfile, @eventcode, @timegenerated, @message, @type)'
$secevtQuery = 'INSERT INTO secevt (date, computername, logfile, eventcode, timegenerated, message, type)
VALUES (@date, @computername, @logfile, @eventcode, @timegenerated, @message, @type)'
$sysevtQuery = 'INSERT INTO sysevt (date, computername, logfile, eventcode, timegenerated, message, type)
VALUES (@date, @computername, @logfile, @eventcode, @timegenerated, @message, @type)'
$groupsQuery = 'INSERT INTO groups (date, computername, caption, domain, name, sid)
VALUES (@date, @computername, @caption, @domain, @name, @sid)'
$loggedinuserQuery = 'INSERT INTO loggedinuser (date, computername, username)
VALUES (@date, @computername, @username)'
$netlogonQuery = 'INSERT INTO netlogon (date, computername, name, lastlogon, lastlogoff, numberoflogons, passwordage)
VALUES (@date, @computername, @name, @lastlogon, @lastlogoff, @numberoflogons, @passwordage)'
$mappeddrivesQuery = 'INSERT INTO mappeddrives (date, computername, providername)
VALUES (@date, @computername, @providername)'
$processQuery = 'INSERT INTO process (date, computername, name, path, commandline, description, processid, parentprocessid, handle, handlecount, threadcount, creationdate)
VALUES (@date, @computername, @name, @path, @commandline, @description, @processid, @parentprocessid, @handle, @handlecount, @threadcount, @creationdate)'
$schedtaskQuery = 'INSERT INTO schedtask (date, computername, name, owner, jobid, command, runrepeatedly, interactwithdesktop)
VALUES (@date, @computername, @name, @owner, @jobid, @command, @runrepeatedly, @interactwithdesktop)'
$servicesQuery = 'INSERT INTO services (date, computername, processid, name, description, pathname, started, startmode, startname, state)
VALUES (@date, @computername, @processid, @name, @description, @pathname, @started, @startmode, @startname, @state)'
$useraccountQuery = 'INSERT INTO useraccount (date, computername, accounttype, fullname, domain, disabled, localaccount, lockedout, passwordchangeable, passwordexpires, sid)
VALUES (@date, @computername, @accounttype, @fullname, @domain, @disabled, @localaccount, @lockedout, @passwordchangeable, @passwordexpires, @sid)'
$networksQuery = 'INSERT INTO networks (date, computername, ipaddress, ipsubnet, defaultipgateway, dhcpserver, dnshostname, dnsserversearchorder, macaddress, description)
VALUES (@date, @computername, @ipaddress, @ipsubnet, @defaultipgateway, @dhcpserver, @dnshostname, @dnsserversearchorder, @macaddress, @description)'
$sharesQuery = 'INSERT INTO shares (date, computername, name, path, description)
VALUES (@date, @computername, @name, @path, @description)'
$computersystemQuery = 'INSERT INTO computersystem (date, computername, domain, model, manufacturer, enabledaylightsavingstime, partofdomain, roles, systemtype, numberofprocessors, totalphysicalmemory, username)
VALUES (@date, @computername, @domain, @model, @manufacturer, @enabledaylightsavingstime, @partofdomain, @roles, @systemtype, @numberofprocessors, @totalphysicalmemory, @username)'
$patchQuery = 'INSERT INTO patch (date, computername, hotfixid, description, installedby, installedon)
VALUES (@date, @computername, @hotfixid, @description, @installedby, @installedon)'
$softwareQuery = 'INSERT INTO software (date, computername, name, packetcache, vendor, version, identifyingnumber)
VALUES (@date, @computername, @name, @packetcache, @vendor, @version, @identifyingnumber)'
$connectionsQuery = 'INSERT INTO connections (date, computername, protocol, version, localaddress, localport, remoteaddress, remoteport, state, processid, processname, processpath)
VALUES (@date, @computername, @protocol, @version, @localaddress, @localport, @remoteaddress, @remoteport, @state, @processid, @processname, @processpath)'
foreach($item in $autorun){
Invoke-SqliteQuery -DataSource $poshDB -Query $autorunQuery -SqlParameters @{
date = (get-item $PSScriptRoot\PoSh-R2_data\$dirDate\Autoruns.csv).CreationTimeUtc
computername = $item.pscomputername
name = $item.name
location = $item.location
command = $item.command
user = $item.user
} | Out-Null
}
foreach($item in $disk){
Invoke-SqliteQuery -DataSource $poshDB -Query $diskQuery -SqlParameters @{
date = (get-item $PSScriptRoot\PoSh-R2_data\$dirDate\disk.csv).CreationTimeUtc
computername = $item.pscomputername
deviceid = $item.deviceid
description = $item.description
providername = $item.providername
} | Out-Null
}
foreach($item in $drivers){
Invoke-SqliteQuery -DataSource $poshDB -Query $driversQuery -SqlParameters @{
date = (get-item $PSScriptRoot\PoSh-R2_data\$dirDate\drivers.csv).CreationTimeUtc
computername = $item.pscomputername
name = $item.name
installdate = $item.installdate
displayname = $item.displayname
pathname = $item.pathname
state = $item.state
startmode = $item.startmode
} | Out-Null
}
foreach($item in $envVar){
Invoke-SqliteQuery -DataSource $poshDB -Query $envQuery -SqlParameters @{
date = (get-item $PSScriptRoot\PoSh-R2_data\$dirDate\Environment_Variables.csv).CreationTimeUtc
computername = $item.pscomputername
username = $item.username
name = $item.name
variablevalue = $item.variablevalue
} | Out-Null
}
foreach($item in $evtApp){
Invoke-SqliteQuery -DataSource $poshDB -Query $appevtQuery -SqlParameters @{
date = (get-item $PSScriptRoot\PoSh-R2_data\$dirDate\Eventlogs-Application.csv).CreationTimeUtc
computername = $item.pscomputername