Commit this day work
This commit is contained in:
parent
f897ca973c
commit
b221e5db4d
13 changed files with 370 additions and 60 deletions
250
cleanW10.ps1
250
cleanW10.ps1
|
@ -76,7 +76,7 @@ function FwBlockOutputIP {
|
|||
}
|
||||
}
|
||||
|
||||
function remove_shitty_tasks () {
|
||||
function DisablesheduledTask () {
|
||||
param($taskList)
|
||||
Foreach ($task in $taskList){
|
||||
Write-Host -NoNewline "`t$task : "
|
||||
|
@ -98,14 +98,9 @@ function remove_shitty_tasks () {
|
|||
}
|
||||
}
|
||||
|
||||
# Modify a reg value
|
||||
# Params :
|
||||
# path : the complete path to reg key
|
||||
# key : key name
|
||||
# value : The value to write
|
||||
function AddRegKey {
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[Parameter(Mandatory=$true)]
|
||||
[object]$params
|
||||
)
|
||||
Write-Host -NoNewline "`t$($params.key) reg key to $($params.value) : "
|
||||
|
@ -114,7 +109,7 @@ function AddRegKey {
|
|||
}
|
||||
if ( -not $params.type ){ $params.type="DWORD" }
|
||||
if ( -not (Test-Path $params.path) ){
|
||||
Write-Host -NoNewline "- creating path -"
|
||||
Write-Host -NoNewline "- creating path - "
|
||||
New-Item -Path $params.path -Force | Out-Null
|
||||
}
|
||||
try {
|
||||
|
@ -132,59 +127,77 @@ function AddRegKey {
|
|||
Write-host -ForegroundColor Green "done"
|
||||
}
|
||||
|
||||
# Delete a reg key
|
||||
# Params :
|
||||
# path : the complete path to reg key
|
||||
# key : key name
|
||||
function delete_shitty_reg_key {
|
||||
param([string]$path, [string]$key)
|
||||
Write-Host -NoNewline "`tDelete key $key reg : "
|
||||
if (!(Test-Path $path)){
|
||||
Write-Host -ForegroundColor Red -NoNewline "path not found"
|
||||
function DelRegKey {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[object]$params
|
||||
)
|
||||
Write-Host -NoNewline "`tDelete registery key $($params.key) : "
|
||||
if ( ! (Test-Path $params.path) ){
|
||||
Write-Host -ForegroundColor Red " Error path not found"
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
Remove-ItemProperty -Path $path -Name $key
|
||||
}
|
||||
catch [System.Security.SecurityException]{
|
||||
Write-Host -ForegroundColor Red "access denied"
|
||||
Write-Host -ForegroundColor Red "Error in DelRegKey`n`t"
|
||||
Write-Host -ForegounndColor DarkRed "Access to $($params.path)\$($params.key) denied"
|
||||
return
|
||||
}
|
||||
catch {
|
||||
Write-Host -ForegroundColor Red "error"
|
||||
Write-Host "`t$Error[0]"
|
||||
Write-Host -ForegroundColor Red -NoNewLine "Error in DelRegKey`n`t"
|
||||
Write-Host -ForegounndColor DarkRed $Error[0].Exception.Message
|
||||
return
|
||||
}
|
||||
Write-host -ForegroundColor Green "done"
|
||||
}
|
||||
|
||||
# Function to remove shitty prog from shitty win
|
||||
# Params :
|
||||
# $name : Feature name
|
||||
function disable_shitty_feature {
|
||||
param ($name)
|
||||
Write-Host -NoNewline "`t$name : "
|
||||
$requestInstall = dism /online /Get-FeatureInfo /FeatureName:$name /English
|
||||
$isInstalled = $requestInstall | Select-String "state"
|
||||
If ($isInstalled -match "Enable") {
|
||||
function DisableFeature {
|
||||
param (
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='params'
|
||||
)]
|
||||
[Parameter(
|
||||
ValueFromPipeline=$False,
|
||||
ParameterSetName="params",
|
||||
Position = 0
|
||||
)]
|
||||
[object]$params,
|
||||
|
||||
[Parameter(
|
||||
ValueFromPipeline=$True,
|
||||
ParameterSetName="feature",
|
||||
Position = 0
|
||||
)]
|
||||
[Object]$feature
|
||||
)
|
||||
if ( $params.file ) {
|
||||
Get-Content $params.file | foreach {
|
||||
DisableFeature -feature $(dism /online /Get-FeatureInfo /FeatureName:$_ /English)
|
||||
}
|
||||
}
|
||||
elseif ( $params.name ) {
|
||||
$(dism /online /Get-FeatureInfo /FeatureName:$($params.name) /English) | DisableFeature
|
||||
}
|
||||
elseif ( $feature ) {
|
||||
try {
|
||||
$name = $feature | Select-String "Feature Name" | %{($_ -split " : ")[1]}
|
||||
Write-Host -NoNewline "`tDisable Feature $name : "
|
||||
if ( $($feature | Select-String "state") -match "Disable" ){
|
||||
Write-Host -ForegroundColor Yellow "already disable"
|
||||
return
|
||||
}
|
||||
Dism /online /Disable-Feature /FeatureName:$name /NoRestart | Out-Null
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
catch {
|
||||
Write-Host -ForegroundColor Red "error"
|
||||
Return
|
||||
}
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
else {
|
||||
Write-Host -ForegroundColor Yellow "already disable"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# remove unwanted "Modern App"
|
||||
# Params
|
||||
#
|
||||
function UninstallModernApp {
|
||||
param(
|
||||
[cmdletbinding(
|
||||
|
@ -270,29 +283,63 @@ function UninstallModernProvisonnedApp {
|
|||
}
|
||||
}
|
||||
|
||||
function disable_shitty_service {
|
||||
param([string]$name)
|
||||
Write-Host -NoNewline "`t$name : "
|
||||
$serv = Get-Service -name $name
|
||||
if ( !$serv) {
|
||||
Write-Host -ForegroundColor Red "not found"
|
||||
return
|
||||
function DisableService {
|
||||
param (
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='params'
|
||||
)]
|
||||
[Parameter(
|
||||
ValueFromPipeline=$False,
|
||||
ParameterSetName="params",
|
||||
Position = 0
|
||||
)]
|
||||
[object]$params,
|
||||
|
||||
[Parameter(
|
||||
ValueFromPipeline=$True,
|
||||
ParameterSetName="service"
|
||||
)]
|
||||
[Object]$service
|
||||
)
|
||||
if ( $params.file ) {
|
||||
Get-Service | Where-Object { $_.name -in $( Get-Content $params.file ) } | Foreach {
|
||||
$_ | DisableService
|
||||
}
|
||||
}
|
||||
if ( $serv.StartType -eq "Disable") {
|
||||
Write-Host -ForegroundColor Yellow "already disabled"
|
||||
elseif ( $params.name ) {
|
||||
DisableService-service $(Get-Service -name $params.name)
|
||||
}
|
||||
else {
|
||||
Stop-Service -InputObject $serv -PassThru | Set-Service -StartupType disabled
|
||||
Write-Host -ForegroundColor Green "done "
|
||||
elseif ( $service ) {
|
||||
try {
|
||||
Write-Host -NoNewline "`tDisable service $($service.name) : "
|
||||
if ( $service.StartType -eq "Disable") {
|
||||
Write-Host -ForegroundColor Yellow "already disabled"
|
||||
return
|
||||
}
|
||||
Stop-Service -InputObject $service -PassThru | Set-Service -StartupType disabled
|
||||
Write-Host -ForegroundColor Green "done "
|
||||
}
|
||||
catch {
|
||||
Write-Host -NoNewLine -ForegroundColor Red "`tError in DisableService`n`t"
|
||||
write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Kill a process
|
||||
# Param :
|
||||
# $process : name of process to kill (String)
|
||||
function kill_shitty_process {
|
||||
param([string]$process)
|
||||
Write-Host -NoNewLine "`tKilling $process : "
|
||||
function KillProcess {
|
||||
param(
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='params'
|
||||
)]
|
||||
[Parameter(
|
||||
ValueFromPipeline=$False,
|
||||
ParameterSetName="params",
|
||||
Position = 0
|
||||
)]
|
||||
[object]$params
|
||||
)
|
||||
Write-Host -NoNewLine "`tKilling $($params.name) : "
|
||||
try {
|
||||
$p = Get-Process $process
|
||||
Stop-Process $p | Out-Null
|
||||
|
@ -303,8 +350,91 @@ function kill_shitty_process {
|
|||
}
|
||||
}
|
||||
|
||||
Write-Output "`nI's time to kick ass and chew bubble gum"
|
||||
Write-Output "________________________________________`n"
|
||||
function DelFile {
|
||||
param (
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='params'
|
||||
)]
|
||||
[Parameter(
|
||||
ValueFromPipeline=$False,
|
||||
ParameterSetName="params",
|
||||
Position = 0
|
||||
)]
|
||||
[object]$params
|
||||
)
|
||||
$path = Invoke-Expression """$($params.path)"""
|
||||
Write-Host -NoNewline "`tDelete $path : "
|
||||
if ( -not (Test-Path $path) ){
|
||||
Write-Host -ForegroundColor Yellow "not found"
|
||||
return
|
||||
}
|
||||
$command = "Remove-Item $command -ErrorAction SilentlyContinue -Force -Path `"$path`""
|
||||
if ( $params.recurse -eq $true ) {
|
||||
$command += "-Recurse"
|
||||
}
|
||||
try {
|
||||
Invoke-Expression $command
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
catch {
|
||||
Write-Host -NoNewLine -ForegroundColor Red "`Error in DelFile`n`t"
|
||||
write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
function ExecCommand {
|
||||
param (
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='params'
|
||||
)]
|
||||
[Parameter(
|
||||
ValueFromPipeline=$False,
|
||||
ParameterSetName="params",
|
||||
Position = 0
|
||||
)]
|
||||
[object]$params
|
||||
)
|
||||
Write-Host -NoNewline "`tExecute : $($params.path) : "
|
||||
if ( -not (Test-Path $params.path) ) {
|
||||
Write-Host -ForegroundColor Yellow "File not found"
|
||||
return
|
||||
}
|
||||
try {
|
||||
Start-Process $params.path -ArgumentList $params.arguments
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
catch {
|
||||
Write-Host -NoNewLine -ForegroundColor Red "`Error in DelFile`n`t"
|
||||
write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Write-Output "`nIt's time to kick ass and chew bubble gum"
|
||||
Write-Output "_________________________________________`n"
|
||||
|
||||
try {
|
||||
Write-Host -NoNewline "Mount Default user registery hive : "
|
||||
reg load "hku\Default" "C:\Users\Default\NTUSER.DAT" | Out-Null
|
||||
New-PSDrive -PSProvider Registry -Root HKEY_USERS -Name HKU | Out-Null
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
catch {
|
||||
Write-Host -NoNewline -ForegroundColor Red "Error`n`t"
|
||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
exit 1
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Host -NoNewline "Mount HK_CLASSES_ROOT registery hive : "
|
||||
New-PSDrive -PSProvider Registry -Root HKEY_CLASSES_ROOT -Name HKCR | Out-Null
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
catch {
|
||||
Write-Host -NoNewline -ForegroundColor Red "Error`n`t"
|
||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
exit 1
|
||||
}
|
||||
|
||||
Get-ChildItem -Path $PSScriptRoot"\modules.d" -Filter "*.conf" | foreach {
|
||||
$module = ""
|
||||
|
@ -315,7 +445,7 @@ Get-ChildItem -Path $PSScriptRoot"\modules.d" -Filter "*.conf" | foreach {
|
|||
$module.actions | Foreach {
|
||||
$action_file = ""
|
||||
$current_action = $_
|
||||
# If action content a file element, nedd to test if file exist
|
||||
# If action content a file element, need to test if file exist
|
||||
if ( $_.file) {
|
||||
$action_file = $module_dir + $_.file
|
||||
if ( -not (Test-Path $action_file) ) {
|
||||
|
@ -325,6 +455,6 @@ Get-ChildItem -Path $PSScriptRoot"\modules.d" -Filter "*.conf" | foreach {
|
|||
$_.file = $action_file
|
||||
}
|
||||
# Invoke function
|
||||
Invoke-Expression "$($_.action) -params `$_"
|
||||
Invoke-Expression "$($_.action) `$_"
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue