-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMulti-Module.psm1
2547 lines (2054 loc) · 94.6 KB
/
Multi-Module.psm1
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
#Requires -Version 5.0
<#=========Multi-Module.psm1===========
Original Creator:
JBrummans
Description:
Collection of functions for use within a Windows Enviroment. Module contains custom and sourced code.
See README for details
#>
Function Get-MMInfo {
<#
.SYNOPSIS
Searches Multi-Module for functions and displays the name and synopsis of each.
#>
Process{
$Name = (get-command -Module Multi-Module).name
$Array = @()
Foreach($n in $Name){
$Synopsis = (get-help $n | Select-object synopsis).synopsis
$Array += [PSCustomObject]@{
Name = $n
Synopsis = $Synopsis
}
}
Return $Array
}
}
Function Show-MMPercentage {
<#
.SYNOPSIS
Function that accepts a value between 0-100 and displays as a simple bar chart.
.EXAMPLE
Show-Percentage 40 200
Passes two parameters to the function. The first is the smaller value. The second is the total/max value. The function will calculate the percentage of 40 out of 200 and graph the result.
.EXAMPLE
Show-Percentage 50
Passes a single parameter. The function assumes this value is between 1-100 and will graph it out of 100.
#>
[cmdletbinding()]
param([long]$a, [long]$b=100)
Process{
If($b -ge $a){
$amount = $a/$b*100/5
$Used = "#"*($Amount)
$Unused = " "*(20-$Amount)
$graph = '['+$Used+$Unused+']'
}Else{
$graph = '[ GRAPHING ERROR ]'
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message "Invalid paramaters. Total value is less then provided." -Severity "Error"
}
Return $graph
}
}
Function Get-MMStats {
<#
.SYNOPSIS
Displays computer resource stats.
.DESCRIPTION
Displays computer resource stats. Refreshes every few seconds. Loops until user terminates function manually.
#>
#Get total ram in system
$TotalRam = (Get-Ciminstance Win32_OperatingSystem).TotalVisibleMemorySize
$a = 0
#Set arrays
$CPUarr = @()
$RAMarr = @()
$HDDarr = @()
While($a -eq 0) {
#Get CPU usage
$CPUCurrent = (Get-WmiObject win32_processor).LoadPercentage
$CPUarr += $CPUCurrent
$CPUavg = [math]::round((($CPUarr | Measure-Object -Average).average),2)
#Get Ram usage
$FreeRam = (Get-Ciminstance Win32_OperatingSystem).FreePhysicalMemory
$RamPercFree = [math]::Round(($FreeRam/$totalRam)*100,0)
$RamPercUsed = 100-$RamPercFree
$RAMArr += $RamPercUsed
$RAMAvg = [math]::round((($RAMArr | Measure-Object -Average).average),2)
#Get hdd utilisation
$HddPerc = (Get-WMIObject -Class "Win32_PerfFormattedData_PerfDisk_PhysicalDisk" -Filter 'Name = "_Total"').PercentDiskTime
$HDDarr += $HddPerc
$HDDAvg = [math]::round((($HDDarr | Measure-Object -Average).average),2)
#Get list of top 10 processes
$TopProcess = Get-MMTopProcess 10
$CPUgraph = Show-MMPercentage $CPUCurrent
$RAMgraph = Show-MMPercentage $RamPercUsed
$HDDgraph = Show-MMPercentage $HddPerc
Clear-Host
Write-host CPU Util: $CPUCurrent '%'
$CPUgraph
Write-Host CPU Avg: $CPUAvg
Write-Host ""
Write-host RAM Util: $RamPercUsed '%'
$RAMgraph
Write-host RAM Avg: $RAMAvg
Write-Host ""
Write-Host HDD Util: $HddPerc '%'
$HDDgraph
Write-host HDD Avg: $HDDAvg
$TopProcess
}
}
Function Get-MMTopProcess {
<#
.SYNOPSIS
Lists the top processes ordered by CPU utilisation. Limits to paramater passed.
#>
[cmdletbinding()]
param([int]$Top=10)
$TopProcess = (Get-Process | Sort-Object CPU -desc | Select-Object -first $top | Format-Table ProcessName, ID, CPU)
Return $TopProcess
}
Function Get-MMTVID {
<#
.SYNOPSIS
Checks registry of remote computer and returns the TeamViewer ID number.
.LINK
https://community.spiceworks.com/scripts/show/3990-retrieve-teamviewer-client-id-via-powershell
.EXAMPLE
Get-MMTVID -Hostname COMPUTERNAME
Finds the TV ID of a remote computer by its name and displays it.
.EXAMPLE
Get-MMTVID -Hostname 192.168.0.1 -Copy
Finds the TV ID of a remote computer by its IP, displays it and copies it to clipboard.
.EXAMPLE
Get-MMTVID -Hostname COMPUTERNAME -AutoConnect
Finds the TV ID of a remote computer by its name, displays it and attempts to open Teamviewer and connect to said ID.
#>
param(
[string] $Hostname,
[switch] $Copy,
[switch] $AutoConnect
)
#If no hostname provided, assume local computer
If (!$Hostname){
$Hostname = $env:COMPUTERNAME
}
#Start Remote Registry Service
If ($Hostname -ne $env:COMPUTERNAME){
$Service = Get-Service -Name "Remote Registry" -ComputerName $Hostname
$Service.Start()
}
#Suppresses errors (comment to disable error suppression)
$ErrorActionPreference = "SilentlyContinue"
#Attempts to pull clientID value from remote registry and display it if successful
$RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Hostname)
$RegKey= $RegCon.OpenSubKey("SOFTWARE\\WOW6432Node\\TeamViewer")
$ClientID = $RegKey.GetValue("clientID")
#Stop Remote Registry service
If ($Hostname -ne $env:COMPUTERNAME) {
$Service.Stop()
}
#Display results
Write-Host
If (!$clientid) {
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message "Unable to retrieve clientID value via remote registry" -Severity "Error" -Display
}Else{
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message "TeamViewer client ID for $Hostname is $Clientid" -Severity "Information" -Display
#Copy to clipboard
If ($copy){
$ClientID | clip
}
If($AutoConnect){
$TV86 = Test-Path "C:\Program Files (x86)\TeamViewer\TeamViewer.exe"
$TV64 = Test-Path "C:\Program Files\TeamViewer\TeamViewer.exe"
If($TV86){
$TVLocation = "C:\Program Files (x86)\TeamViewer\TeamViewer.exe"
& $TVLocation -i $ClientID
} Elseif($TV64){
$TVLocation = "C:\Program Files\TeamViewer\TeamViewer.exe"
& $TVLocation -i $ClientID
} Else {
#Write-Host "Error: Teamviewer was not located on this computer" -ForegroundColor Red
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message "Teamviewer was not located on this computer" -Severity "Error" -Display
}
}
}
Write-Host
}
Function Unlock-MMUser {
<#
.SYNOPSIS
Checks if the user is locked in AD. If yes, unlock.
.DESCRIPTION
Checks if the user is locked in AD. If yes, unlock. Accepts "-r" as a switch to loop until manually closed.
.NOTES
Requires AD Module
.EXAMPLE
Unlock-MMUser jsmith
Checks jsmith for lockouts and unlocks if locked.
.EXAMPLE
Unlock-MMUser jsmith -r
Checks jsmith for lockouts and unlocks if locked. Checks every 15 seconds until closed.
#>
[cmdletbinding()]
param ([String]$user,[switch]$repeat)
process {
$a = 0
do {
Write-Host "Checking..." -ForegroundColor Yellow
$Userinfo = Get-ADUser -Filter * -Properties LockedOut |
Where-Object { $_.SAMAccountName -like "*$user*" } |
Select-Object -Property SamAccountName, DistinguishedName, LockedOut #| Out-GridView -PassThru
$lockstatus = $Userinfo.lockedout
if ($lockstatus -eq "True") {
$date = Get-MMTimeStamp
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message "Account locked (Date:" $Date")" -Severity "Information" -Display
Write-Host "Unlocking Account"
Try{
Unlock-ADAccount $Userinfo.SamAccountName
}Catch{
Write-Host "An Error has occured. What a bummer... Is AD module installed and do you have access to AD?" -ForegroundColor red
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message $_.Exception.Message -Severity "Error" -Display
}
} Else {
Write-Host -f Green "Account is Not Locked out"
}
If($repeat -eq $true){
Write-Host "Waiting..." -ForegroundColor Yellow
start-sleep 15
}Else{
$a = 1
}
} until ($a -eq 1)
}
}
Function Get-MMHostList {
<#
.SYNOPSIS
Searches the domain for Hyper V hosts and returns a list.
.NOTES
Requires AD module.
.LINK
https://techibee.com/powershell/find-list-of-hyper-v-servers-in-domain-using-powershell/2100
#>
[cmdletbinding()]
param()
Try {
Import-Module ActiveDirectory -ErrorAction Stop
} Catch {
Write-Warning "Failed to import Active Directory module. Exiting"
Return
}
Try {
$Hypervs = Get-ADObject -Filter 'ObjectClass -eq "serviceConnectionPoint" -and Name -eq "Microsoft Hyper-V"' -ErrorAction Stop
} Catch {
Write-Error "Failed to query active directory. More details : $_"
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message $_.Exception.Message -Severity "Error"
}
Return $Hypervs
}
Function Get-MMHOSTS {
<#
.SYNOPSIS
Searches the domain for Hyper V hosts and displays a list.
.NOTES
Requires AD module.
.LINK
https://techibee.com/powershell/find-list-of-hyper-v-servers-in-domain-using-powershell/2100
#>
[cmdletbinding()]
param()
$Hypervs = Get-MMHostList
foreach($Hyperv in $Hypervs) {
$temp = $Hyperv.DistinguishedName.split(",")
$HypervDN = $temp[1..$temp.Count] -join ","
$Comp = Get-ADComputer -Id $HypervDN -Prop *
$OutputObj = New-Object PSObject -Prop (
@{
HyperVName = $Comp.Name
OSVersion = $($comp.operatingSystem)
})
$OutputObj
}
}
Function Get-MMVMS {
<#
.SYNOPSIS
Searches AD for hosts and their VMs. Displays list of VMs grouped by host.
.LINK
https://techibee.com/powershell/find-list-of-hyper-v-servers-in-domain-using-powershell/2100
.EXAMPLE
Get-MMVMS
Lists all hosts and their VM's.
#>
[cmdletbinding()]
param()
$Credential = Get-Credential
$Hypervs = Get-MMHostList
foreach($Hyperv in $Hypervs) {
$temp = $Hyperv.DistinguishedName.split(",")
$HypervDN = $temp[1..$temp.Count] -join ","
$Comp = Get-ADComputer -Id $HypervDN -Prop *
$OutputObj = New-Object PSObject -Prop (
@{
HyperVName = $Comp.Name
OSVersion = $($comp.operatingSystem)
}
)
foreach($hyperVName in $OutputObj){
Write-Host "HostName:" $OutputObj.HyperVName -ForegroundColor Yellow
Invoke-Command -ComputerName $OutputObj.HyperVName -ScriptBlock {Get-VM | Select-Object VMName, Uptime} -Credential $Credential
}
}
}
Function Export-MMSineList {
<#
.SYNOPSIS
Exports a csv file with a list of users, names, numbers etc required for updating sine. Some modification is still required.
.NOTES
Requires AD module.
.EXAMPLE
Export-MMSineList
Exports a CSV file to C:\Temp.
#>
Write-Host "Exporting list to C:\temp\ADExport.csv"
Get-ADUser -Filter * -Properties EmailAddress, givenName, sn, Mobile | Select-Object EmailAddress, givenName, sn, Mobile | Export-CSV "C:\temp\ADExport.csv"
}
Function Get-MMMulti-Info {
<#
.SYNOPSIS
DEPRECATED. Replacement Get-MMSystemInfo. Searches computer for mulitple peices of infomation which may be helpful when diag issues. Displays info as a list.
.NOTES
Created by Jbrummans
This Function was initially created when I first started learning powershell. It has been replaced by Get-MMSystemInfo. Keeping it here for nostalgia reasons only.
Several sources are referenced thoughout the script.
Old Notes Below:
To do: display last boot. Format and clean code.
Date Modified: 26/06/2018 Replaced percentage with Show-MMPercentage function. Added Logon Server and OU
Date Modified: 31/12/2016 Added Domain/workgroup
Date Modified: 29/12/2016 Added DNS, GPU and Resolution, some formatting, fixed gatewayIP, Commented out Public IP for now.
Date modified: 15/02/2016 Initial creation
#>
write-host =============================================
write-host =+=+=+=+=+=+=+= -NoNewLine
Write-Host "Multi-Info Tool DEPRECATED. Use Get-MMSystemInfo instead." -ForegroundColor Red -NoNewLine
Write-Host =+=+=+=+=+=+=+=
write-host =================== -NoNewLine
Write-Host "V0.6" -NoNewLine -ForegroundColor Yellow
Write-Host ======================
Write-Host
#Write-Host -NoNewLine "`r0% complete" #Progress meter
Show-MMPercentage 0
#==============General Computer details=================
$PcManu = (Get-WmiObject -Class Win32_ComputerSystem).Manufacturer
$Model = (Get-WmiObject -Class Win32_ComputerSystem).Model
$PcName = (Get-WmiObject -Class Win32_ComputerSystem).Name #alternative $env:COMPUTERNAME
$Primary = (Get-WmiObject -Class Win32_ComputerSystem).PrimaryOwnerName
$Memory = (Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory/1000/1000
$Memory = [System.Math]::Round($Memory)
Show-MMPercentage 10
#=============HDD space/capacity=====================
#http://stackoverflow.com/questions/12159341/how-to-get-disk-capacity-and-free-space-of-remote-computer
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName localhost -Filter "DeviceID='C:'" |
Select-Object Size,FreeSpace
$ds = [math]::round($disk.Size/1000/1000/1000, 2)
$fs = [math]::round($disk.FreeSpace/1000/1000/1000, 2)
Show-MMPercentage 20
#=============CPU details=====================
$CpuManu = Get-WmiObject -Class Win32_Processor | Select-Object -Property [a-z]* -expand Manufacturer
$CpuName = Get-WmiObject -Class Win32_Processor | Select-Object -Property [a-z]* -expand Name
$CpuCore = Get-WmiObject -Class Win32_Processor | Select-Object -Property [a-z]* -expand NumberOfCores
$CpuThread = Get-WmiObject -Class Win32_Processor | Select-Object -Property [a-z]* -expand NumberOflogicalProcessors
Show-MMPercentage 30
#==============OS Version==================
#http://stackoverflow.com/questions/27316104/how-to-get-os-name-in-windows-powershell-using-functions
$OS = (Get-WmiObject Win32_OperatingSystem).Name
Show-MMPercentage 40
#==============local IP address================
#http://powershell.com/cs/blogs/tips/archive/2015/04/22/get-current-ip-address.aspx
$ipaddress = [System.Net.DNS]::GetHostByName($null)
foreach($ip in $ipaddress.AddressList){
if ($ip.AddressFamily -eq 'InterNetwork'){
$lip = $ip.IPAddressToString
}
}
#=============DNS=================
$DNS1,$DNS2 = (Get-WMIObject -Class "Win32_NetworkAdapterConfiguration" -Filter "IPEnabled=TRUE").DNSServerSearchOrder #Get DNS Servers
#=============Default Gateway and DHCP===============
$Gate = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | select-object DefaultIPGateway -expand DefaultIPGateway
$IPstat = Get-NetIPAddress -AddressFamily IPv4 -PrefixLength 24 | Select-Object -expand PrefixOrigin #DHCP or STATIC
Show-MMPercentage 70
#==============Public IP address================
#http://tfl09.blogspot.com.au/2008/07/finding-your-external-ip-address-with.html
$wc=New-Object net.webclient
$pip = $wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"
Show-MMPercentage 80
#=============TimeZone/Date/Time===================
$timezone =(Get-TimeZone).displayname # Get Timezone
$date = Get-MMTimeStamp
$ntp = w32tm /query /source #Get Time Server
$CheckDomain = (Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain #Checks if computer is a member of a domain
If($CheckDomain -eq 'True'){
$domain = (Get-WmiObject -Class Win32_ComputerSystem).Domain
$logonserver = $Env:LOGONSERVER
$filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))" #https://stackoverflow.com/questions/11146264/get-current-computers-distinguished-name-in-powershell-without-using-the-active
$OU = ([adsisearcher]$filter).FindOne().Properties.distinguishedname
} Else {
$workgroup = (Get-WmiObject -Class Win32_ComputerSystem).Domain
}
#==================GPU====================
#This will not work well with multiple cards as it will overwrite the variable.
#https://community.spiceworks.com/topic/1543645-powershell-get-wmiobject-win32_videocontroller-multiple-graphics-cards
foreach($gpu in Get-WmiObject Win32_VideoController){
$graphics = $gpu.SYNOPSIS
}
$ResH = (Get-WmiObject win32_videocontroller).CurrentHorizontalResolution
$ResV = (Get-WmiObject win32_videocontroller).CurrentVerticalResolution
<#Requires elevation. Commenting out for now
#Driver Checks for AMD and Nvidia
#AMD
$ati = Get-WindowsDriver -online | Where Providername -like *ati*
$amd = Get-WindowsDriver -online | Where Providername -like *amd*
#Nvidia
$nvidia = Get-WindowsDriver -online | Where Providername -like *intel*
#>
#Write-Host -NoNewLine "`r60% complete"
Show-MMPercentage 100
Start-Sleep -s 1
write-host "`r==============================================="
write-host "SCAN COMPLETE" -ForegroundColor Yellow
write-host "==============================================="
write-host
Write-Host ""
Write-Host "============"
Write-Host "System Info" -ForegroundColor Yellow
Write-Host "============"
Write-Host "Computer name:" $PcName
Write-Host "OS Version:" $OS
If($CheckDomain -eq 'True'){
Write-host "Domain Name:" $domain
Write-host "Logon Server:" $logonserver
Write-host "Current Computer OU:" $OU
} Else {
Write-Host "WorkGroup Name:" $workgroup
}
#Write-Host "Domain or Workgroup:" $Domain
Write-Host "Computer Manufacturer:" $PcManu
Write-Host "Computer Model:" $Model
Write-Host "Primary User of Machine:" $Primary
write-host "Hard disk:" $fs "GB Free of "$ds "GB"
Write-Host "Total Memory:" $Memory " MB"
Write-Host "TimeZone:" $timezone
Write-Host "System Time/Date:" $Date
Write-Host "NTP Time Server: " $ntp
Write-Host ""
Write-Host "============"
Write-Host "Graphics Info" -ForegroundColor Yellow
Write-Host "============"
Write-Host "Graphics Processor: " -Nonewline
Write-Host $graphics -ForegroundColor Yellow
Write-Host "Resolution (HxV):" -Nonewline
Write-Host $ResH -NoNewLine -ForegroundColor Yellow
Write-Host " X" -Nonewline -ForegroundColor Yellow
Write-Host $ResV -ForegroundColor Yellow
<#
Write-Host "Software/Driver Checks:"
If($ati -eq $null){
Write-Host "No ATI Drivers found"
}Else{
Write-Host "ATI drivers Found"
}
If($amd -eq $null){
Write-Host "No AMD Drivers found"
}Else{
Write-Host "AMD drivers Found"
}
If($nvidia -eq $null){
Write-Host "No Nvidia Drivers found"
}Else{
Write-Host "Nvidia drivers Found"
}
#>
Write-Host ""
Write-Host "============"
Write-Host "Network Info" -ForegroundColor Yellow
Write-Host "============"
Write-Host "Local IP Address:" $lip " (" $IPstat ")"
#Write-Host "Static or Dynamic IP:" $IPstat
write-host "Gateway Server:" $Gate
Write-Host "DNS Servers:" $DNS1"," $DNS2
write-host "Public IP address:" $pip
Write-Host ""
Write-Host "============"
Write-Host "Processor Info" -ForegroundColor Yellow
Write-Host "============"
Write-Host "Processor Brand:" $CpuManu
Write-Host "Processor Model:" $CpuName
Write-host "Processor Cores:" $CpuCore
Write-host "Processor Threads:" $CpuThread
#Pause script and wait for response
Write-Host
Write-Host "END OF PROGRAM"
Pause
}
Function Get-MMSystemInfo{
<#
.SYNOPSIS
Gether system inforamtion for local or remote computer.
.DESCRIPTION
Gather information such as the Computer Name, OS, Memory, Disk, CPU, and Network Info.
.NOTES
Modified version of the below link. Added more points of Info and reduced the number of queries. Should speed up remote computer queries.
Original Author: MosaicMK Software LLC
Email: [email protected]
Original Version: 2.0.2
.LINK
https://www.powershellgallery.com/packages/GetSystemInfo/2.0.2
.EXAMPLE
Get-MMSystemInfo
Returns info of local machine
.EXAMPLE
Get-MMSystemInfo -ComputerName COMPUTERNAME
Returns info of the remote machine
#>
param([string]$ComputerName = $env:computername)
$Computer = $ComputerName
#Gets computer info.
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer
$Domain = $ComputerInfo.Domain
$ComputerModel = $ComputerInfo.Model
$LoggedOnUser = $ComputerInfo.Username
#Get list of users who have logged in before.
$UserProfile = (Get-ChildItem \\$ComputerName\C$\users\).Name
#Gets the OS info.
$GetOS = Get-WmiObject -class Win32_OperatingSystem -computername $Computer
$OS = $GetOS.Caption
$OSArchitecture = $GetOS.OSArchitecture
$OSBuildNumber = $GetOS.BuildNumber
#Gets memory information.
$Getmemoryslot = Get-WmiObject Win32_PhysicalMemoryArray -ComputerName $computer
$Getmemorymeasure = Get-WMIObject Win32_PhysicalMemory -ComputerName $computer | Measure-Object -Property Capacity -Sum
$MemorySlot = $Getmemoryslot.MemoryDevices
$MaxMemory = $($Getmemoryslot.MaxCapacity/1024/1024)
$TotalMemSticks = $Getmemorymeasure.count
$TotalMemSize = $($Getmemorymeasure.sum/1024/1024/1024)
#Get the disk info.
$GetDiskInfo = Get-WmiObject Win32_logicaldisk -ComputerName $computer -Filter "DeviceID='C:'"
$DiskSize = $([math]::Round($GetDiskInfo.Size/1GB))
$FreeSpace = $([math]::Round($GetDiskInfo.FreeSpace/1GB))
$UsedSapce =$([math]::Round($DiskSize-$FreeSpace))
#Gets CPU info.
$GetCPU = Get-wmiobject win32_processor -ComputerName $Computer
$CPUName = $GetCPU.Name
$CPUManufacturer = $GetCPU.Manufacturer
$CPUMaxClockSpeed = $GetCPU.MaxClockSpeed
$CPUCores = $GetCPU.NumberOfCores
$CPULogical = $GetCPU.NumberOflogicalProcessors
#Get IP address.
$NetworkInfo = (Get-WmiObject win32_NetworkadapterConfiguration -ComputerName $Computer | Where-Object IPAddress -ne $null)
$IPAddress = $NetworkInfo.ipaddress
$DNS = $NetworkInfo.DNSServerSearchOrder
$Gateway = $NetworkInfo.DefaultIPGateway
#Determine DHCP enabled.
If($networks.DHCPEnabled) {
$IsDHCPEnabled = $true
} Else {
$IsDHCPEnabled = $false
}
#Resolve DNS server names.
$DNSServerNames = @()
ForEach($D in $DNS){
Try{
$DNSServerNames += [System.Net.Dns]::GetHostByAddress($D).Hostname
}Catch{
$DNSServerNames += "NA"
}
}
#Gets BIOS info.
$GetBios = Get-WmiObject win32_bios -ComputerName $Computer
$BIOSName = $GetBios.Name
$BIOSManufacturer = $GetBios.Manufacturer
$BIOSVersion = $GetBios.Version
$SerialNumber = $GetBios.SerialNumber
#Gets Motherboard info.
$GetMotherboard = Get-WmiObject Win32_BaseBoard -ComputerName $Computer
$MotherBoardName = $GetMotherboard.Name
$MotherBoardManufacturet = $GetMotherboard.Manufacturer
$MotherBoardModel = $GetMotherboard.Model
$MotherBoardProduct = $GetMotherboard.Product
$MotherBoardSerial = $GetMotherboard.SerialNumber
#Gets GPU info.
$GetGPU = Get-WmiObject Win32_VideoController
$GPUDevice = $GetGPU.name
$ResH = $GetGPU.CurrentHorizontalResolution
$ResV = $GetGPU.CurrentVerticalResolution
#Gets system last boot and uptime.
$Uptime, $LastBoot = Get-MMUptime -ComputerName $ComputerName
#Define the object to hold the info.
$ComputerInfo = New-Object -TypeName psobject
#Add the items to the object.
$ComputerInfo | Add-Member -MemberType NoteProperty -Name ComputerName -Value $ComputerName
$ComputerInfo | Add-Member -MemberType NoteProperty -Name ComputerModel -Value $ComputerModel
$ComputerInfo | Add-Member -MemberType NoteProperty -Name SerialNumber -Value $SerialNumber
$ComputerInfo | Add-Member -MemberType NoteProperty -Name DomainName -Value $Domain
$ComputerInfo | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $os
$ComputerInfo | Add-Member -MemberType NoteProperty -Name OSArchitecture -Value $OSArchitecture
$ComputerInfo | Add-Member -MemberType NoteProperty -Name OSBuild -Value $OSBuildNumber
$ComputerInfo | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
$ComputerInfo | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNS
$ComputerInfo | Add-Member -MemberType NoteProperty -Name Gateway -Value $Gateway
$ComputerInfo | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled
$ComputerInfo | Add-Member -MemberType NoteProperty -Name DNSServerNames -Value $DNSServerNames
$ComputerInfo | Add-Member -MemberType NoteProperty -Name LoggedInUsers -Value $LoggedOnUser
$ComputerInfo | Add-Member -MemberType NoteProperty -Name UserProfile -Value $UserProfile
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MemorySlots -Value $MemorySlot
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MaxMemory -Value "$MaxMemory GB"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MemorySlotsUsed -Value $TotalMemSticks
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MemoryInstalled -Value "$TotalMemSize GB"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name SystemDrive -Value $ENV:SystemDrive
$ComputerInfo | Add-Member -MemberType NoteProperty -Name DiskSize -Value "$DiskSize GB"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name FreeSpace -Value "$FreeSpace GB"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name UsedSpace -Value "$UsedSapce GB"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPU -Value $CPUName
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPUManufacturer -Value $CPUManufacturer
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPUMaxClockSpeed -Value $CPUMaxClockSpeed
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPUCores -Value $CPUCores
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPULogical -Value $CPULogical
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoard -Value $MotherBoardName
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardManufacturer -Value $MotherBoardManufacturet
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardModel -Value $MotherBoardModel
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardSerialNumber -Value $MotherBoardSerial
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardProduct -Value $MotherBoardProduct
$ComputerInfo | Add-Member -MemberType NoteProperty -Name BIOSName -Value $BIOSName
$ComputerInfo | Add-Member -MemberType NoteProperty -Name BIOSManufacturer -Value $BIOSManufacturer
$ComputerInfo | Add-Member -MemberType NoteProperty -Name BIOSVersion -Value $BIOSVersion
$ComputerInfo | Add-Member -MemberType NoteProperty -Name GPUDevice -Value $GPUDevice
$ComputerInfo | Add-Member -MemberType NoteProperty -Name HorizontalResolution -Value $ResH
$ComputerInfo | Add-Member -MemberType NoteProperty -Name VerticalResolution -Value $ResV
$ComputerInfo | Add-Member -MemberType NoteProperty -Name Uptime -Value $Uptime
$ComputerInfo | Add-Member -MemberType NoteProperty -Name LastBootTime -Value $LastBoot
Return $ComputerInfo
}
Function Get-MMExcuse {
<#
.SYNOPSIS
Are you out of excuses? Let powershell help you.
.LINK
https://github.com/SpacezCowboy/Scripts/blob/master/PowerShell/Profiles-Modules/Profiles/Microsoft.PowerShell_profile.ps1
#>
$ex = (Invoke-WebRequest http://pages.cs.wisc.edu/~ballard/bofh/excuses -OutVariable excuses).content.split([Environment]::NewLine)[(get-random $excuses.content.split([Environment]::NewLine).count)]
write-host "$ex" -Foregroundcolor Green
}
Function Set-MMCalanderPermission {
<#
.SYNOPSIS
Sets the calendar permission for a delegates access.
.DESCRIPTION
Sets the calendar permission for a delegates access. Accepts a Owner, Delegate and Access Level paramater. Creates a session with the local exchange to apply the setting.
.EXAMPLE
Set-MMCalanderPermission -o jbrummans -d jsmith -a reviewer
Sets jsmith to have access to JBrummans calendar as a reviewer
.EXAMPLE
Set-MMCalanderPermission
Calling the function without paramaters (or incomplete paramaters) will cause it to prompt for input.
#>
[cmdletbinding()]
param ([String]$Owner, [String]$Delegate, [String]$AccessLevel)
process {
Write-Host "Credentials are required to connect with Exchange:"
$Credential = Get-Credential #Store credentials to connect to exchange server with.
$Session = New-PSSession -ConfigurationName microsoft.exchange -ConnectionUri http://EXCHANGESERVERNAME/powershell/ -Authentication Kerberos -Credential $Credential
Import-PSSession -Session $Session -CommandName Get-MailboxFolderPermission, Add-MailboxFolderPermission, Set-MailboxFolderPermission #Start the session.
If ((-Not$Owner) -or (-Not$Delegate) -or (-not$AccessLevel)){
Write-host "Required information missing! Please enter Owner, Delegate and Access Level" -ForegroundColor Red
Write-host "(This can be skiped by passing Owner and Delegate usernames using -o, -d and -a paramaters respectively)" -ForegroundColor Yellow
$Owner = Read-Host "Owner Username"
$Delegate = Read-Host "Delegate Username"
Write-Host "Access Level must be typed correctly in full."
Write-Host "Examples: Editor (View, Create, Edit, Delete), Author (View, Create), Reviewer (View), AvailabilityOnly (Free/Busy Time)."
$AccessLevel = Read-Host "Access Level"
} Else {
#Nothing for now I guess
}
do {
Clear-Host
$CurrentLevel = (Get-MailboxFolderPermission -Identity ${Owner}:\Calendar -User $Delegate).Accessrights
Clear-Host
If(!$CurrentLevel){
Write-host "No Access Level currently set. Adding now" -ForegroundColor Green
Add-MailboxFolderPermission -Identity ${Owner}:\calendar -user $Delegate -AccessRights $AccessLevel
}Elseif($CurrentLevel){
Write-host "Access Level is currently" $CurrentLevel". Modifying now" -ForegroundColor Green
Set-MailboxFolderPermission -Identity ${Owner}:\calendar -user $Delegate -AccessRights $AccessLevel
}Else{
Write-Host "Woops... Something went wrong" -ForegroundColor Red
}
$NewLevel = (Get-MailboxFolderPermission -Identity ${Owner}:\Calendar -User $Delegate).Accessrights
Write-host $Delegate "is now a(n)" $NewLevel "of" $Owner -ForegroundColor Green
$loop = Read-Host "Another user delegation?: Y or N"
If($loop -eq "Y"){
Write-Host ""
$Owner = Read-Host "Owner Username:"
$Delegate = Read-Host "Delegate Username:"
Write-Host "Access Level must be typed correctly. Examples Editor (View, Create, Edit, Delete), Author (View, Create), Reviewer (View)."
$AccessLevel = Read-Host "Access Level:"
}
} until ($loop -eq "N")
Remove-PSSession $Session #Close the session.
}
}
Function Set-MMMailbox {
<#
.SYNOPSIS
Get mailbox size of user and prompt to change.
#>
[cmdletbinding()]
param ([String]$Username)
process {
$Session = Connect-MMExchange
Import-PSSession -Session $Session -AllowClobber -CommandName Get-MailboxFolderPermission, Add-MailboxFolderPermission, Set-MailboxFolderPermission, Get-Mailbox, Set-Mailbox #Start the session.
$CurrentSize = Get-Mailbox $Username | Format-List *Quota
Write-Host "Current Mailbox Size:"
Write-Host $CurrentSize
$Choice = Read-Host "Change Mailbox Quota? (Y or N)"
If($Choice -eq "Y" -or "y"){
$IssueWarning = Read-Host "Issue warning at what size (in GB. EG 19)"
$ProhibitSend = Read-Host "Prohibit Send/Rec at what size (in GB. EG 20)"
$IssueWarning = $IssueWarning+"GB"
$ProhibitSend = $ProhibitSend+"GB"
}Else{
Exit-MMFunction -Message1 "Exiting" -Colour1 "Red"
}
Set-Mailbox $USername -IssueWarningQuota $IssueWarning -ProhibitSendQuota $ProhibitSend `
-ProhibitSendReceiveQuota $ProhibitSend -UseDatabaseQuotaDefaults $false
$NewSize = Get-Mailbox $Username | Select-Object IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota | Format-List *Quota
Clear-Host
Write-Host "Previous Mailbox Size was:" -ForegroundColor Yellow
Write-Host $CurrentSize -ForegroundColor yellow
Write-Host "New Mailbox Size was:" -ForegroundColor Green
Write-Host $NewSize -ForegroundColor green
}
}
Function Connect-MMExchange{
<#
.SYNOPSIS
Establishes session to the exchange server.
#>
[CmdletBinding()]
Param ()
process {
Write-Host "Credentials are required to connect with Exchange:"
$Credential = Get-Credential #Store credentials to connect to exchange server with.
$Session = New-PSSession -ConfigurationName microsoft.exchange -ConnectionUri http://EXCHANGESERVERNAME/powershell/ -Authentication Kerberos -Credential $Credential
Return $Session
}
}
Function Get-MMCompMgmt {
<#
.SYNOPSIS
Opens remote computer management.
.LINK
https://github.com/SpacezCowboy/Scripts/blob/master/PowerShell/Profiles-Modules/Profiles/Microsoft.PowerShell_profile.ps1
.EXAMPLE
Get-MMCompMgmt -Computer PCNAME
Opens remote computer management to PCNAME
#>
[CmdletBinding()]
Param ([Parameter(Mandatory = $true)]$computer)
compmgmt.msc /computer:$computer
}
Function Get-MMPasswordExpiry{
<#
.SYNOPSIS
Searches Ad for a name or Username and returns password set date and expiry.
.DESCRIPTION
Searches Ad for a name or Username and returns password set date and expiry. Accepts either a Name (-N) or SAM (-S).
.EXAMPLE
Get-MMPasswordExpiry -Name john
Searches for users based on first name john
.EXAMPLE
Get-MMPasswordExpiry -SAM jsmith
Searches for users based on username jsmith
#>
[cmdletbinding()]
param ([String]$Name,[String]$SAM)
process {
If($Name){
$NameResults = Get-ADUser -filter ("name -like ""*$name*""") -properties passwordlastset, passwordneverexpires, LockedOut, SamAccountName | sort-object name | Format-Table SamAccountName, Name, passwordlastset, Passwordneverexpires, LockedOut
$NameResults
}Elseif($SAM){
Try{
$Exist = $(try {Get-ADUser $SAM} Catch {$null})
If ($Null -ne $Exist){
Write-Host
Write-Host "User found in AD" -ForegroundColor Green
Write-Host
$SAMResults = Get-ADUser -identity $SAM -properties passwordlastset, passwordneverexpires, LockedOut, SamAccountName | sort-object name | Format-Table SamAccountName, Name, passwordlastset, Passwordneverexpires, LockedOut
$SAMResults
} Else {
Write-Host
Write-Host "User does not exist in AD" -ForegroundColor Red
Write-Host
}
}Catch{
Write-Host "An Error has occured while searching for that username. Please check the username and try again." -ForegroundColor Red
Write-MMLog -Function ($MyInvocation.MyCommand).Name -Message $_.Exception.Message -Severity "Error"
}
}Else{
Write-host "No valid input"
}
}
}