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