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

21 lines
808 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-06-10 08:26:41 +00:00
if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
2022-05-08 12:19:41 +00:00
}
2022-06-10 08:26:41 +00:00
if (!$ConfigFile) {
2022-05-08 12:19:41 +00:00
$ConfigFile = @{}
}
2022-06-10 08:26:41 +00:00
if ($ConfigFile.installBehavior.preferences.scope) {
2022-05-08 12:19:41 +00:00
$ConfigFile.installBehavior.preferences.scope = "Machine"
}
else {
2022-06-10 08:26:41 +00:00
$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
2022-05-08 12:19:41 +00:00
}
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
2022-10-26 22:49:10 +00:00
}