Skip to content

Commit 0436e55

Browse files
author
maddieclayton
committed
fix alias
1 parent 2309d69 commit 0436e55

File tree

1 file changed

+12
-4
lines changed
  • src/ResourceManager/Profile/Commands.Profile/AzureRmAlias

1 file changed

+12
-4
lines changed

src/ResourceManager/Profile/Commands.Profile/AzureRmAlias/AliasHelper.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,22 @@ public static string GetProfilePath(string Scope, SessionState sessionState)
4545
var userprofile = "";
4646
if (Scope != null && Scope.Equals("CurrentUser"))
4747
{
48-
var editionType = sessionState.PSVariable.GetValue("PSEdition") as string;
49-
var psFolder = string.Equals(editionType, "Desktop", StringComparison.OrdinalIgnoreCase) ? "WindowsPowerShell" : "PowerShell";
50-
userprofile = Path.Combine(sessionState.PSVariable.GetValue("env:USERPROFILE").ToString(), "Documents", psFolder, "profile.ps1");
48+
var powershellProfile = sessionState.PSVariable.GetValue("PROFILE") as PSObject;
49+
if (powershellProfile == null || !powershellProfile.Members.ToList().Any(a => a.Name.Equals("CurrentUserAllHosts")))
50+
{
51+
throw new NullReferenceException(string.Format(Properties.Resources.ProfilePathNull, "PROFILE.CurrentUserAllHosts"));
52+
}
53+
userprofile = powershellProfile.Members.ToList().Where(a => a.Name.Equals("CurrentUserAllHosts")).First().Value.ToString();
5154
}
5255

5356
else if (Scope != null && Scope.Equals("LocalMachine"))
5457
{
55-
userprofile = Path.Combine(sessionState.PSVariable.GetValue("PSHOME").ToString(), "profile.ps1");
58+
var powershellProfile = sessionState.PSVariable.GetValue("PROFILE") as PSObject;
59+
if (powershellProfile == null || !powershellProfile.Members.ToList().Any(a => a.Name.Equals("AllUsersAllHosts")))
60+
{
61+
throw new NullReferenceException(string.Format(Properties.Resources.ProfilePathNull, "PROFILE.AllUsersAllHosts"));
62+
}
63+
userprofile = powershellProfile.Members.ToList().Where(a => a.Name.Equals("AllUsersAllHosts")).First().Value.ToString();
5664
}
5765

5866
return userprofile;

0 commit comments

Comments
 (0)