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

21 lines
824 B
PowerShell
Raw Normal View History

#Function to configure the prefered scope option as Machine
function Add-ScopeMachine ($SettingsPath) {
if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
}
if (!$ConfigFile) {
$ConfigFile = @{}
}
if ($ConfigFile.installBehavior.preferences.scope) {
$ConfigFile.installBehavior.preferences.scope = "Machine"
}
else {
$Scope = New-Object PSObject -Property $(@{scope = "Machine" })
$Preference = New-Object PSObject -Property $(@{preferences = $Scope })
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force
}
$ConfigFile | ConvertTo-Json -Depth 100 | Out-File $SettingsPath -Encoding utf8 -Force
2022-10-26 22:49:10 +00:00
}