Fix scripts

This commit is contained in:
2023-10-23 16:33:08 +00:00
parent e333365da4
commit b76e612f35
3 changed files with 31 additions and 39 deletions

View File

@@ -29,11 +29,7 @@ foreach ($fileInfo in $filesToDownload) {
} }
# Install Office # Install Office
function Check-OfficeInstall { function CheckOfficeInstall {
param (
[string] $version = "Office365" # Specify the Office version (e.g., "Office365" or "2019")
)
$officeRegistryPath = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun" $officeRegistryPath = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun"
if (Test-Path -Path $officeRegistryPath) { if (Test-Path -Path $officeRegistryPath) {
$installedPath = Get-ItemProperty -Path $officeRegistryPath | Select-Object -ExpandProperty "InstallPath" $installedPath = Get-ItemProperty -Path $officeRegistryPath | Select-Object -ExpandProperty "InstallPath"
@@ -57,13 +53,14 @@ function Check-OfficeInstall {
Start-Process -FilePath $(Join-Path $driveLetter '\Office\Setup64.exe') -Wait Start-Process -FilePath $(Join-Path $driveLetter '\Office\Setup64.exe') -Wait
} }
} }
CheckOfficeInstall
# Activate windows/office # Activate windows/office
irm https://massgrave.dev/get | iex Invoke-RestMethod https://massgrave.dev/get | Invoke-Expression
# Setup users # Setup users
$username = "Eleve" $username = "Eleve"
if ($(Get-LocalUser -Name $username -ErrorAction SilentlyContinue) -eq $null) { if ($null -eq $(Get-LocalUser -Name $username -ErrorAction SilentlyContinue)) {
Write-Host "User $username doesn't exist. Creating the user..." Write-Host "User $username doesn't exist. Creating the user..."
New-LocalUser -Name $username -Description "New User Account" -NoPassword -UserMayNotChangePassword New-LocalUser -Name $username -Description "New User Account" -NoPassword -UserMayNotChangePassword
Add-LocalGroupMember -Group Users -Member $username Add-LocalGroupMember -Group Users -Member $username
@@ -73,7 +70,7 @@ if ($(Get-LocalUser -Name $username -ErrorAction SilentlyContinue) -eq $null) {
} }
$username = "Prof" $username = "Prof"
$SecurePassword = ConvertTo-SecureString -String "IPRprof2398" -AsPlainText -Force $SecurePassword = ConvertTo-SecureString -String "IPRprof2398" -AsPlainText -Force
if ($(Get-LocalUser -Name $username -ErrorAction SilentlyContinue) -eq $null) { if ($null -eq $(Get-LocalUser -Name $username -ErrorAction SilentlyContinue)) {
Write-Host "User $username doesn't exist. Creating the user..." Write-Host "User $username doesn't exist. Creating the user..."
New-LocalUser -Name $username -Description "New User Account" -Password $SecurePassword -PasswordNeverExpires -UserMayNotChangePassword New-LocalUser -Name $username -Description "New User Account" -Password $SecurePassword -PasswordNeverExpires -UserMayNotChangePassword
Add-LocalGroupMember -Group Users -Member $username Add-LocalGroupMember -Group Users -Member $username
@@ -83,7 +80,7 @@ if ($(Get-LocalUser -Name $username -ErrorAction SilentlyContinue) -eq $null) {
} }
$username = "Admin" $username = "Admin"
$SecurePassword = ConvertTo-SecureString -String "Lprsnm4ehk26-" -AsPlainText -Force $SecurePassword = ConvertTo-SecureString -String "Lprsnm4ehk26-" -AsPlainText -Force
if ($(Get-LocalUser -Name $username -ErrorAction SilentlyContinue) -eq $null) { if ($null -eq $(Get-LocalUser -Name $username -ErrorAction SilentlyContinue)) {
Write-Host "User $username doesn't exist. Creating the user..." Write-Host "User $username doesn't exist. Creating the user..."
New-LocalUser -Name $username -Description "New User Account" -Password $SecurePassword -PasswordNeverExpires -UserMayNotChangePassword New-LocalUser -Name $username -Description "New User Account" -Password $SecurePassword -PasswordNeverExpires -UserMayNotChangePassword
Add-LocalGroupMember -Group Administrators -Member $username Add-LocalGroupMember -Group Administrators -Member $username
@@ -100,7 +97,7 @@ function UserReg {
) )
$UserProfiles = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false } $UserProfiles = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false }
$UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") } $UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") }
if ($UserProfile -ne $null) { if ($null -ne $UserProfile) {
$UserSID = $UserProfile.SID $UserSID = $UserProfile.SID
if( -not (Test-Path -Path "Registry::HKEY_USERS\$UserSID" -PathType Container) ) { if( -not (Test-Path -Path "Registry::HKEY_USERS\$UserSID" -PathType Container) ) {
REG LOAD HKEY_USERS\$UserSID "C:\Users\$Username\NTUSER.DAT" REG LOAD HKEY_USERS\$UserSID "C:\Users\$Username\NTUSER.DAT"
@@ -134,7 +131,7 @@ function SetRegistry {
$UserSID, $UserHKUPath = UserReg -Username "Eleve" $UserSID, $UserHKUPath = UserReg -Username "Eleve"
# Add restriction # Add restriction
if ($UserSID -ne $null -and $UserHKUPath -ne $null) { if ($null -ne $UserSID -and $null -ne $UserHKUPath) {
# Restrict access to Settings # Restrict access to Settings
$ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" $ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
$ControlPanelValueName = "NoControlPanel" $ControlPanelValueName = "NoControlPanel"
@@ -157,7 +154,7 @@ if ($UserSID -ne $null -and $UserHKUPath -ne $null) {
if (-not (Test-Path -Path "Registry::$DisallowRunPath" -PathType Container)) { if (-not (Test-Path -Path "Registry::$DisallowRunPath" -PathType Container)) {
New-Item -Path $DisallowRunPath -Force New-Item -Path $DisallowRunPath -Force
} }
Set-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "DisallowRun" -Value 1 Set-ItemProperty -Path $DisallowRunKeyPath -Name $DisallowRunValueName -Value 1
$applications = @("cmd.exe", "powershell.exe", "powershell_ise.exe") $applications = @("cmd.exe", "powershell.exe", "powershell_ise.exe")
Get-ItemProperty -Path $DisallowRunPath | ForEach-Object { Get-ItemProperty -Path $DisallowRunPath | ForEach-Object {
Remove-ItemProperty -Path $DisallowRunPath -Name $_.PSObject.Properties.Name -ErrorAction SilentlyContinue Remove-ItemProperty -Path $DisallowRunPath -Name $_.PSObject.Properties.Name -ErrorAction SilentlyContinue
@@ -202,7 +199,6 @@ function InstallExe {
if (-not (Test-Path -Path $targetPath -PathType Container)) { if (-not (Test-Path -Path $targetPath -PathType Container)) {
New-Item -Path $targetPath -ItemType Directory New-Item -Path $targetPath -ItemType Directory
} }
$appFilePath = Join-Path $tmpPath $app
Copy-Item -Path (Join-Path $tmpPath $app) -Destination $targetPath -Force Copy-Item -Path (Join-Path $tmpPath $app) -Destination $targetPath -Force
createShortcut -exe (Join-Path $targetPath $app) -app $appName createShortcut -exe (Join-Path $targetPath $app) -app $appName
} }
@@ -247,7 +243,7 @@ function createShortcut {
} }
#Install Choco #Install Choco
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Installing needed apps # Installing needed apps
choco upgrade all -y choco upgrade all -y
@@ -271,7 +267,7 @@ InstallMsi -app "EV3_Classroom_Windows_1.5.3_Global.msi"
InstallZip -zip "RobotProg.zip" -exe "RobotProg.exe" -app "RobotProg" InstallZip -zip "RobotProg.zip" -exe "RobotProg.exe" -app "RobotProg"
# URL shortcut # URL shortcut
function Create-DesktopShortcut { function New-DesktopShortcut {
param ( param (
[string] $ShortcutName, [string] $ShortcutName,
[string] $TargetUrl [string] $TargetUrl
@@ -285,10 +281,10 @@ function Create-DesktopShortcut {
$urlShortcut.Save() $urlShortcut.Save()
} }
Create-DesktopShortcut -ShortcutName "Office 365" -TargetUrl "https://office.com/" New-DesktopShortcut -ShortcutName "Office 365" -TargetUrl "https://office.com/"
Create-DesktopShortcut -ShortcutName "Ecole Direct" -TargetUrl "https://ecoledirecte.com/" New-DesktopShortcut -ShortcutName "Ecole Direct" -TargetUrl "https://ecoledirecte.com/"
Create-DesktopShortcut -ShortcutName "PIX" -TargetUrl "https://pix.fr/" New-DesktopShortcut -ShortcutName "PIX" -TargetUrl "https://pix.fr/"
Create-DesktopShortcut -ShortcutName "Framindmap" -TargetUrl "https://framindmap.org/" New-DesktopShortcut -ShortcutName "Framindmap" -TargetUrl "https://framindmap.org/"
# Update Windows # Update Windows

View File

@@ -1,5 +1,5 @@
# Activate windows # Activate windows
irm https://massgrave.dev/get | iex Invoke-RestMethod https://massgrave.dev/get | Invoke-Expression
#Download temp files #Download temp files
$tmpPath = Join-Path $env:LOCALAPPDATA "Temp" $tmpPath = Join-Path $env:LOCALAPPDATA "Temp"
@@ -67,7 +67,7 @@ foreach ($fileInfo in $filesToDownload) {
} }
} }
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Setup users # Setup users
Set-LocalUser -Name "Eleve" -PasswordNeverExpires $true -UserMayChangePassword $false -Password ([securestring]::new()) Set-LocalUser -Name "Eleve" -PasswordNeverExpires $true -UserMayChangePassword $false -Password ([securestring]::new())
@@ -84,9 +84,8 @@ function UserReg {
) )
$UserProfiles = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false } $UserProfiles = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false }
$UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") } $UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") }
if ($UserProfile -ne $null) { if ($null -ne $UserProfile) {
$UserSID = $UserProfile.SID $UserSID = $UserProfile.SID
$HivePath = Join-Path -Path $UserProfile.LocalPath -ChildPath "NTUSER.DAT"
return $UserSID, "Registry::HKEY_USERS\$UserSID" return $UserSID, "Registry::HKEY_USERS\$UserSID"
} else { } else {
Write-Host "User profile for $Username not found." Write-Host "User profile for $Username not found."
@@ -117,7 +116,7 @@ function SetRegistry {
$TargetUsername = "Eleve" $TargetUsername = "Eleve"
$UserSID, $UserHKUPath = UserReg -Username $TargetUsername $UserSID, $UserHKUPath = UserReg -Username $TargetUsername
# Add restriction # Add restriction
if ($UserSID -ne $null -and $UserHKUPath -ne $null) { if ($null -ne $UserSID -and $null -ne $UserHKUPath) {
# Restrict access to Settings # Restrict access to Settings
$ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" $ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
$ControlPanelValueName = "NoControlPanel" $ControlPanelValueName = "NoControlPanel"
@@ -177,15 +176,14 @@ function InstallExe {
if (-not (Test-Path -Path $targetPath -PathType Container)) { if (-not (Test-Path -Path $targetPath -PathType Container)) {
New-Item -Path $targetPath -ItemType Directory New-Item -Path $targetPath -ItemType Directory
} }
$appFilePath = Join-Path $tmpPath $app
Copy-Item -Path (Join-Path $tmpPath $app) -Destination $targetPath -Force Copy-Item -Path (Join-Path $tmpPath $app) -Destination $targetPath -Force
createShortcut -exe (Join-Path $targetPath $app) -app $appName createShortcut -exe (Join-Path $targetPath $app) -app $appName
} }
function InstallZipSetup { function InstallZipSetup {
param ( param (
[string] $zip [string] $zip,
[string] $exe, [string] $exe
) )
$zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip) $zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip)
Expand-Archive -Path (Join-Path $tmpPath $zip) -DestinationPath $tmpPath -Force Expand-Archive -Path (Join-Path $tmpPath $zip) -DestinationPath $tmpPath -Force
@@ -194,9 +192,9 @@ function InstallZipSetup {
function InstallZip { function InstallZip {
param ( param (
[string] $zip [string] $zip,
[string] $exe, [string] $exe,
[string] $app, [string] $app
) )
$zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip) $zipName = [System.IO.Path]::GetFileNameWithoutExtension($zip)
@@ -207,8 +205,8 @@ function InstallZip {
function createShortcut { function createShortcut {
param ( param (
[string] $exe [string] $exe,
[string] $app, [string] $app
) )
$shell = New-Object -ComObject WScript.Shell $shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($(Join-Path $env:PUBLIC "Desktop\$app.lnk")) $shortcut = $shell.CreateShortcut($(Join-Path $env:PUBLIC "Desktop\$app.lnk"))

View File

@@ -1,4 +1,4 @@
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# remove bloatware # remove bloatware
$apps = @( $apps = @(
"Microsoft.549981C3F5F10" "Microsoft.549981C3F5F10"
@@ -204,9 +204,9 @@ Set-LocalUser -Name "Prof" -PasswordNeverExpires $true -UserMayChangePassword $f
$SecurePassword = ConvertTo-SecureString -String "Lprsnm4ehk26-" -AsPlainText -Force $SecurePassword = ConvertTo-SecureString -String "Lprsnm4ehk26-" -AsPlainText -Force
Set-LocalUser -Name "Admin" -PasswordNeverExpires $true -Password $SecurePassword Set-LocalUser -Name "Admin" -PasswordNeverExpires $true -Password $SecurePassword
cd D:\Setup\Labo Set-Location D:\Setup\Labo
cd E:\Setup\Labo Set-Location E:\Setup\Labo
cd F:\Setup\Labo Set-Location F:\Setup\Labo
Copy-Item -Path .\Software\* -Destination "C:\Program Files\" -Recurse Copy-Item -Path .\Software\* -Destination "C:\Program Files\" -Recurse
Copy-Item -Path .\Shortcut\* -Destination "C:\Users\Public\Desktop\" -Recurse Copy-Item -Path .\Shortcut\* -Destination "C:\Users\Public\Desktop\" -Recurse
icacls "C:\Users\Public" /grant:r "Eleve:(OI)(CI)(R)" icacls "C:\Users\Public" /grant:r "Eleve:(OI)(CI)(R)"
@@ -225,11 +225,9 @@ function UserReg {
$UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") } $UserProfile = $UserProfiles | Where-Object { $_.LocalPath.EndsWith("\$Username") }
# Check if the user profile exists # Check if the user profile exists
if ($UserProfile -ne $null) { if ($null -ne $UserProfile) {
# Construct the path to the user's NTUSER.DAT file (registry hive) # Construct the path to the user's NTUSER.DAT file (registry hive)
$UserSID = $UserProfile.SID $UserSID = $UserProfile.SID
$HivePath = Join-Path -Path $UserProfile.LocalPath -ChildPath "NTUSER.DAT"
# Return the user's SID and HKU registry key # Return the user's SID and HKU registry key
return $UserSID, "Registry::HKEY_USERS\$UserSID" return $UserSID, "Registry::HKEY_USERS\$UserSID"
} else { } else {
@@ -241,7 +239,7 @@ function UserReg {
$TargetUsername = "Eleve" $TargetUsername = "Eleve"
$UserSID, $UserHKUPath = UserReg -Username $TargetUsername $UserSID, $UserHKUPath = UserReg -Username $TargetUsername
if ($UserSID -ne $null -and $UserHKUPath -ne $null) { if ($null -ne $UserSID -and $null -ne $UserHKUPath) {
# Restrict access to Settings # Restrict access to Settings
$ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" $ControlPanelKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
$ControlPanelValueName = "NoControlPanel" $ControlPanelValueName = "NoControlPanel"