Mark Minasi's Tech Forum
Register Calendar Latest Topics Chat
 
 
 


Reply
  Author   Comment  
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 741
Reply with quote  #1 
I'm trying to automate the connection to Azure RM for CSP
 
I have a few scripts in my profile that allows me connect to several different services, Exchange, O365, Azure EA (Classic and ARM) and Azure CSP ARM.

It all works brilliantly with the other services.
We use ADFS in work, not sure if this is related.
 
The Azure Classic/ ARM connection piece is:

Code:

$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
    "Connect To Azure", {
#azure functionality
"Loading Azure functionality..."
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1"
$cred = Get-Credential
Add-AzureAccount -Credential $cred
 
#Get All Azure Subscription information
 
Import-AzurePublishSettingsFile D:\DropBoxRoot\Dropbox\Powershell\Publish\ClassicIaaS.publishsettings
#Get detailed subscription information
Get-AzureSubscription
},
    "Control+Alt+7"
)
 


Works, allows me connect and all good.
 
Similar thing, I'm trying to automate the connection to Azure RM CSP subscription.
If I run the actions manually, all is good.
But if I try to automate it...

Code:

$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
    "Connect To AzureRM", {
#azure functionality
"Loading Azure functionality..."
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1"
$cred = Get-Credential
Login-AzureRmAccount -Credential $cred
psEdit "D:\ConnectToCustomers\AzureRMConnections.ps1"
},
    "Control+Alt+9"
)


But this throws an error when I try to connect to a Subscription

Code:

PS C:\> # Connect to MickeyMouse Azure RM
$TenantID=”MickeyMouse.onmicrosoft.com”
$SubscriptionID=”01234567-6eac-1111-2222-222222223333”
Select-AzureRmSubscription -SubscriptionID $SubscriptionID -TenantId $TenantID
Select-AzureRmSubscription : Provided subscription 01234567-6eac-1111-2222-222222223333 does not exist
At line:4 char:1
+ Select-AzureRmSubscription -SubscriptionID $SubscriptionID -TenantId $TenantID
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmContext], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand


Any ideas?

__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
Infradeploy

Avatar / Picture

Senior Member
Registered:
Posts: 165
Reply with quote  #2 
What do you get if you do 'get-azurermsubscription' in the script?
__________________
Have SpaceSuit, Will Travel

0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 741
Reply with quote  #3 
After running the script, get-azurermsubscription gives me a list of my EA subscriptions!


__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
Infradeploy

Avatar / Picture

Senior Member
Registered:
Posts: 165
Reply with quote  #4 
I filter get-subscrtiotion by name and pipe it to select-subscription. That works..
__________________
Have SpaceSuit, Will Travel

0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 741
Reply with quote  #5 
OK, I think my problem is as follows:
I have my work account.
This is linked to the EA Account and used to manage the EA customers.
I also have CSP customers and get in on that account.
When I log into AzureRM, the subscriptions I see are the EA subscriptions.
I cannot see any of the CSP subscriptions.

Hummmm



__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #6 
Quote:
Originally Posted by wobble_wobble
OK, I think my problem is as follows:
I have my work account.
This is linked to the EA Account and used to manage the EA customers.
I also have CSP customers and get in on that account.
When I log into AzureRM, the subscriptions I see are the EA subscriptions.
I cannot see any of the CSP subscriptions.

Hummmm




Is it being cached on a different profile..?

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 741
Reply with quote  #7 
no idea....
How do I clear it and not delete my user profile?


__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 741
Reply with quote  #8 
So its two steps forward and three back...

How can I tell when I'm using powershell, who I'm logged in as against Azure or Office 365 for that matter.
In linux I can see my logon name and location.
In powershell, whoami gives me local computer and username - not a great deal of use.

Can't find another command to tell me the info I'm looking for.

Also, how do I disconnect from a Azure Powershell session?
I have been using 
Code:

exit-PSSession


which I don't think works.




__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #9 
Quote:
Originally Posted by wobble_wobble
So its two steps forward and three back...

How can I tell when I'm using powershell, who I'm logged in as against Azure or Office 365 for that matter.
In linux I can see my logon name and location.
In powershell, whoami gives me local computer and username - not a great deal of use.

Can't find another command to tell me the info I'm looking for.

Also, how do I disconnect from a Azure Powershell session?
I have been using 
Code:
 exit-PSSession 


which I don't think works.





perhaps this will help

Code:

Get-PSSession | ForEach {$_.Name +”  ” +  $_.Runspace.OriginalConnectionInfo.Credential.UserName}


Found here - https://blogs.technet.microsoft.com/rmilne/2016/09/19/remote-powershell-pssession-whoami/


Similar here -

https://automationnext.wordpress.com/2015/03/18/azure-automation-who-am-i/


I will be able to test later tonight...



__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 741
Reply with quote  #10 
No Tim, not showing a user, or showing the session even.

Code:

PS C:\Users\Administrator> Get-PSSession | ForEach {$_.Name +”  ” +  $_.Runspace.OriginalConnectionInfo.Credential.UserName}
PS C:\Users\Administrator> get-pssession
PS C:\Users\Administrator> Get-PSSession
PS C:\Users\Administrator> [System.Security.Principal.WindowsIdentity]::GetCurrent()

AuthenticationType : NTLM
ImpersonationLevel : None
IsAuthenticated    : True
IsGuest            : False
IsSystem           : False
IsAnonymous        : False
Name               : JOE2012\Administrator
Owner              : S-1-5-32-544
User               : S-1-5-21-aaabbbcccddd
Groups             : {S-1-5-21-aaabbbcccddd, S-1-aaabbbcccddd, S-1-5-aaabbbcccddd, S-1-5-21-aaabbbcccddd...}
Token              : 4624
AccessToken        : Microsoft.Win32.SafeHandles.SafeAccessTokenHandle
UserClaims         : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: JOE2012\Administrator, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid: 
                     S-1-5-21-aaabbbcccddd, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarygroupsid: S-1-5-21-99aaabbbcccddd, 
                     http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-21-99aaabbbcccddd...}
DeviceClaims       : {}
Claims             : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: JOE2012\Administrator, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid: 
                     S-1-5-21-9aaabbbcccddd, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarygroupsid: S-1-5-21-9aaabbbcccddd, 
                     http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-21-9aaabbbcccddd...}
Actor              : 
BootstrapContext   : 
Label              : 
NameClaimType      : http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
RoleClaimType      : http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid


PS C:\Users\Administrator> [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
LT2012\Administrator

__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation: