Persist/Save Azure login credentials in a PowerShell session

When working with Azure its very common to open multiple PowerShell windows in order to execute multiple PS scripts in parallel to get the work done faster. One of the repetitive task we have to do is to login to Azure portal in each new PS window.

In order to avoid the above mentioned hassle we can save the Azure login credentials to a json file and re-use it across multiple PS sessions/windows. The save credentials are valid for 12 hours.

#Login to Azure subscription
Login-AzureRmAccount

#If you have multiple subscriptions associated with the login, view all subscriptions
Get-AzureRmSubscription

#Select the subscription for the current session
Select-AzureRmSubscription -SubscriptionId <guid of Azure subscription>

#Save the credentials to a json file
Save-AzureRmProfile -Path C:\Projects\AzureLogin.json

Once the credentials are saved using the above procedure, whenever you open a new PS window you can re-user the credentials as below;

#select the persisted Azure credentials from the json file (in new PowerShell window)
Select-AzureRmProfile -Path C:\Projects\AzureLogin.json

Usage and Health Data Collection Proxy : Stopped

After installing and configuring SharePoint 2010 farm and if you notice that the “Usage and Health Data Collection Proxy” is still in the stopped state, follow the below to provision it.

Run the following PowerShell command to view the GUID of the service

Get-SPServiceApplicationProxy

image

Copy the Id of the SSA “WSS_UsageApplication”

Execute the following by replacing the GUID copied from above output.

$UP = Get-SPServiceApplicationProxy | where {$_.ID -eq "<GUID of the WSS_UsageApplication>"}

$UP.Provision()

image

 

Now check the service status from central admin site.

image

How to convert a windows user name to claims user name using PowerShell

#read the user name

$claimsUserID = read-host -prompt ‘Enter windows user name in format DOMAIN\UserName :’

#convert the user name to claims id
$claimsUserID = New-SPClaimsPrincipal -Identity $claimsUserID -IdentityType WindowsSamAccountName

$claimsUserID = $claimsUserID.ToEncodedString()

#display the claims id
write-host ‘Claims user ID is ‘ $claimsUserID