Experimental.psm1 6.15 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"
}

Gabriel Moreau's avatar
Gabriel Moreau committed
38 39
################################################################

40 41 42 43 44 45 46
# 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
47
	Write-Output "Set Target Release to $($Global:SWMB_Custom.TargetReleaseVersionInfo)..."
Olivier De Marchi's avatar
Olivier De Marchi committed
48
	Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "ProductVersion" -value  $Global:SWMB_Custom.ProductVersion -Type String -Force
49
	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
50
	Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersionInfo" -value $Global:SWMB_Custom.TargetReleaseVersionInfo -Type String -Force
51 52 53 54 55 56 57 58 59 60 61 62
}

# 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
63
	Write-Output 'Target Release (nothing = no target release)'
64 65
	Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -Name "TargetReleaseVersionInfo" -ErrorAction SilentlyContinue
}
66

Gabriel Moreau's avatar
Gabriel Moreau committed
67
################################################################
68

Gabriel Moreau's avatar
Gabriel Moreau committed
69
# Suppress Kaspersky Endpoint software
Gabriel Moreau's avatar
Gabriel Moreau committed
70 71
# Uninstall
Function TweakUninstallKasperskyEndpoint { # RESINFO
Gabriel Moreau's avatar
Gabriel Moreau committed
72 73 74 75 76
	Write-Output "Suppress software Kaspersky Endpoint protection..."
	$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)"
Gabriel Moreau's avatar
Gabriel Moreau committed
77
		If ($($Global:SWMB_Custom.KesPassword)) {
Gabriel Moreau's avatar
Gabriel Moreau committed
78
			# Batch - password defined in clear text
Gabriel Moreau's avatar
Gabriel Moreau committed
79 80
			$PlainPassword = $($Global:SWMB_Custom.KesPassword)
		} ElseIf (($($Global:SWMB_Custom.KesSecureString)) -And (Test-Path -LiteralPath "$($Global:SWMB_Custom.KesKeyFile)")) {
Gabriel Moreau's avatar
Gabriel Moreau committed
81
			# Batch - encrypted (blurred) password
Gabriel Moreau's avatar
Gabriel Moreau committed
82 83
			$Password = $($Global:SWMB_Custom.KesSecureString) | ConvertTo-SecureString -Key (Get-Content $($Global:SWMB_Custom.KesKeyFile))
			$Credential = New-Object System.Management.Automation.PsCredential($($Global:SWMB_Custom.KesLogin),$Password)
Gabriel Moreau's avatar
Gabriel Moreau committed
84 85 86
			$PlainPassword = $Credential.GetNetworkCredential().Password
		} Else {
			# Interactive - ask password
Gabriel Moreau's avatar
Gabriel Moreau committed
87
			$PlainPassword = Read-Host -AsSecureString -Prompt "Give the Kaspersky endpoint password for $($($Global:SWMB_Custom.KesLogin))"
Gabriel Moreau's avatar
Gabriel Moreau committed
88 89 90 91 92 93
		}

		# Uninstall
		$MSIArguments = @(
			"/x"
			$Kes.IdentifyingNumber
Gabriel Moreau's avatar
Gabriel Moreau committed
94
			"KLLOGIN=$($($Global:SWMB_Custom.KesLogin))"
Gabriel Moreau's avatar
Gabriel Moreau committed
95 96 97 98 99
			"KLPASSWD=$PlainPassword"
			"/norestart"
			"/qn"
		)
		Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
100

101 102 103 104 105 106 107
		# Remove Kaspersky Agent, Franch Guid = {2924BEDA-E0D7-4DAF-A224-50D2E0B12F5B}
		$KesAgent = Get-WmiObject win32_product | Where { $_.Name -like "*Agent*Kaspersky Security Center*" }
		If ($KesAgent.IdentifyingNumber) {
			Write-Output "Suppress Agent Kaspersky Security Center..."
			Start-Process "msiexec.exe" -ArgumentList "/X $($KesAgent.IdentifyingNumber) /qn" -Wait -NoNewWindow
			}
			
Gabriel Moreau's avatar
Gabriel Moreau committed
108 109 110
		Write-Host "Uninstall finish"
	} Else {
		Write-Host "Kaspersky not installed on this computer"
111 112 113
	}
}

Gabriel Moreau's avatar
Gabriel Moreau committed
114 115 116 117 118 119 120 121
# Install
#Function TweakInstallKasperskyEndpoint { # RESINFO
#	Write-Output "Install software Kaspersky Endpoint protection..."
#	Write-Output "Error: Empty function defined only for check"
#	Write-Output "Error: use your deploiement software in order to install Kasperky Endpoint"
#	Exit
#}

122

123 124 125 126 127 128
################################################################
###### Export Functions
################################################################

# Export functions
Export-ModuleMember -Function *