Skip to content

Commit c4da61c

Browse files
authored
Fix PowerShell updates failing (#4878)
1 parent 586edea commit c4da61c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellPkgOperationHelper.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ OperationType operation
3333
if (options.PreRelease)
3434
parameters.Add("-AllowPrerelease");
3535

36-
if (!package.OverridenOptions.PowerShell_DoNotSetScopeParameter)
36+
// Update-Module (PowerShellGet) has no -Scope parameter; only Install-Module accepts it
37+
if (operation is OperationType.Install && !package.OverridenOptions.PowerShell_DoNotSetScopeParameter)
3738
{
3839
if (
3940
package.OverridenOptions.Scope == PackageScope.Global
@@ -66,6 +67,10 @@ package.OverridenOptions.Scope is null
6667
}
6768
);
6869

70+
// Windows PowerShell 5.x defaults to TLS 1.0/1.1, which the PowerShell Gallery rejects; force TLS 1.2 so gallery operations can connect under -NoProfile
71+
if (operation is not OperationType.Uninstall)
72+
parameters.Insert(0, "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;");
73+
6974
return parameters;
7075
}
7176

‎src/UniGetUI.PackageEngine.Operations/AbstractProcessOperation.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ protected override async Task<OperationVeredict> PerformOperation()
103103
Line($" - Arguments: \"{process.StartInfo.Arguments.Trim()}\"", LineType.VerboseDetails);
104104
Line($"Start Time: \"{DateTime.Now}\"", LineType.VerboseDetails);
105105

106+
// An empty FileName means elevation was required but no elevator (UniGetUI Elevator/GSudo) is available
107+
if (string.IsNullOrWhiteSpace(process.StartInfo.FileName))
108+
{
109+
Line(
110+
CoreTools.Translate(
111+
"This operation requires administrator privileges, but the elevation tool could not be found. The operation cannot continue."
112+
),
113+
LineType.Error
114+
);
115+
return OperationVeredict.Failure;
116+
}
117+
106118
if (_requiresUACCache)
107119
{
108120
_requiresUACCache = false;

0 commit comments

Comments
 (0)