-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Automatic Context Autosave
Profile cmdlets are changing to support persistence of credentials between branches. Changes to cmdlets are described below.
The main behavior change is that context information and credential will be automatically saved to disk when the user opts in to autosave, and that users will be able to use PowerShell jobs without having to perform separate authentication within the job.
Controls whether the context is automatically saved to the default location. Default is 'false'
$env:Azure_Profile_Autosave="true" | "false"
Allow scoping the login, so it can affect only the process or the currrent user
Add-AzureRmAccount
Import-AzureRmContext
Allow changing existing named contexts
Set-AzureRmContext -InputObject <IAzureContext> [-Name <string>] [-Subscription(SubscriptionId, SubscriptionName) <nameOrId>] [-Tenant(TenantId, DomainName) string] [-StorageAccount <string>] [-WhatIf] [-Confirm]
Set-AzureRmContext [-Name <string>] [-Subscription(SubscriptionId, SubscriptionName) <nameOrId>] [-Tenant(TenantId, DomainName) string] [-StorageAccount <string>] [-WhatIf] [-Confirm]
Allow saving the context between PowerShell sessions. Any changes will by default change the global context
Enable-AzureRmContextAutosave [-Scope Process | CurrentUser] [-WhatIf] [-Confirm]
Turn off autosaving the context. When new powershell windows are opened, each will have to log in.
Disable-AzureRmContextAutosave [-Scope Process | CurrentUser] [-WhatIf] [-Confirm]
Select a context as the default
Select-AzureRmContext -Name <string> [-Scope Process | CurrentUser] [-WhatIf] [-Confirm]
Remove a named context
Remove-AzureRmContext [-Name <string>] [-WhatIf] [-Confirm]
Rename an existing context, to make it easire to re-use later
Rename-AzureRmContext [-Name <string>] [-WhatIf] [-Confirm]
New-AzureRmWidget [-AzureRmContext(AzureCredentials, AzureRMProfile) <IAzureContextContainer>]
If context autosave is turned on, you can excute a cmdlet as a job, return immediately, and process the results later
$job = Start-Job {New-AzureRmVM ...}
... cmdlets...
Receive-Job $job
Whether or not context autosave is anabled, you can pass in the results of a login, or a context to a job as a parameter:
$job = Start-Job {param ($ctx) New-AzureRmVM -AzureRmContext $ctx ...} -ArgumentList (Get-AzureRmContext "myContextName")
... cmdlets...
Receive-Job $job
Profile provider will acquire a read lock when first populating the ContextContainer, and drop it afterward.
Each cmdlet which changes the context (Add-Account, Import-Context, Set-Context, Select-Context, Remove-Context) will
- if operating at the CurrentUser scope, acquire a write lock, read the persisted data, make appropariate changes, write the data, and drop the write lock
- if operating at the Process scope, make the changes in memory
TokenCache will operate independently from cmdlets.
- If operating with ContextAutoSaveDisabled scope Cache is saved in the context
- If operating with ContextAutoSaveEnabled, Cache is saved in a file