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

June 29, 2012 6 comments

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.

Categories: Windows Server Tags: ,

Interviewed by Steef-Jan Wiggers (BizTalk MVP)

June 20, 2012 1 comment

I would like to thank Steef-Jan for taking his time and posting my interview on his site:


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

April 17, 2012 Leave a comment

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

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

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

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

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

function Get-DbDataTable
	[string]$providerName = "System.Data.SqlClient"	
	$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

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

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

March 1, 2012 Leave a comment

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";
			 "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
Categories: Powershell Tags: ,

[Powershell] Missing shared custom modules when using Powershell Remoting

February 27, 2012 Leave a comment

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:


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.

Categories: Powershell Tags: , ,

[Powershell] Centralize Powershell Script (Modules) Repository

February 27, 2012 1 comment

In this post I will try to describe on how you can centralize your powershell scripts (custom modules) so that it can be  loaded from any servers in the system.

Note: The sample below is using Powershell v2.0 and is intended for Windows Server 2008 and up.

Centralize Powershell Repository Diagram:

Centralize Powershell Scripting Diagram

In this diagram it states that there are 3 custom modules on the powershell scripting server that can be loaded from any of the servers in the network.

Powershell Server Setup Steps:

Necessary steps needs to be undertaken to the Powershell Server is as follows:

1. Create a shared folder in the PS Server that will contain all the custom modules. Assign appropriate permissions.

2. Create/move custom modules in the shared folder. On instructions on how to create a custom module, click here.

Quick Guide: Creating Custom Powershell Module

Creating a custom script module is quite easy, you just need to create a psd1 file (contains manifest information) and psm1 file (basically contains the dot sourcing of all scripts you want to load in the module) and place it in a folder with name equal to the module name.

Sample Folder structure: The C:\Modules will be setup as shared folder.

Contents of Sample.psd1 file

# Module manifest for module 'Sample'
# Generated by: Randy Aldrich Paulo
# Generated on:


# Script module or binary module file associated with this manifest
ModuleToProcess = 'Sample.psm1'

# Version number of this module.
ModuleVersion = '1.0'

# ID used to uniquely identify this module
GUID = 'c78688f252-fc04-413a-8b0e-5cfc7e78dcd6'

# Author of this module
Author = 'Randy Aldrich Paulo'

# Company or vendor of this module
CompanyName = 'My Company'

# Copyright statement for this module
Copyright = '(c) 2012 Randy Paulo.'

# Description of the functionality provided by this module
Description = 'Description'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''

# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = ''

# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module
ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = @()

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# List of all modules packaged with this module
ModuleList = @()

# List of all files packaged with this module
FileList = 'DataMgtDeployment.psm1'

# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''


Contents of Sample.psm1 file

# DataMgtDeployment Module

$ModulePath = \\PowershellServer\Modules\Sample
# Set the location
Set-Location $ModulePath

# Reference the Scripts
. .MyFunction.ps1
. .MyFunction2.ps1

3. Update System Variable PSModulePath to include the location of custom modules

Right Click Computer -> Propeties -> Advanced Settings -> Environment Variables -> Add a semi-colon (;) at the end and add the path of the custom module (Ex. C:\Modules)

4.  To test whether the setup is correct, run the Powershell Command Prompt (As Administrator) and type:

Get-Module -ListAvailable

It should display your custom module.


Server(s) Setup Steps:

After the module is properly setup you can now load it on any servers on the network once the following setup steps have been performed:

1. Update System Variable PSModulePath to include the location of custom modules (shared folder)

Right Click Computer -> Propeties -> Advanced Settings -> Environment Variables -> Add a semi-colon (;) at the end and add the path of the custom module (Ex. \\PowershellServer\Modules)

2. Since we are loading the module from a shared location we need to change the execution policy to RemoteSigned. For information about execution-policy see: About Execution Policy. Execute the following script (as Administrator):

Set-ExecutionPolicy RemotedSigned -force

3. After step 2, when you try to load the custom module it will still throw an exception, to solve the problem we need to add the path of shared folder to the list of trusted sites.

Open Internet Explorer -> Tools -> Internet Options -> Go to Security Tab

Click Trusted Sites -> Sites -> In the add type: file://PowershellServer (replace it with actual servername)

Click Add -> Close -> Ok.

Now you can load the custom module from remote powershell server into any of the servers in the network (as long as you did the Server(s) Setup Steps.

Using the shared custom module in powershell remoting is possible but you need to update some settings see my next blog: [Powershell] Missing shared custom modules when using Powershell Remoting

Categories: Powershell Tags:
%d bloggers like this: