-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-WindowsSystemDetails.ps1
More file actions
2741 lines (2558 loc) · 152 KB
/
Copy pathGet-WindowsSystemDetails.ps1
File metadata and controls
2741 lines (2558 loc) · 152 KB
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
This cmdlet will report interesting details about a local or remote machine.
.DESCRIPTION
.PARAMETER ComputerName
This is an optional parameter which defines the computer name to pull information from.
.PARAMETER Credential
This is an optional parameter which defines the credential to be used for pulling the information.
.INPUTS
None. You cannot pipe objects to this script.
.OUTPUTS
[Object] This command will return an object with information about the specified computer.
.EXAMPLE
$localMachine = Get-WindowsSystemDetails;
The preceding example exports information from the local computer.
.EXAMPLE
$remoteMachine = Get-WindowsSystemDetails -ComputerName SERVER1
The preceding example exports information from the computer named SERVER1.
.EXAMPLE
$creds = Get-Credential;
$remoteMachine = Get-WindowsSystemDetails -ComputerName SERVER2 -Credential $creds;
The preceding example exports information from the computer named SERVER2 using the
the account information stored in $creds.
.NOTES
Author: fr3dd
Version: 1.0.0
.LINK
https://github.com/fr3dd/PSUtils.git
#>
#region API definitions
$typeDefinition = @'
using System;
namespace PowerShell.UserRights
{
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal;
using LSA_HANDLE = IntPtr;
public enum Rights
{
SeTrustedCredManAccessPrivilege, // Access Credential Manager as a trusted caller
SeNetworkLogonRight, // Access this computer from the network
SeTcbPrivilege, // Act as part of the operating system
SeMachineAccountPrivilege, // Add workstations to domain
SeIncreaseQuotaPrivilege, // Adjust memory quotas for a process
SeInteractiveLogonRight, // Allow log on locally
SeRemoteInteractiveLogonRight, // Allow log on through Remote Desktop Services
SeBackupPrivilege, // Back up files and directories
SeChangeNotifyPrivilege, // Bypass traverse checking
SeSystemtimePrivilege, // Change the system time
SeTimeZonePrivilege, // Change the time zone
SeCreatePagefilePrivilege, // Create a pagefile
SeCreateTokenPrivilege, // Create a token object
SeCreateGlobalPrivilege, // Create global objects
SeCreatePermanentPrivilege, // Create permanent shared objects
SeCreateSymbolicLinkPrivilege, // Create symbolic links
SeDebugPrivilege, // Debug programs
SeDenyNetworkLogonRight, // Deny access this computer from the network
SeDenyBatchLogonRight, // Deny log on as a batch job
SeDenyServiceLogonRight, // Deny log on as a service
SeDenyInteractiveLogonRight, // Deny log on locally
SeDenyRemoteInteractiveLogonRight, // Deny log on through Remote Desktop Services
SeEnableDelegationPrivilege, // Enable computer and user accounts to be trusted for delegation
SeRemoteShutdownPrivilege, // Force shutdown from a remote system
SeAuditPrivilege, // Generate security audits
SeImpersonatePrivilege, // Impersonate a client after authentication
SeIncreaseWorkingSetPrivilege, // Increase a process working set
SeIncreaseBasePriorityPrivilege, // Increase scheduling priority
SeLoadDriverPrivilege, // Load and unload device drivers
SeLockMemoryPrivilege, // Lock pages in memory
SeBatchLogonRight, // Log on as a batch job
SeServiceLogonRight, // Log on as a service
SeSecurityPrivilege, // Manage auditing and security log
SeRelabelPrivilege, // Modify an object label
SeSystemEnvironmentPrivilege, // Modify firmware environment values
SeManageVolumePrivilege, // Perform volume maintenance tasks
SeProfileSingleProcessPrivilege, // Profile single process
SeSystemProfilePrivilege, // Profile system performance
SeUnsolicitedInputPrivilege, // "Read unsolicited input from a terminal device"
SeUndockPrivilege, // Remove computer from docking station
SeAssignPrimaryTokenPrivilege, // Replace a process level token
SeRestorePrivilege, // Restore files and directories
SeShutdownPrivilege, // Shut down the system
SeSyncAgentPrivilege, // Synchronize directory service data
SeTakeOwnershipPrivilege // Take ownership of files or other objects
}
[StructLayout(LayoutKind.Sequential)]
struct LSA_OBJECT_ATTRIBUTES
{
internal int Length;
internal IntPtr RootDirectory;
internal IntPtr ObjectName;
internal int Attributes;
internal IntPtr SecurityDescriptor;
internal IntPtr SecurityQualityOfService;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct LSA_UNICODE_STRING
{
internal ushort Length;
internal ushort MaximumLength;
[MarshalAs(UnmanagedType.LPWStr)]
internal string Buffer;
}
[StructLayout(LayoutKind.Sequential)]
struct LSA_ENUMERATION_INFORMATION
{
internal IntPtr PSid;
}
internal sealed class Win32Sec
{
[DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern uint LsaOpenPolicy(
LSA_UNICODE_STRING[] SystemName,
ref LSA_OBJECT_ATTRIBUTES ObjectAttributes,
int AccessMask,
out IntPtr PolicyHandle
);
[DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern uint LsaAddAccountRights(
LSA_HANDLE PolicyHandle,
IntPtr pSID,
LSA_UNICODE_STRING[] UserRights,
int CountOfRights
);
[DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern uint LsaRemoveAccountRights(
LSA_HANDLE PolicyHandle,
IntPtr pSID,
bool AllRights,
LSA_UNICODE_STRING[] UserRights,
int CountOfRights
);
[DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern uint LsaEnumerateAccountRights(
LSA_HANDLE PolicyHandle,
IntPtr pSID,
out IntPtr /*LSA_UNICODE_STRING[]*/ UserRights,
out ulong CountOfRights
);
[DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern uint LsaEnumerateAccountsWithUserRight(
LSA_HANDLE PolicyHandle,
LSA_UNICODE_STRING[] UserRights,
out IntPtr EnumerationBuffer,
out ulong CountReturned
);
[DllImport("advapi32")]
internal static extern int LsaNtStatusToWinError(int NTSTATUS);
[DllImport("advapi32")]
internal static extern int LsaClose(IntPtr PolicyHandle);
[DllImport("advapi32")]
internal static extern int LsaFreeMemory(IntPtr Buffer);
}
internal sealed class Sid : IDisposable
{
public IntPtr pSid = IntPtr.Zero;
public SecurityIdentifier sid = null;
public Sid(string account)
{
try { sid = new SecurityIdentifier(account); }
catch { sid = (SecurityIdentifier)(new NTAccount(account)).Translate(typeof(SecurityIdentifier)); }
Byte[] buffer = new Byte[sid.BinaryLength];
sid.GetBinaryForm(buffer, 0);
pSid = Marshal.AllocHGlobal(sid.BinaryLength);
Marshal.Copy(buffer, 0, pSid, sid.BinaryLength);
}
public void Dispose()
{
if (pSid != IntPtr.Zero)
{
Marshal.FreeHGlobal(pSid);
pSid = IntPtr.Zero;
}
GC.SuppressFinalize(this);
}
~Sid() { Dispose(); }
}
public sealed class LsaWrapper : IDisposable
{
enum Access : int
{
POLICY_READ = 0x20006,
POLICY_ALL_ACCESS = 0x00F0FFF,
POLICY_EXECUTE = 0X20801,
POLICY_WRITE = 0X207F8
}
const uint STATUS_ACCESS_DENIED = 0xc0000022;
const uint STATUS_INSUFFICIENT_RESOURCES = 0xc000009a;
const uint STATUS_NO_MEMORY = 0xc0000017;
const uint STATUS_OBJECT_NAME_NOT_FOUND = 0xc0000034;
const uint STATUS_NO_MORE_ENTRIES = 0x8000001a;
IntPtr lsaHandle;
public LsaWrapper() : this(null) { } // local system if systemName is null
public LsaWrapper(string systemName)
{
LSA_OBJECT_ATTRIBUTES lsaAttr;
lsaAttr.RootDirectory = IntPtr.Zero;
lsaAttr.ObjectName = IntPtr.Zero;
lsaAttr.Attributes = 0;
lsaAttr.SecurityDescriptor = IntPtr.Zero;
lsaAttr.SecurityQualityOfService = IntPtr.Zero;
lsaAttr.Length = Marshal.SizeOf(typeof(LSA_OBJECT_ATTRIBUTES));
lsaHandle = IntPtr.Zero;
LSA_UNICODE_STRING[] system = null;
if (systemName != null)
{
system = new LSA_UNICODE_STRING[1];
system[0] = InitLsaString(systemName);
}
uint ret = Win32Sec.LsaOpenPolicy(system, ref lsaAttr, (int)Access.POLICY_ALL_ACCESS, out lsaHandle);
if (ret == 0) return;
if (ret == STATUS_ACCESS_DENIED) throw new UnauthorizedAccessException();
if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY)) throw new OutOfMemoryException();
throw new Win32Exception(Win32Sec.LsaNtStatusToWinError((int)ret));
}
public Rights[] EnumerateAccountPrivileges(string account)
{
uint ret = 0;
ulong count = 0;
IntPtr privileges = IntPtr.Zero;
Rights[] rights = null;
using (Sid sid = new Sid(account))
{
ret = Win32Sec.LsaEnumerateAccountRights(lsaHandle, sid.pSid, out privileges, out count);
}
if (ret == 0)
{
rights = new Rights[count];
for (int i = 0; i < (int)count; i++)
{
LSA_UNICODE_STRING str = (LSA_UNICODE_STRING)Marshal.PtrToStructure(
IntPtr.Add(privileges, i * Marshal.SizeOf(typeof(LSA_UNICODE_STRING))),
typeof(LSA_UNICODE_STRING));
rights[i] = (Rights)Enum.Parse(typeof(Rights), str.Buffer);
}
Win32Sec.LsaFreeMemory(privileges);
return rights;
}
if (ret == STATUS_OBJECT_NAME_NOT_FOUND) return null; // No privileges assigned
if (ret == STATUS_ACCESS_DENIED) throw new UnauthorizedAccessException();
if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY)) throw new OutOfMemoryException();
throw new Win32Exception(Win32Sec.LsaNtStatusToWinError((int)ret));
}
public string[] EnumerateAccountsWithUserRight(Rights privilege)
{
uint ret = 0;
ulong count = 0;
LSA_UNICODE_STRING[] rights = new LSA_UNICODE_STRING[1];
rights[0] = InitLsaString(privilege.ToString());
IntPtr buffer = IntPtr.Zero;
string[] accounts = null;
ret = Win32Sec.LsaEnumerateAccountsWithUserRight(lsaHandle, rights, out buffer, out count);
if (ret == 0)
{
accounts = new string[count];
for (int i = 0; i < (int)count; i++)
{
LSA_ENUMERATION_INFORMATION LsaInfo = (LSA_ENUMERATION_INFORMATION)Marshal.PtrToStructure(
IntPtr.Add(buffer, i * Marshal.SizeOf(typeof(LSA_ENUMERATION_INFORMATION))),
typeof(LSA_ENUMERATION_INFORMATION));
try {
accounts[i] = (new SecurityIdentifier(LsaInfo.PSid)).Translate(typeof(NTAccount)).ToString();
} catch (System.Security.Principal.IdentityNotMappedException) {
accounts[i] = (new SecurityIdentifier(LsaInfo.PSid)).ToString();
}
}
Win32Sec.LsaFreeMemory(buffer);
return accounts;
}
if (ret == STATUS_NO_MORE_ENTRIES) return null; // No accounts assigned
if (ret == STATUS_ACCESS_DENIED) throw new UnauthorizedAccessException();
if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY)) throw new OutOfMemoryException();
throw new Win32Exception(Win32Sec.LsaNtStatusToWinError((int)ret));
}
public void Dispose()
{
if (lsaHandle != IntPtr.Zero)
{
Win32Sec.LsaClose(lsaHandle);
lsaHandle = IntPtr.Zero;
}
GC.SuppressFinalize(this);
}
~LsaWrapper() { Dispose(); }
// helper functions:
static LSA_UNICODE_STRING InitLsaString(string s)
{
// Unicode strings max. 32KB
if (s.Length > 0x7ffe) throw new ArgumentException("String too long");
LSA_UNICODE_STRING lus = new LSA_UNICODE_STRING();
lus.Buffer = s;
lus.Length = (ushort)(s.Length * sizeof(char));
lus.MaximumLength = (ushort)(lus.Length + sizeof(char));
return lus;
}
}
}
'@;
if ( $PSEdition -ne 'Core' ) {
if ( -not ( [System.Management.Automation.PSTypeName]'PowerShell.UserRights.Rights' ).Type ) {
Add-Type $typeDefinition -ErrorAction SilentlyContinue;
}
}
#endregion
function Get-WindowsSystemDetails {
[CmdletBinding()]
Param
(
[CmdletBinding()]
[Parameter( Position = 0, Mandatory = $false, HelpMessage = 'Enter the computer name that you what to collect information from' )]
[String] $ComputerName = ".",
[Parameter( Position = 1, Mandatory = $false, HelpMessage = 'Enter a credential to perform the task' )]
[Management.Automation.PSCredential] $Credential = $null
)
Write-Verbose -Message 'Cmdlet: Get-WindowsSystemDetails';
Write-Verbose -Message ( " -ComputerName = {0}" -f $ComputerName );
Write-Verbose -Message ( " -Credential = {0}" -f $Credential );
[Boolean] $collectOptionalFeatures = $false;
[Boolean] $collectServerFeatures = $false;
[Boolean] $collectTasks = $false;
[Boolean] $collectUserProfiles = $false;
[Object] $errorOutput = [pscustomobject][ordered] @{
Message = ''
}
[Object] $output = [pscustomobject][ordered] @{
'_bcObjectType' = 'wmiComputer'
'_bcID' = ''
BootupState = ''
Certificates = [Collections.ArrayList] @()
ComputerName = ''
Disks = [Collections.ArrayList] @()
DomainName = ''
DomainRole = ''
DNSHostName = ''
EnvironmentVariables = [ordered] @{}
Groups = [ordered] @{}
HostsFile = [Collections.ArrayList] @()
InstalledFeatures = [Collections.ArrayList] @()
InstalledRoles = [Collections.ArrayList] @()
IsDomainController = $false
IsDomainMember = $false
IsPDCEmulator = $false
IsVirtual = $false
IsWorkgroupMember = $false
LastBootUpTime = ''
LogicalProcessors = 1
Manufacturer = ''
Memory = 0
MissingSubnets = [Collections.ArrayList] @()
Model = ''
NetworkAdapters = [Collections.ArrayList] @()
OperatingSystem = ''
OperatingSystemArchitecture = ''
OperatingSystemLanguage = 1033
OperatingSystemServicePack = ''
OperatingSystemSKU = ''
OperatingSystemVersion = ''
PhysicalProcessors = 1
Printers = [Collections.ArrayList] @()
SerialNumber = ''
Services = [Collections.ArrayList] @()
Shares = [Collections.ArrayList] @()
Software = [Collections.ArrayList] @()
SystemDirectory = ''
SystemType = ''
TCPPorts = [Collections.ArrayList] @()
TimeDaylightInEffect = $false
TimeSyncSource = ''
TimeSyncType = ''
TimeZone = ''
UserProfiles = [Collections.ArrayList] @()
UserRights = [ordered] @{}
Users = [Collections.ArrayList] @()
WindowsDirectory = ''
WorkgroupName = ''
}
Write-Verbose -Message 'Update local computer value based on passed information';
if ( $ComputerName -eq '.' ) {
$localComputer = $env:COMPUTERNAME;
} else {
$localComputer = $ComputerName.ToUpper();
}
Write-Verbose -Message ( "`$localComputer = {0}" -f $localComputer );
Write-Verbose -Message 'Trying to ping the machine';
if ( Test-Connection -BufferSize 32 -Count 1 -Quiet -ComputerName $localComputer ) {
$cimOptions = New-CimSessionOption -Protocol Dcom;
if ( $Credential ) {
Write-Verbose -Message ( "Establishing a CIM session with the following account: {0}" -f $Credential.UserName );
$cimSession = New-CimSession -ComputerName $localComputer -Credential $Credential -SessionOption $cimOptions -ErrorAction SilentlyContinue;
} else {
Write-Verbose -Message ( "Establishing a CIM session with the current account: {0}\{1}" -f $env:USERDOMAIN, $env:USERNAME );
$cimSession = New-CimSession -ComputerName $localComputer -SessionOption $cimOptions -ErrorAction SilentlyContinue;
}
if ( $null -eq $cimSession ) {
Write-Warning -Message "Unable to connect to $localComputer via WMI";
$errorOutput.Message = 'WMIError';
$output = $errorOutput;
} else {
$wmiClass = 'Win32_ComputerSystem';
Write-Verbose -Message ( "`$wmiClass = {0}" -f $wmiClass );
Write-Verbose -Message "Collect WMI information from $wmiClass";
$cimData = Get-CimInstance -CimSession $cimSession -ClassName $wmiClass;
if ( $null -ne $cimData ) {
$output.BootupState = $cimData.BootupState;
Write-Verbose -Message ( "`$output.BootupState = {0}" -f $output.BootupState );
$output._bcID = $cimData.Name;
Write-Verbose -Message ( "`$output.ComputerName = {0}" -f $output.ComputerName );
$output.ComputerName = $cimData.Name;
Write-Verbose -Message ( "`$output.ComputerName = {0}" -f $output.ComputerName );
Write-Verbose -Message 'Check for machine name match';
if ( $localComputer -ne $cimData.Name ) {
Write-Verbose -Message ( "{0} <> {1}" -f $localComputer, $cimData.Name );
Write-Verbose -Message 'Checking NetBIOS name in case this is the Fully-Qualified Domain Name';
if ( $localComputer.Contains( '.' ) ) {
$netBIOSName = $localComputer.Split( '.' )[ 0 ];
Write-Verbose -Message ( "`$netBIOSName = {0}" -f $netBIOSName );
Write-Verbose -Message 'Check for machine name match';
if ( $netBIOSName -ne $cimData.Name ) {
Write-Verbose -Message ( "Provided name ({0}) does not match target machine name of ({1})" -f $netBIOSName, $cimData.Name );
} else {
Write-Verbose -Message ( "{0} = {1}" -f $netBIOSName, $cimData.Name );
}
} else {
Write-Verbose -Message ( "Provided name ({0}) does not match target machine name of ({1})" -f $localComputer, $cimData.Name );
}
}
$output.LogicalProcessors = $cimData.NumberOfLogicalProcessors;
Write-Verbose -Message ( "`$output.LogicalProcessors = {0}" -f $output.LogicalProcessors );
$output.PhysicalProcessors = $cimData.NumberOfProcessors;
Write-Verbose -Message ( "`$output.PhysicalProcessors = {0}" -f $output.PhysicalProcessors );
$output.TimeDaylightInEffect = $cimData.DaylightInEffect;
Write-Verbose -Message ( "`$output.TimeDaylightInEffect = {0}" -f $output.TimeDaylightInEffect );
$output.Manufacturer = $cimData.Manufacturer;
Write-Verbose -Message ( "`$output.Manufacturer = {0}" -f $output.Manufacturer );
$output.Memory = "{0} GB" -f [Math]::Round( $cimData.TotalPhysicalMemory / 1GB );
Write-Verbose -Message ( "`$output.Memory = {0}" -f $output.Memory );
$output.Model = $cimData.Model;
Write-Verbose -Message ( "`$output.Model = {0}" -f $output.Model );
if ( $output.Model -like '*Virtual*' ) {
$output.IsVirtual = $true;
} elseif ( $output.Model -like '*VMware*' ) {
$output.IsVirtual = $true;
} elseif ( $output.Model -like '*Microsoft*' ) {
$output.IsVirtual = $true;
} elseif ( $output.Model -like '*Xen*' ) {
$output.IsVirtual = $true;
} elseif ( $output.Model -like '*A M I*' ) {
$output.IsVirtual = $true;
} else {
$output.IsVirtual = $false;
}
Write-Verbose -Message ( "`$output.IsVirtual = {0}" -f $output.IsVirtual );
$output.SystemType = $cimData.SystemType;
Write-Verbose -Message ( "`$output.SystemType = {0}" -f $output.SystemType );
if ( $cimData.PartOfDomain ) {
$output.DomainName = $cimData.Domain;
Write-Verbose -Message ( "`$output.DomainName = {0}" -f $output.DomainName );
$output.DNSHostName = [String]::Format( "{0}.{1}", $cimData.Caption.ToLower(), $output.DomainName );
Write-Verbose -Message ( "`$output.DNSHostName = {0}" -f $output.DNSHostName );
$output.IsDomainMember = $true;
Write-Verbose -Message ( "`$output.IsDomainMember = {0}" -f $output.IsDomainMember );
$output.IsWorkgroupMember = $false;
Write-Verbose -Message ( "`$output.IsWorkgroupMember = {0}" -f $output.IsWorkgroupMember );
switch ( $cimData.DomainRole ) {
0 {
$output.DomainRole = 'Stadard Workstation';
$output.IsDomainController = $false;
$output.IsPDCEmulator = $false;
}
1 {
$output.DomainRole = 'Member Workstation';
$output.IsDomainController = $false;
$output.IsPDCEmulator = $false;
}
2 {
$output.DomainRole = 'Standard Server';
$output.IsDomainController = $false;
$output.IsPDCEmulator = $false;
}
3 {
$output.DomainRole = 'Member Server';
$output.IsDomainController = $false;
$output.IsPDCEmulator = $false;
}
4 {
$output.DomainRole = 'Domain Controller';
$output.IsDomainController = $true;
$output.IsPDCEmulator = $false;
}
5 {
$output.DomainRole = 'Domain Controller';
$output.IsDomainController = $true;
$output.IsPDCEmulator = $true;
}
}
Write-Verbose -Message ( "`$output.DomainRole = {0}" -f $output.DomainRole );
Write-Verbose -Message ( "`$output.IsDomainController = {0}" -f $output.IsDomainController );
Write-Verbose -Message ( "`$output.IsPDCEmulator = {0}" -f $output.IsPDCEmulator );
#bookmark Missing Subnet Information
if ( $output.IsDomainController ) {
Write-Verbose -Message 'Attempt to access netlogon file on DC to determine missing subnets';
Write-Verbose -Message 'Creating a PSDrive to reference the hosts file directory';
$remoteUNCPath = "\\{0}\admin$\debug" -f $localComputer;
Write-Verbose -Message ( "`$remoteUNCPath = {0}" -f $remoteUNCPath );
if ( $Credential ) {
$remoteDrive = New-PSDrive -Name 'remoteDrive' -PSProvider FileSystem -Root $remoteUNCPath -Credential $Credential -ErrorAction SilentlyContinue;
} else {
$remoteDrive = New-PSDrive -Name 'remoteDrive' -PSProvider FileSystem -Root $remoteUNCPath -ErrorAction SilentlyContinue;
}
if ( $null -ne $remoteDrive) {
[String] $netlogonPath = "remoteDrive:\netlogon.log" -f $remoteUNCPath;
Write-Verbose -Message ( "`$netlogonPath = {0}" -f $netlogonPath );
if ( Test-Path -Path $netlogonPath ) {
[Array] $netlogon = Get-Content -Path $netlogonPath -Tail 500 | Select-String 'NO_CLIENT_SITE:';
$missingSubnets = [Collections.ArrayList] @();
if ( $null -ne $netlogon ) {
foreach ( $netlogonEntry in $netlogon ) {
[String[]] $lineData = $netlogonEntry.ToString().Split(' ');
[String] $machineName = $lineData[ $lineData.Count - 2 ];
Write-Verbose -Message ( "`$machineName = {0}" -f $machineName );
[String] $ipAddress = "{0}.0/24" -f $lineData[ $lineData.Count - 1 ].Substring( 0, $lineData[ $lineData.Count - 1 ].LastIndexOf( '.' ) );
Write-Verbose -Message ( "`$ipAddress = {0}" -f $ipAddress );
if ( -not $missingSubnets.Contains( $ipAddress ) ) {
[Void] $missingSubnets.Add( $ipAddress );
}
}
}
}
Write-Verbose -Message 'Remove the PSDrive';
if ( Get-PSDrive -Name 'remoteDrive' ) {
Remove-PSDrive -Name 'remoteDrive';
}
}
$output.MissingSubnets = $missingSubnets;
}
} else {
$output.DNSHostName = $cimData.Name.ToLower();
$output.IsDomainMember = $false;
$output.IsWorkgroupMember = $true;
$output.WorkgroupName = $cimData.Workgroup;
}
#bookmark Collect disk information
try {
$wmiClass = 'Win32_LogicalDisk';
Write-Verbose -Message ( "`$wmiClass = {0}" -f $wmiClass );
Write-Verbose -Message "Collect WMI information from $wmiClass";
$cimData = Get-CimInstance -CimSession $cimSession -ClassName $wmiClass;
$logicalDisk = [ordered] @{
0 = 'Unknown'
1 = 'No root directory'
2 = 'Removable disk'
3 = 'Local disk'
4 = 'Network drive'
5 = 'Compact disc'
6 = 'RAM disk'
}
if ( $null -ne $cimData ) {
foreach ( $item in $cimData ) {
$freeSpace = "{0} GB" -f [Math]::Round( $item.FreeSpace / 1GB );
Write-Verbose -Message ( "`$freeSpace = {0}" -f $freeSpace );
$capacity = "{0} GB" -f [Math]::Round( $item.Size / 1GB );
Write-Verbose -Message ( "`$capacity = {0}" -f $capacity );
[Int32] $driveType = [Convert]::ToInt32( $item.DriveType );
Write-Verbose -Message ( "`$driveType = {0}" -f $driveType );
$childObject = [pscustomobject][ordered] @{
DeviceID = $item.DeviceID
DriveType = $logicalDisk[ $driveType ]
Capacity = $capacity
FreeSpace = $freeSpace
VolumeName = $item.VolumeName
}
[Void] $output.Disks.Add( $childObject );
}
$childObject = $null;
}
} catch {
Write-Verbose -Message 'Logical disk information could not be collected';
}
#bookmark Collect environment variable information
try {
$wmiClass = 'Win32_Environment';
Write-Verbose -Message ( "`$wmiClass = {0}" -f $wmiClass );
Write-Verbose -Message "Collect WMI information from $wmiClass";
$cimData = Get-CimInstance -CimSession $cimSession -ClassName $wmiClass;
if ( $null -ne $cimData ) {
foreach ( $item in $cimData ) {
Write-Verbose -Message 'Collect only system-level environment variables';
if ( $item.UserName -eq '<SYSTEM>' ) {
[String] $environmentVariable = $item.Name;
[String] $environmentVariableValue = $item.VariableValue;
[Void] $output.EnvironmentVariables.Add( $environmentVariable, $environmentVariableValue );
}
}
}
} catch {
Write-Verbose -Message 'Environment information could not be collected';
}
#bookmark Collect operating system information
try {
$wmiClass = 'Win32_OperatingSystem';
Write-Verbose -Message ( "`$wmiClass = {0}" -f $wmiClass );
Write-Verbose -Message "Collect WMI information from $wmiClass";
$cimData = Get-CimInstance -CimSession $cimSession -ClassName $wmiClass;
if ( $null -ne $cimData ) {
$output.OperatingSystem = $cimData.Name.Split( '|' )[ 0 ];
Write-Verbose -Message ( "`$output.OperatingSystem = {0}" -f $output.OperatingSystem );
switch ( $output.OperatingSystem ) {
{ $_ -like '*Windows 7*' } {
$collectOptionalFeatures = $true;
$collectTasks = $true;
$collectUserProfiles = $true;
$oemServices = @(
'ActiveX Installer (AxInstSV)',
'Adaptive Brightness',
'Application Experience',
'Application Identity',
'Application Information',
'Application Layer Gateway Service',
'Application Management',
'Background Intelligent Transfer Service',
'Base Filtering Engine',
'BitLocker Drive Encryption Service',
'Block Level Backup Engine Service',
'Bluetooth Support Service',
'BranchCache',
'Certificate Propagation',
'CNG Key Isolation',
'COM+ Event System',
'COM+ System Application',
'Computer Browser',
'Credential Manager',
'Cryptographic Services',
'DCOM Server Process Launcher',
'Desktop Window Manager Session Manager',
'DHCP Client',
'Diagnostic Policy Service',
'Diagnostic Service Host',
'Diagnostic System Host',
'Disk Defragmenter',
'Distributed Link Tracking Client',
'Distributed Transaction Coordinator',
'DNS Client',
'Encrypting File System (EFS)',
'Extensible Authentication Protocol',
'Fax',
'Function Discovery Provider Host',
'Function Discovery Resource Publication',
'Group Policy Client',
'Health Key and Certificate Management',
'HomeGroup Provider',
'Human Interface Device Access',
'Hyper-V Data Exchange Service',
'Hyper-V Guest Shutdown Service',
'Hyper-V Heartbeat Service',
'Hyper-V Time Synchronization Service',
'Hyper-V Volume Shadow Copy Requestor',
'IKE and AuthIP IPsec Keying Modules',
'Interactive Services Detection',
'Internet Connection Sharing (ICS)',
'IP Helper',
'IPsec Policy Agent',
'KtmRm for Distributed Transaction Coordinator',
'Link-Layer Topology Discovery Mapper',
'Media Center Extender Service',
'Microsoft .NET Framework NGEN v2.0.50727_X86',
'Microsoft iSCSI Initiator Service',
'Microsoft Software Shadow Copy Provider',
'Multimedia Class Scheduler',
'Net.Tcp Port Sharing Service',
'Netlogon',
'Network Access Protection Agent',
'Network Connections',
'Network List Service',
'Network Location Awareness',
'Network Store Interface Service',
'Offline Files',
'Parental Controls',
'Peer Name Resolution Protocol',
'Peer Networking Grouping',
'Peer Networking Identity Manager',
'Performance Logs & Alerts',
'Plug and Play',
'PnP-X IP Bus Enumerator',
'PNRP Machine Name Publication Service',
'Portable Device Enumerator Service',
'Power',
'Print Spooler',
'Problem Reports and Solutions Control Panel Support',
'Program Compatibility Assistant Service',
'Protected Storage',
'Quality Windows Audio Video Experience',
'Remote Access Auto Connection Manager',
'Remote Access Connection Manager',
'Remote Desktop Configuration',
'Remote Desktop Services',
'Remote Desktop Services UserMode Port Redirector',
'Remote Procedure Call (RPC)',
'Remote Procedure Call (RPC) Locator',
'Remote Registry',
'Routing and Remote Access',
'RPC Endpoint Mapper',
'Secondary Logon',
'Secure Socket Tunneling Protocol Service',
'Security Accounts Manager',
'Security Center',
'Server',
'Shell Hardware Detection',
'Smart Card',
'Smart Card Removal Policy',
'SNMP Trap',
'Software Protection',
'SPP Notification Service',
'SSDP Discovery',
'Storage Service',
'Superfetch',
'System Event Notification Service',
'Tablet PC Input Service',
'Task Scheduler',
'TCP/IP NetBIOS Helper',
'Telephony',
'Themes',
'Thread Ordering Server',
'TPM Base Services',
'UPnP Device Host',
'User Profile Service',
'Virtual Disk',
'Volume Shadow Copy',
'WebClient',
'Windows Audio',
'Windows Audio Endpoint Builder',
'Windows Backup',
'Windows Biometric Service',
'Windows CardSpace',
'Windows Color System',
'Windows Connect Now - Config Registrar',
'Windows Defender',
'Windows Driver Foundation - User-mode Driver Framework',
'Windows Error Reporting Service',
'Windows Event Collector',
'Windows Event Log',
'Windows Firewall',
'Windows Font Cache Service',
'Windows Image Acquisition (WIA)',
'Windows Installer',
'Windows Management Instrumentation',
'Windows Media Center Receiver Service',
'Windows Media Center Scheduler Service',
'Windows Media Player Network Sharing Service',
'Windows Modules Installer',
'Windows Presentation Foundation Font Cache 3.0.0.0',
'Windows Remote Management (WS-Management)',
'Windows Search',
'Windows Time',
'Windows Update',
'WinHTTP Web Proxy Auto-Discovery Service',
'Wired AutoConfig',
'WLAN AutoConfig',
'WMI Performance Adapter',
'Workstation',
'WWAN AutoConfig'
);
}
{ $_ -like '*Windows 8*' } {
$collectOptionalFeatures = $true;
$collectTasks = $true;
$collectUserProfiles = $true;
$oemServices = @(
'ActiveX Installer (AxInstSV)',
'Application Experience',
'Application Identity',
'Application Information',
'Application Layer Gateway Service',
'Application Management',
'Background Intelligent Transfer Service',
'Background Tasks Infrastructure Service',
'Base Filtering Engine',
'BitLocker Drive Encryption Service',
'Block Level Backup Engine Service',
'Bluetooth Support Service',
'BranchCache',
'Certificate Propagation',
'CNG Key Isolation',
'COM+ Event System',
'COM+ System Application',
'Computer Browser',
'Credential Manager',
'Cryptographic Services',
'DCOM Server Process Launcher',
'Device Association Service',
'Device Install Service',
'Device Setup Manager',
'DHCP Client',
'Diagnostic Policy Service',
'Diagnostic Service Host',
'Diagnostic System Host',
'Distributed Link Tracking Client',
'Distributed Transaction Coordinator',
'DNS Client',
'Encrypting File System (EFS)',
'Extensible Authentication Protocol',
'Family Safety',
'Fax',
'File History Service',
'Function Discovery Provider Host',
'Function Discovery Resource Publication',
'Group Policy Client',
'Health Key and Certificate Management',
'HomeGroup Provider',
'Human Interface Device Access',
'Hyper-V Data Exchange Service',
'Hyper-V Guest Shutdown Service',
'Hyper-V Heartbeat Service',
'Hyper-V Remote Desktop Virtualization Service',
'Hyper-V Time Synchronization Service',
'Hyper-V Volume Shadow Copy Requestor',
'IKE and AuthIP IPsec Keying Modules',
'Interactive Services Detection',
'Internet Connection Sharing (ICS)',
'IP Helper',
'IPsec Policy Agent',
'KtmRm for Distributed Transaction Coordinator',
'Link-Layer Topology Discovery Mapper',
'Local Session Manager',
'Microsoft Account Sign-in Assistant',
'Microsoft iSCSI Initiator Service',
'Microsoft Software Shadow Copy Provider',
'Multimedia Class Scheduler',
'Net.Tcp Port Sharing Service',
'Netlogon',
'Network Access Protection Agent',
'Network Connected Devices Auto-Setup',
'Network Connections',
'Network Connectivity Assistant',
'Network List Service',
'Network Location Awareness',
'Network Store Interface Service',
'Offline Files',
'Optimize drives',
'Peer Name Resolution Protocol',
'Peer Networking Grouping',
'Peer Networking Identity Manager',
'Performance Counter DLL Host',
'Performance Logs & Alerts',
'Plug and Play',
'PNRP Machine Name Publication Service',
'Portable Device Enumerator Service',
'Power',
'Print Spooler',
'Printer Extensions and Notifications',
'Problem Reports and Solutions Control Panel Support',
'Program Compatibility Assistant Service',
'Quality Windows Audio Video Experience',
'Remote Access Auto Connection Manager',
'Remote Access Connection Manager',
'Remote Desktop Configuration',
'Remote Desktop Services',
'Remote Desktop Services UserMode Port Redirector',
'Remote Procedure Call (RPC)',
'Remote Procedure Call (RPC) Locator',
'Remote Registry',
'Routing and Remote Access',
'RPC Endpoint Mapper',
'Secondary Logon',
'Secure Socket Tunneling Protocol Service',
'Security Accounts Manager',
'Security Center',
'Sensor Monitoring Service',
'Server',
'Shell Hardware Detection',
'Smart Card',
'Smart Card Removal Policy',
'SNMP Trap',
'Software Protection',
'Spot Verifier',
'SSDP Discovery',
'Still Image Acquisition Events',
'Storage Service',
'Superfetch',
'System Event Notification Service',
'System Events Broker',
'Task Scheduler',
'TCP/IP NetBIOS Helper',
'Telephony',
'Themes',
'Thread Ordering Server',
'Time Broker',
'Touch Keyboard and Handwriting Panel Service',
'UPnP Device Host',
'User Profile Service',
'Virtual Disk',
'Volume Shadow Copy',
'WebClient',
'Windows All-User Install Agent',
'Windows Audio',
'Windows Audio Endpoint Builder',
'Windows Backup',
'Windows Biometric Service',
'Windows Color System',
'Windows Connect Now - Config Registrar',
'Windows Connection Manager',
'Windows Defender Service',
'Windows Driver Foundation - User-mode Driver Framework',
'Windows Error Reporting Service',
'Windows Event Collector',
'Windows Event Log',
'Windows Firewall',
'Windows Font Cache Service',
'Windows Image Acquisition (WIA)',
'Windows Installer',
'Windows Licensing Monitoring Service',
'Windows Management Instrumentation',
'Windows Media Player Network Sharing Service',
'Windows Modules Installer',