wingetautoupdate/Winget-AutoUpdate/functions/Add-ScopeMachine.ps1

22 lines
804 B
PowerShell
Raw Normal View History

2022-05-08 12:19:41 +00:00
#Function to configure prefered scope option as Machine
2022-05-09 16:18:02 +00:00
function Add-ScopeMachine ($SettingsPath) {
2022-05-08 12:19:41 +00:00
2022-05-09 16:18:02 +00:00
if (Test-Path $SettingsPath){
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object {$_ -notmatch '//'} | ConvertFrom-Json
2022-05-08 12:19:41 +00:00
}
if (!$ConfigFile){
$ConfigFile = @{}
}
if ($ConfigFile.installBehavior.preferences.scope){
$ConfigFile.installBehavior.preferences.scope = "Machine"
}
else {
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $(
New-Object PSObject -Property $(@{preferences = $(
New-Object PSObject -Property $(@{scope = "Machine"}))
})
) -Force
}
2022-05-09 16:18:02 +00:00
$ConfigFile | ConvertTo-Json | Out-File $SettingsPath -Encoding utf8 -Force
2022-05-08 12:19:41 +00:00
}