Experimental.psm1 5.18 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
# 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
45
	Write-Output "Set Target Release to $($Global:SWMB_Custom.TargetReleaseVersionInfo)..."
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

Olivier De Marchi's avatar
Olivier De Marchi committed
65
Function TweakRemoveKasperskyEndpoint { # RESINFO
66 67 68 69 70 71 72
	# Todo
	# test on KesKeyFile

	$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)"
73
	  if ($Global:SWMB_Custom.Kespass) {
74
	    # mot de passe défini en clair
75
	    $PlainPassword = $Global:SWMB_Custom.Kespass
76
	  }
77
	  elseif ($Global:SWMB_Custom.KesSecureString) {
78
	    # mot de passe chiffré
79 80
	    $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)
81 82 83 84
	    $PlainPassword = $credential.GetNetworkCredential().Password
	  }
	  else {
	    # Interactif - mot de passe demandé
85
	    $PlainPassword = Read-Host -AsSecureString -Prompt "Give the Kaspersky endpoint password for $($Global:SWMB_Custom.KesLogin)"
86 87 88 89 90 91
	  }

	### uninstall
	  $MSIArguments = @(
	    "/x"
	    $kes.IdentifyingNumber
92
	    "KLLOGIN=$($Global:SWMB_Custom.KesLogin)"
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	    "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"
	}
}



108 109 110 111 112 113
################################################################
###### Export Functions
################################################################

# Export functions
Export-ModuleMember -Function *