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

SharePoint online (o365) add-in workflow – AppOnlySequence

If you are going to use “AppOnlySequence” workflow activity in a SP add-in, make sure you follow the below activities in order to grant the required permission by the workflow to execute successfully. If you have missed any of the steps, then the workflow will be suspended with the error “Exception: Access denied. You do not have permission to perform this action or access this resource.”

Step 1:

Enable the feature “Workflows can use app permissions” at site level (site settings -> site actions -> manage site features):

image1

Step 2:

In visual studio open AppManifest.xml and grant the app “Manage” permission.

image2

Step 3:

Tick the option “Allow the app to make app-only calls to SharePoint”

image3

You can also update the raw xml of AppManifest.xml with AllowAppOnlyPolicy=”true” instead of using the VS designer.

XML :

<AppPermissionRequests AllowAppOnlyPolicy=”true”>
<AppPermissionRequest Scope=”http://sharepoint/content/sitecollection/web&#8221; Right=”Manage” />
</AppPermissionRequests>

The Variations Create Hierarchies job failed

 

If you get the following message in variations logs (Site Actions –> Site Settings –> Site Collection Administration –> Variation Logs)  when the “Variations Create Hierarchies Job Definition” executed, it could be due to missing language packs.

“The Variations Create Hierarchies job failed with the following error message: File or arguments not valid for site template ‘CMSPUBLISHING#0’. Parameter name: WebTemplate.”

When installing a language pack in SharePoint 2010 Server make sure the following is followed.

Lets say for “Spanish” language pack

  1. Download SPF 2010 Spanish language pack from http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=646e311a-aaf3-4d30-b03c-2f3c70d19a22
  2. Install the Spanish language pack.
  3. Run the SP configuration wizard.
  4. Download MOSS 2010 Server Spanish language pack from http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=046f16a9-4bce-4149-8679-223755560d54
  5. Repeat step 2 & 3

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

SharePoint 2010 Managed Accounts

When you try to add a managed account to SharePoint 2010, it was throwing a error

“The specified user DOMAIN\SPFASTContentAdmAppPool could not be found. Some or all identity references could not be translated.”

But the user exists in the active directory. When I investigate further I found out that SharePoint does not accept user names which are more than 20 characters in length.

So new rule to the pre-installation documentation. “Manage account ids should be less than 20 characters”.

image

Publishing Pages : check-in file programmatically

One of the common scenarios when working with content migration is to handle the files checked out by other users. Following code is written to check-in all files check out by any users.

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter site url");
            
            using (SPSite site = new SPSite(Console.ReadLine()))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    PublishingPageCollection publishingPages 
= PublishingWeb.GetPublishingWeb(web).GetPublishingPages(); foreach (PublishingPage page in publishingPages) { SPFile file = page.ListItem.File; if (file.CheckedOutByUser != null) { Console.WriteLine("The page {0} is check out by
user {1}. Check-in in to take control."
,
file.Title, file.CheckedOutByUser); file.CheckIn("checked in by script",
SPCheckinType.MajorCheckIn); SPModerationInformation moderationInformation
= page.ListItem.ModerationInformation; if (moderationInformation.Status
== SPModerationStatusType.Pending) { file.Approve("Approved by script"); } if (moderationInformation.Status
== SPModerationStatusType.Draft) { file.Publish("Published using script"); file.Approve("Approved by script"); } } } } } } }

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

Nintex workflow: Extract and save InfoPath form embedded attachments into a document library

Following workflow will extract InfoPath embedded attachments and save it to a given document library in the same site collection. I have created a very simple InfoPath form to demonstrate this.

 

The below workflow supports extract single attachment or multiple attachments from the same InfoPath form. I am using Title field value to create the folder name. This can change based on the requirement.

 

Following are the detail configurations of the workflow activities. I think the above flow is self explaining and I don’t need to detail it J

Steps:

  1. Read title value from InfoPath form:

     

  2. Check whether there is a folder exists in a give document library with a name equal to title

     

  3. If the folder does not exists create the folder in the document library
  4. Get the path to the destination folder. In other words path the folder created in the above step.
  5. Extract and copy attachments from InfoPath form into folder inside document library

     

  6. This step I am writing some debug info into workflow history list.

 

This is just a quick post, so my explanations are very minimal. If you all have any questions or ideas please leave a comment.

 

Bind an “Image” column to a WPF DataGrid (XCEED)

Last week I was evaluating Xceed WPF grid & it was awesome. My objective is to connect the HR database with a nice sexy WPF application, so any employee in the company can search on other employees in style J

First you need to write a converter to convert the byte[] stream to a BitmapImage.

public
object Convert(object value, Type targetType, object parameter, CultureInfo culture)

{

 


Byte[] bytes = value as
Byte[];


MemoryStream mem = new
MemoryStream(bytes);

mem.Write(bytes, 0, bytes.Length);

mem.Seek(0, SeekOrigin.Begin);


BitmapImage image = new
BitmapImage();

 

image.BeginInit();

image.DecodePixelWidth = 60;

image.CacheOption = BitmapCacheOption.OnLoad;

image.StreamSource = mem;

image.EndInit();


return image;

 

}

 


public
object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

{

     return
null;

}

 

#endregion

}

Then do the xaml…….. That’s it. I hope I don’t have to show the code behind how to to the databind J

 

<Window x:Class=”Brandix.Employees”


xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;


xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;


xmlns:converters=”clr-namespace:Brandix”


Title=”Employees” Height=”600″ Width=”800″ xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221; Loaded=”Window_Loaded”>


<Window.Resources>


<converters:ImageConverter x:Key=”imageConverter” />


</Window.Resources>


<Grid>


<xcdg:DataGridControl Height=”160″ HorizontalAlignment=”Left” Name=”dgEmployees” VerticalAlignment=”Top” Width=”Auto” AutoCreateColumns=”False”>


<xcdg:DataGridControl.View>


<xcdg:CardflowView3D />


</xcdg:DataGridControl.View>


<xcdg:DataGridControl.Columns>


<xcdg:Column FieldName=”epic_picture” ReadOnly=”True” Title=”Picture” IsMainColumn=”True”>


<xcdg:Column.CellContentTemplate>


<DataTemplate>


<Image Source=”{xcdg:CellEditorBinding Converter={StaticResource imageConverter}}” />


</DataTemplate>


</xcdg:Column.CellContentTemplate>


</xcdg:Column>


</xcdg:DataGridControl.Columns>


</xcdg:DataGridControl>


</Grid>

</Window>