diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 344b69631..030ae1629 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -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 _pathsToInstallPkg; @@ -84,6 +85,7 @@ public List InstallPackages( bool authenticodeCheck, bool savePkg, List pathsToInstallPkg, + ScopeType? scope, string tmpPath) { _cmdletPassedIn.WriteVerbose(string.Format("Parameters passed in >>> Name: '{0}'; Version: '{1}'; Prerelease: '{2}'; Repository: '{3}'; " + @@ -140,7 +142,8 @@ public List InstallPackages( repository: repository, trustRepository: _trustRepository, credential: _credential, - skipDependencyCheck: skipDependencyCheck); + skipDependencyCheck: skipDependencyCheck, + scope: scope?? ScopeType.CurrentUser); } #endregion @@ -152,7 +155,8 @@ private List ProcessRepositories( string[] repository, bool trustRepository, PSCredential credential, - bool skipDependencyCheck) + bool skipDependencyCheck, + ScopeType scope) { var listOfRepositories = RepositorySettings.Read(repository, out string[] _); var yesToAll = false; @@ -238,7 +242,8 @@ private List ProcessRepositories( repo.Uri.AbsoluteUri, repo.CredentialInfo, credential, - isLocalRepo); + isLocalRepo, + scope: scope); foreach (PSResourceInfo pkg in pkgsInstalled) { @@ -322,7 +327,8 @@ private List InstallPackage( string repoUri, PSCredentialInfo repoCredentialInfo, PSCredential credential, - bool isLocalRepo) + bool isLocalRepo, + ScopeType scope) { List pkgsSuccessfullyInstalled = new List(); int totalPkgs = pkgsToInstall.Count; @@ -580,6 +586,18 @@ private List 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) { diff --git a/src/code/InstallPSResource.cs b/src/code/InstallPSResource.cs index b27b48093..84e563235 100644 --- a/src/code/InstallPSResource.cs +++ b/src/code/InstallPSResource.cs @@ -552,6 +552,7 @@ private void ProcessInstallHelper(string[] pkgNames, VersionRange pkgVersion, bo authenticodeCheck: AuthenticodeCheck, savePkg: false, pathsToInstallPkg: _pathsToInstallPkg, + scope: Scope, tmpPath: _tmpPath); if (PassThru) diff --git a/src/code/SavePSResource.cs b/src/code/SavePSResource.cs index 9c92a261f..4b3c9cc82 100644 --- a/src/code/SavePSResource.cs +++ b/src/code/SavePSResource.cs @@ -291,6 +291,7 @@ private void ProcessSaveHelper(string[] pkgNames, bool pkgPrerelease, string[] p authenticodeCheck: AuthenticodeCheck, savePkg: true, pathsToInstallPkg: new List { _path }, + scope: null, tmpPath: _tmpPath); if (PassThru) diff --git a/src/code/UpdatePSResource.cs b/src/code/UpdatePSResource.cs index c670c0afe..fcb0dfe3e 100644 --- a/src/code/UpdatePSResource.cs +++ b/src/code/UpdatePSResource.cs @@ -213,6 +213,7 @@ protected override void ProcessRecord() authenticodeCheck: AuthenticodeCheck, savePkg: false, pathsToInstallPkg: _pathsToInstallPkg, + scope: Scope, tmpPath: _tmpPath); if (PassThru)