Experimental.psm1 5.08 KB
Newer Older
1 2
################################################################
# Project CNRS RESINFO SWMB
Gabriel Moreau's avatar
Gabriel Moreau committed
3
# Copyright (C) 2020-2022, CNRS, France
4 5 6 7 8 9 10 11 12 13 14
# License: MIT License (Same as project Win10-Initial-Setup-Script)
# Homepage: https://gitlab.in2p3.fr/resinfo-gt/swmb/resinfo-swmb
# Authors:
#  2020 - Olivier de Marchi (Grenoble INP / LEGI)
#  2020 - David Gras (CNRS / DR11)
#  2020 - Clément Deiber (CNRS / DR11)
#  2020 - Gabriel Moreau (CNRS / LEGI)
################################################################

################################################################

Gabriel Moreau's avatar
Gabriel Moreau committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
################################################################

# ClearPageFileAtShutdown
# https://deployadmin.com/2019/11/03/vider-le-fichier-dechange-a-chaque-arret-de-windows/
# Enable
Function TweakEnableClearPageFile { # RESINFO
	Write-Output "Clear PageFile.sys at shutdown..."
	Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name "ClearPageFileAtShutdown" -Type DWord -Value 1
}

# Disable
Function TweakDisableClearPageFile { # RESINFO
	Write-Output "Do not reset PageFile.sys at shutdown..."
	Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name "ClearPageFileAtShutdown" -Type DWord -Value 0
}

# View
Function TweakViewClearPageFile { # RESINFO
	Write-Output 'Clear PageFile.sys (0 nothing enable, 1 clear at shutdown)'
	$KeyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
	Get-ItemProperty -Path $KeyPath -Name "ClearPageFileAtShutdown"
}

38 39 40 41 42 43 44 45
# Set a target version
# https://docs.microsoft.com/en-us/windows/release-health/release-information
# If you don't update this policy before the device reaches end of service, the device will automatically be updated once it is 60 days past end of service for its version.
# If you specify a TargetReleaseVersion the same as the current version, Windows 10 will stay on this version until it reaches end of service.
# If you specify a TargetReleaseVersion higher than the current version, Windows 10 will directly update only to the specified version even if a higher version is available.
# Enable
Function TweakSetTargetRelease { # RESINFO
	Write-Output "Set Target Release..."
Olivier De Marchi's avatar
Olivier De Marchi committed
46
	Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "ProductVersion" -value  $Global:SWMB_Custom.ProductVersion -Type String -Force
47
	Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersion" -value '00000001' -Type DWord -Force
Olivier De Marchi's avatar
Olivier De Marchi committed
48
	Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersionInfo" -value $Global:SWMB_Custom.TargetReleaseVersionInfo -Type String -Force
49 50 51 52 53 54 55 56 57 58 59 60
}

# Disable
Function TweakUnsetTargetRelease { # RESINFO
	Write-Output "No Target Release..."
	Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "ProductVersion" -ErrorAction SilentlyContinue
	Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersion" -ErrorAction SilentlyContinue
	Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersionInfo" -ErrorAction SilentlyContinue
}

# View
Function TweakViewTargetRelease { # RESINFO
Olivier De Marchi's avatar
Olivier De Marchi committed
61
	Write-Output 'Target Release (nothing = no target release)'
62 63
	Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersionInfo" -ErrorAction SilentlyContinue
}
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
Function RemoveKasperskyEndpoint { # RESINFO
	# Todo
	# move var in Custom-VarDefault
	# test on KesKeyFile

	$KesLogin = "KLAdmin"
	$Kespass = ""
	$KesKeyFile = ""
	$KesSecureString = ""

	$kes = Get-WmiObject win32_product | Where { $_.Name -like "*Kaspersky endpoint security*" }

	if ($kes.IdentifyingNumber) {
	  Write-Host "Uninstalling Kaspersky version $($kes.Version) with guid => $($kes.IdentifyingNumber)"
	  if ($Kespass) {
	    # mot de passe défini en clair
	    $PlainPassword = $Kespass
	  }
	  elseif ($KesSecureString) {
	    # mot de passe chiffré
	    $password = $KesSecureString | ConvertTo-SecureString -Key (Get-Content $KesKeyFile)
	    $credential = New-Object System.Management.Automation.PsCredential($KesLogin,$password)
	    $PlainPassword = $credential.GetNetworkCredential().Password
	  }
	  else {
	    # Interactif - mot de passe demandé
	    $PlainPassword = Read-Host -AsSecureString -Prompt "Give the Kaspersky endpoint password for $KesLogin"
	  }

	### uninstall
	  $MSIArguments = @(
	    "/x"
	    $kes.IdentifyingNumber
	    "KLLOGIN=$KesLogin"
	    "KLPASSWD=$PlainPassword"
	    "/norestart"
	    "/qn"
	  )
	  Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
	  Write-Host "Uninstall finish"
	}

	else {
	  Write-Host "Kaspersky not installed on this computer"
	}
}



114 115 116 117 118 119
################################################################
###### Export Functions
################################################################

# Export functions
Export-ModuleMember -Function *