Skip to content

Commit

Permalink
Merge pull request #94 from Romanitho/wrong-copy-paste
Browse files Browse the repository at this point in the history
fix Add-ScopeMachine
  • Loading branch information
Romanitho authored Oct 29, 2023
2 parents 4318d09 + 50b7e81 commit 8942196
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions winget-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,34 @@ function Get-WingetCmd {

#Function to configure prefered scope option as Machine
function Add-ScopeMachine {
#Function to configure prefered scope option as Machine
function Add-ScopeMachine {
#Get Settings path for system or current user
if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
$SettingsPath = "$Env:windir\System32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\settings.json"
}
else {
$SettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
}

$ConfigFile = @{}
#Get Settings path for system or current user
if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
$SettingsPath = "$Env:windir\System32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\settings.json"
}
else {
$SettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
}

#Check if setting file exist, if not create it
if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
}
else {
New-Item -Path $SettingsPath
}
$ConfigFile = @{}

if ($ConfigFile.installBehavior.preferences) {
Add-Member -InputObject $ConfigFile.installBehavior.preferences -MemberType NoteProperty -Name 'scope' -Value 'Machine' -Force
}
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
}
#Check if setting file exist, if not create it
if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
}
else {
New-Item -Path $SettingsPath
}

$ConfigFile | ConvertTo-Json | Out-File $SettingsPath -Encoding utf8 -Force
if ($ConfigFile.installBehavior.preferences) {
Add-Member -InputObject $ConfigFile.installBehavior.preferences -MemberType NoteProperty -Name 'scope' -Value 'Machine' -Force
}
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 | Out-File $SettingsPath -Encoding utf8 -Force
}

function Install-Prerequisites {
Expand Down

0 comments on commit 8942196

Please sign in to comment.