wbMSPmodule.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

<#PSScriptInfo
 
.VERSION 1.3
 
.GUID 52945996-1255-4333-8f09-c5e2bca3b715
 
.AUTHOR WadeBach22
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 The updated MSP module from Wade Bachelder
 
#>
 
Param()


function wbMSPfireWallOn {
    NetSh Advfirewall set allprofiles state on;
}

function wbMSPfireWallOff {
    NetSh Advfirewall set allprofiles state off;
}
function wbMSPsetPowerState {
    Powercfg.exe /h off;
    Powercfg /x -disk-timeout-ac 0;
    Powercfg /x -disk-timeout-dc 0;
    Powercfg /x -monitor-timeout-ac 30;
    Powercfg /x -monitor-timeout-dc 30;
    Powercfg /x -standby-timeout-ac 0;
    Powercfg /x -standby-timeout-dc 0;
    Powercfg /x -hibernate-timeout-ac 0;
    Powercfg /x -hibernate-timeout-dc 0;    
}
function wbMSPshowMemoryProcesses {
    Get-Process | Sort-Object -Descending WS   
}

function wbMSPsetLaptopPower {
    Powercfg -setacvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0;
    Powercfg -setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
}

function wbMSPsetRegistry {
   Try{New-ItemProperty -ErrorAction Stop -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -PropertyType DWORD -Name 'EnableLinkedConnections' -Value 1;}
    Catch{Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name 'EnableLinkedConnections' -Value 1;}
    Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -name "fDenyTSConnections" -value 0;
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Open Find\" -Force | Out-Null;
    Try{New-ItemProperty -ErrorAction Stop -Path "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Open Find\" -PropertyType DWORD -Name 'EnableShellDataCaching' -Value 1;}
    Catch{Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Open Find\" -Name 'EnableShellDataCaching' -Value 1;}
}

function wbMSPcheckHDHealth {
    Get-PhysicalDisk;
}

function wbMSPoptimizeHD {
    Optimize-Volume -DriveLetter C -Defrag -Verbose;
}

function wbMSPrepairHD {
    Repair-Volume -DriveLetter C -OfflineScanAndFix;
}

function wbMSPsophosUpdateScan {
    $process = Get-Process -Id $pid;
    $process.PriorityClass = 'BelowNormal';
    $sophos = New-Object -ComObject "activelinkclient.clientupdate.1"
    $sophos.updatenow($true,1)
    $Sophos = "C:\Program Files (x86)\Sophos\Sophos Anti-Virus\sav32cli.exe"
    $Arguments = "-remove"
    Start-Process $Sophos -ArgumentList $Arguments -NoNewWindow -Wait
}

function wbMSPwindowsStabilityIndex {
    Get-Ciminstance Win32_ReliabilityStabilityMetrics | Measure-Object -Average -Maximum  -Minimum -Property systemStabilityIndex
}

function wbMSPwindowsCounters {
    Get-Counter;
}

function wbMSPlistTop10Files {
    $process = Get-Process -Id $pid;
    $process.PriorityClass = 'BelowNormal';
    Get-ChildItem c:\ -r| sort -descending -property length | select -first 10 name, Length
}

function wbMSPnetworkDiscoveryOn {
    Netsh advfirewall firewall set rule group="Network Discovery" new enable=Yes;
}

function wbMSPfileDiscoveryOn {
    Netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes;
}

function wbMSPrenameWorkstation {
    $NewSerialNumber = (gwmi win32_bios).SerialNumber;
    Rename-computer -NewName $NewSerialNumber -force;
}

function wbMSPGeneralDiskCleanUp {
    Get-ChildItem "C:\Windows\SoftwareDistribution\*" -Recurse -Force -verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows\prefetch\*" -Recurse -Force -verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Temp\*" -Recurse -Force -verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Recurse -Force -verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows\system32\wbem\Logs\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows\system32\Logfiles\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows\Debug\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows\Downloaded Program Files\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows\LiveKernelReports\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Word\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Roaming\Microsoft\Internet Explorer\UserData\Low\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\WER\ERC\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\INetCache\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Users\*\AppData\Local\Google\Chrome\User Data\Default\Cache\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows.old\*" -Recurse -Force -verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem "C:\Windows10Upgrade\*" -Recurse -Force -verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue;
    Get-ChildItem 'C:\$Recycle.Bin\*' -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    get-psdrive -psprovider filesystem;
}

function wbMSPPackageCleanUp {
    Get-ChildItem "C:\Users\*\AppData\Local\Packages\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    get-psdrive -psprovider filesystem;
}
function wbMSPTEAMSCleanUp {
    Get-ChildItem "C:\Users\*\AppData\Roaming\Microsoft\Teams\*" -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue;
    get-psdrive -psprovider filesystem;
}