BTDF: System.OutOfMemoryException while deploying using Powershell Remoting

Recently when I tried to deploy a BizTalk solution packaged with BTDF (BizTalk Deployment Framework) in combination with Powershell Remoting I encountered this error:

Error: Failed to add resource(s).

Change requests failed for some resources.

BizTalkAssemblyResourceManager failed to complete end type change request.

Exception of type ‘System.OutOfMemoryException’ was thrown.

 

I checked the memory on the remote server and even restarted it but it didn’t help, I still encounter this error.

As it turns out, as well as I’ve suspected it’s the memory of the powershell. To increase the size of the memory, run the PowerShell Command prompt on the target server and enter the ff:

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 512

Or set it even to higher.

 

 

Advertisements

NFS: How to connect to NFS using Windows Server 2008 R2 without using User Mapping Server

When connecting to NFS shared folder the windows credentials needs to be mapped to a equivalent unix account+ group. 

In Windows Server 2008 R2 the support for User Mapping is dropped and the same functionality can only be achived using Identity Management for Unix Components (extension schema for Active Directory).

Below describes on how you can connect to a NFS folder without using User Mapping Server.

A. Install NFS Client

Step 1. Enable File Services Role. Go to Server Management – > Add Roles -> File Services

Step 2. Install Services for Network File System. Go to File Services – > Add Role Services

 

B. Update NFS Client Registry

In this step, we are going to map the anonymous user credential to the unix account credential that you’ll be using to connect to NFS share. First you need to get the User Id and Group Id of the unix account from the unix administrator. It should be of decimal value like: UserId= 6500000 GroupId=4200. Once you have it, we can proceed.

1. Open Regedit.

2. Go to \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default.

3. Create 2 DWORD value, one for AnonymousUid with decimal value=<User Id> and another for AnonymousGid with decimal value=<GroupId>.

It should look like this:

4.  Restart the NFS Client. Go to Administrative Tools -> Services for Network File System (NFS) ->

C. Test NFS Connection

1. Open command prompt.

2. Type:  mount -u:<UserName and not UserId> -p:<Password> <SharedNFSFolder> <drive letter to mount, Ex: J:>

3. dir <drive letter:>

Copy file to this NFS folder. This is only way to confirm that the registry hacking is successfully. Because by default if the anonymous access is turned on in NFS side, you can see the files without having to supply user/password.

Note: Limitation is that, you can only connect to a single NFS share because it would use the same UserId and Group Id everytime you connect.

BizTalk Property Promotion : MessageDataPropertyBase vs MessageContextPropertyBase

When adding a property schema that can either be used for content-based routing (CBR) or just to hold metadata information about a message in BizTalk we are confronted which Property Schema Base to use:

1. MessageDataPropertyBase
2. MessageContextPropertyBase or
3. PartContextPropertyBase

Answer is quite simple:

If the promoted property can be found in the source (incoming) message you need to use MessageDataPropertyBase.

If the property can be set in envelop, pipeline or manually promoted in the orchestration using Correlation Sets then MessageContextPropertyBase is used.  This is also a useful technique if we want to maintain the original structure of the message and at the same time inject some properties that can be used in tracking or routing.

Lastly, suppose if I have a source message without a namespace and I need to map it to my internal schema with promoted properties how will I do it?

1. Create a custom receive pipeline with Set Namespace in Component in Decode Stage. Add an XML Disassembler with schema equals to the source schema with the expected namespace.

2. Add a Map, map source to internal schema (this should contain attribute/fields that will be promoted).

3. Add a Property Schema, question is, which Property Schema based to use?

4. Update internal schema to map the fields to promoted properties.

Note: I used  MessageContextPropertyBase in Step # 3 and it works.

[Powershell] Executing an sql query and returning a disconnected data using Powershell

Below is a script that will execute an sql query and returns a disconnected data (DataTable) using Powershell.

<#
.SYNOPSIS
	Queries a data source and returns a disconnected data (DataTable)

.DESCRIPTION
	Queries a data source and returns a disconnected data (DataTable)

.NOTES
	File Name: Get-DbDataTable.ps1
	Author: Randy Aldrich Paulo

