Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,22 @@ public static string GetProfilePath(string Scope, SessionState sessionState)
var userprofile = "";
if (Scope != null && Scope.Equals("CurrentUser"))
{
var editionType = sessionState.PSVariable.GetValue("PSEdition") as string;
var psFolder = string.Equals(editionType, "Desktop", StringComparison.OrdinalIgnoreCase) ? "WindowsPowerShell" : "PowerShell";
userprofile = Path.Combine(sessionState.PSVariable.GetValue("env:USERPROFILE").ToString(), "Documents", psFolder, "profile.ps1");
var powershellProfile = sessionState.PSVariable.GetValue("PROFILE") as PSObject;
if (powershellProfile == null || !powershellProfile.Members.ToList().Any(a => a.Name.Equals("CurrentUserAllHosts")))
{
throw new PSInvalidOperationException(string.Format(Properties.Resources.ProfilePathNull, "PROFILE.CurrentUserAllHosts"));
}
userprofile = powershellProfile.Members.ToList().Where(a => a.Name.Equals("CurrentUserAllHosts")).First().Value.ToString();
}

else if (Scope != null && Scope.Equals("LocalMachine"))
{
userprofile = Path.Combine(sessionState.PSVariable.GetValue("PSHOME").ToString(), "profile.ps1");
var powershellProfile = sessionState.PSVariable.GetValue("PROFILE") as PSObject;
if (powershellProfile == null || !powershellProfile.Members.ToList().Any(a => a.Name.Equals("AllUsersAllHosts")))
{
throw new PSInvalidOperationException(string.Format(Properties.Resources.ProfilePathNull, "PROFILE.AllUsersAllHosts"));
}
userprofile = powershellProfile.Members.ToList().Where(a => a.Name.Equals("AllUsersAllHosts")).First().Value.ToString();
}

return userprofile;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,7 @@
<data name="AliasImportFailure" xml:space="preserve">
<value>LocalMachine scope can only be set in PowerShell administrative mode.</value>
</data>
<data name="ProfilePathNull" xml:space="preserve">
<value>Unable to set profile because environment variable '${0}' is null.</value>
</data>
</root>