Skip to content

Commit 5f1dcd5

Browse files
authored
Merge pull request #38 from maddieclayton/release-2018-08-24
fix alias
2 parents b69e167 + 1df60d2 commit 5f1dcd5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-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 PSInvalidOperationException(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 PSInvalidOperationException(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;

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,7 @@
420420
<data name="AliasImportFailure" xml:space="preserve">
421421
<value>LocalMachine scope can only be set in PowerShell administrative mode.</value>
422422
</data>
423+
<data name="ProfilePathNull" xml:space="preserve">
424+
<value>Unable to set profile because environment variable '${0}' is null.</value>
425+
</data>
423426
</root>

0 commit comments

Comments
 (0)