.EXAMPLE
	Get-DbDataTable "Data Source=.;Integrated Security=SSPI;Initial Catalog=DatabaseName" "SELECT TOP 10 * From Table1"
#>

function Get-DbDataTable
(
	[string]$connectionString,
	[string]$query,
	[System.Data.CommandType]$commandType=[System.Data.CommandType]::Text,
	[string]$providerName = "System.Data.SqlClient"	
)
{
	#Initialize
	$databaseFactory = [System.Data.Common.DbProviderFactories]::GetFactory($providerName)
	$dbConnection = $databaseFactory.CreateConnection()
	$dbConnection.ConnectionString = $connectionString

	#Create Command
	$dbCommand = $databaseFactory.CreateCommand()
	$dbCommand.Connection = $dbConnection
	$dbCommand.CommandText =$query
	$dbCommand.CommandType = $commandType

	#Create Data Adapter
	$dbAdapter = $databaseFactory.CreateDataAdapter();
	$dbAdapter.SelectCommand = $dbCommand

	$dataTable = New-Object System.Data.DataTable

	try
	{
		#Fill with Results
		$dbAdapter.Fill($dataTable)
	}
	catch { 
		throw 
		}
	finally { 
			if($dbConnection.ConnectionState -ne [System.Data.ConnectionState]::Closed) 
			{ 
				$dbConnection.Close() 
			}
		}
	return $dataTable
}

[Powershell] Calling NET USE to create shared folders on remote server using Powershell

Below is the powershell script sample on how to call NET USE command to create a shared folder on any remote server.


$netShareSettings+= @{	"Server"="TargetServer";
                         "Path"="E:\MyFolderToBeShared";
			 "ShareName" = "SharedFolder";
			  "UserAndPermission" = ("Domain\user1;FULL","Domain\User2;FULL");
		      }

foreach($netShareSetting in $netShareSettings)
  {

   $script =
     {

	$userParam = "";

	foreach($pm in $args[0].UserAndPermission)
	{
		$arr = $pm.Split(";");
		$userName = $arr[0];
		$perm = $arr[1];
		$userParam+= "/grant:`"{0}`,{1}`" " -f $userName, $perm
	}

	$command = "net share {0}=`"{1}`" {2}" -f $args[0].ShareName,$args[0].Path, $userParam
	$msg = " Executing Command: '{0}' on '{1}'" -f $command,$args[0].Server
	$msg = Invoke-Expression $command | Out-String
	$msg = "  Results: " + $msg.Trim();
	Write-Host $msg

     }

     Invoke-Command -ScriptBlock $script -ComputerName $netShareSetting.Server -ArgumentList $netShareSetting
  }

[Powershell] Missing shared custom modules when using Powershell Remoting

In my previous post: Centralize Powershell Script (Modules) Repository, it describes on how to create a custom module and load it on any server. And like the title of this post indicated when you try to connect to a remote server using Powershell remoting, you’ll notice that the custom module is missing ( More information about Powershell Remoting ). This is  because it’s doing a double-hop, First hop is to connect to server (using Enter-PSSession or New-PSSession), next hop is to access the shared folder containing the custom module.

To solve this issue we need to Enable the Credential Service Security Provider (CredSSP) both on remote and host server.

#1 On the server wherein the powershell console instance is started you need to enable the client role.

#2 On the server wherein you want to connect remotely you need to enable server role.

#3 On the server wherein the powershell script is hosted you also need to enable the server role.

Run the following scripts (Run as Administrator):

Script for # 1:
Enable-WSManCredSSP -role Client -DelegateComputer <name of remote server> -force
Script for # 2:
Enable-WSManCredSSP -role Server -force
Script for # 3:
Enable-WSManCredSSP -role Server -force

Powershell remoting with CredSSP:

To connect either by Enter-PSSession or New-PSSession you need to supply extra argument:

$session = New-PSSession -ComputerName <name of remote server> -Authentication CredSSP -Credential Get-Credential

Since i used Get-Credential it would prompt for credential:

Update:

If it still doesn’t work, try restarting the Windows Remote Management (WS-Management) service.

In Run Type, services.msc

In the Name look for: Windows Remote Management (WS-Management), right click Restart.