2023-10-03 08:18:00 +00:00
|
|
|
#Function to configure the prefered scope option as Machine
|
2023-11-20 16:31:38 +00:00
|
|
|
function Add-ScopeMachine {
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-11-20 16:31:38 +00:00
|
|
|
#Get Settings path for system or current user
|
|
|
|
if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
|
2023-11-29 01:04:17 +00:00
|
|
|
$SettingsPath = "$Env:windir\System32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
|
2023-11-20 16:31:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$SettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
|
|
|
|
}
|
|
|
|
|
|
|
|
$ConfigFile = @{}
|
|
|
|
|
|
|
|
#Check if setting file exist, if not create it
|
2023-10-03 08:18:00 +00:00
|
|
|
if (Test-Path $SettingsPath) {
|
|
|
|
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
|
|
|
|
}
|
2023-11-20 16:31:38 +00:00
|
|
|
else {
|
|
|
|
New-Item -Path $SettingsPath -Force | Out-Null
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
2023-11-20 16:31:38 +00:00
|
|
|
|
|
|
|
if ($ConfigFile.installBehavior.preferences) {
|
2023-11-21 11:52:47 +00:00
|
|
|
Add-Member -InputObject $ConfigFile.installBehavior.preferences -MemberType NoteProperty -Name "scope" -Value "Machine" -Force
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-11-21 11:52:47 +00:00
|
|
|
$Scope = New-Object PSObject -Property $(@{scope = "Machine" })
|
2023-10-03 08:18:00 +00:00
|
|
|
$Preference = New-Object PSObject -Property $(@{preferences = $Scope })
|
2023-11-21 11:52:47 +00:00
|
|
|
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name "installBehavior" -Value $Preference -Force
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-11-20 16:31:38 +00:00
|
|
|
$ConfigFile | ConvertTo-Json -Depth 100 | Out-File $SettingsPath -Encoding utf8 -Force
|
|
|
|
}
|