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

41 lines
1.1 KiB
PowerShell
Raw Normal View History

# Function to configure the prefered scope option as Machine
2023-09-15 14:38:54 +00:00
function Add-ScopeMachine
{
[CmdletBinding()]
param
(
2023-09-15 14:38:54 +00:00
[string]
$SettingsPath
)
2023-09-15 14:38:54 +00:00
if (Test-Path -Path $SettingsPath -ErrorAction SilentlyContinue)
{
$ConfigFile = (Get-Content -Path $SettingsPath -ErrorAction SilentlyContinue | Where-Object -FilterScript {
($_ -notmatch '//')
2023-09-15 14:38:54 +00:00
} | ConvertFrom-Json)
}
2023-09-15 14:38:54 +00:00
if (!$ConfigFile)
{
2023-09-15 14:38:54 +00:00
$ConfigFile = @{
}
}
2023-09-15 14:38:54 +00:00
if ($ConfigFile.installBehavior.preferences.scope)
{
$ConfigFile.installBehavior.preferences.scope = 'Machine'
}
2023-09-15 14:38:54 +00:00
else
{
$Scope = (New-Object -TypeName PSObject -Property $(@{
scope = 'Machine'
2023-09-15 14:38:54 +00:00
}))
$Preference = (New-Object -TypeName PSObject -Property $(@{
preferences = $Scope
2023-09-15 14:38:54 +00:00
}))
$null = (Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force)
}
$null = ($ConfigFile | ConvertTo-Json | Out-File -FilePath $SettingsPath -Encoding utf8 -Force -Confirm:$false)
2022-10-26 22:49:10 +00:00
}