Skip to content
Merged
26 changes: 22 additions & 4 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class InstallHelper
public const string PSScriptFileExt = ".ps1";
private const string MsgRepositoryNotTrusted = "Untrusted repository";
private const string MsgInstallUntrustedPackage = "You are installing the modules from an untrusted repository. If you trust this repository, change its Trusted value by running the Set-PSResourceRepository cmdlet. Are you sure you want to install the PSresource from '{0}' ?";
private const string ScriptPATHWarning = "The installation path for the script does not currently appear in the {0} path environment variable. To make the script discoverable, add the script installation path, {1}, to the environment PATH variable.";
private CancellationToken _cancellationToken;
private readonly PSCmdlet _cmdletPassedIn;
private List<string> _pathsToInstallPkg;
Expand Down Expand Up @@ -84,6 +85,7 @@ public List<PSResourceInfo> InstallPackages(
bool authenticodeCheck,
bool savePkg,
List<string> pathsToInstallPkg,
ScopeType? scope,
string tmpPath)
{
_cmdletPassedIn.WriteVerbose(string.Format("Parameters passed in >>> Name: '{0}'; Version: '{1}'; Prerelease: '{2}'; Repository: '{3}'; " +
Expand Down Expand Up @@ -140,7 +142,8 @@ public List<PSResourceInfo> InstallPackages(
repository: repository,
trustRepository: _trustRepository,
credential: _credential,
skipDependencyCheck: skipDependencyCheck);
skipDependencyCheck: skipDependencyCheck,
scope: scope?? ScopeType.CurrentUser);
}

#endregion
Expand All @@ -152,7 +155,8 @@ private List<PSResourceInfo> ProcessRepositories(
string[] repository,
bool trustRepository,
PSCredential credential,
bool skipDependencyCheck)
bool skipDependencyCheck,
ScopeType scope)
{
var listOfRepositories = RepositorySettings.Read(repository, out string[] _);
var yesToAll = false;
Expand Down Expand Up @@ -238,7 +242,8 @@ private List<PSResourceInfo> ProcessRepositories(
repo.Uri.AbsoluteUri,
repo.CredentialInfo,
credential,
isLocalRepo);
isLocalRepo,
scope: scope);

foreach (PSResourceInfo pkg in pkgsInstalled)
{
Expand Down Expand Up @@ -322,7 +327,8 @@ private List<PSResourceInfo> InstallPackage(
string repoUri,
PSCredentialInfo repoCredentialInfo,
PSCredential credential,
bool isLocalRepo)
bool isLocalRepo,
ScopeType scope)
{
List<PSResourceInfo> pkgsSuccessfullyInstalled = new List<PSResourceInfo>();
int totalPkgs = pkgsToInstall.Count;
Expand Down Expand Up @@ -580,6 +586,18 @@ private List<PSResourceInfo> InstallPackage(

_cmdletPassedIn.WriteVerbose(String.Format("Successfully installed package '{0}' to location '{1}'", pkg.Name, installPath));
pkgsSuccessfullyInstalled.Add(pkg);

if (!_savePkg && !isModule)
{
string installPathwithBackSlash = installPath + "\\";
string envPATHVarValue = Environment.GetEnvironmentVariable("PATH",
scope == ScopeType.CurrentUser ? EnvironmentVariableTarget.User : EnvironmentVariableTarget.Machine);

if (!envPATHVarValue.Contains(installPath) && !envPATHVarValue.Contains(installPathwithBackSlash))
{
_cmdletPassedIn.WriteWarning(String.Format(ScriptPATHWarning, scope, installPath));
}
}
}
catch (Exception e)
{
Expand Down
1 change: 1 addition & 0 deletions src/code/InstallPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ private void ProcessInstallHelper(string[] pkgNames, VersionRange pkgVersion, bo
authenticodeCheck: AuthenticodeCheck,
savePkg: false,
pathsToInstallPkg: _pathsToInstallPkg,
scope: Scope,
tmpPath: _tmpPath);

if (PassThru)
Expand Down
1 change: 1 addition & 0 deletions src/code/SavePSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private void ProcessSaveHelper(string[] pkgNames, bool pkgPrerelease, string[] p
authenticodeCheck: AuthenticodeCheck,
savePkg: true,
pathsToInstallPkg: new List<string> { _path },
scope: null,
tmpPath: _tmpPath);

if (PassThru)
Expand Down
1 change: 1 addition & 0 deletions src/code/UpdatePSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ protected override void ProcessRecord()
authenticodeCheck: AuthenticodeCheck,
savePkg: false,
pathsToInstallPkg: _pathsToInstallPkg,
scope: Scope,
tmpPath: _tmpPath);

if (PassThru)
Expand Down