PoshCode Logo PowerShell Code Repository

isMSDTC.ps1 by Chad Miller 18 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2027"></script>download | new post

Checks whether MSDTC is enabled for network access. By default MSDTC network access is disabled. This feature is needed by SQL Server Linked Servers

  1. #MSDTC is needed by SQL Server Linked Servers
  2. #This script checks whether MSDTC has been configured for network access
  3. #See KB http://support.microsoft.com/default.aspx?scid=kb;en-us;816701 for steps to enable
  4. #All values except AllowOnlySecureRpcCalls should be true
  5. param($computerName=$env:computerName)
  6.  
  7. #On an x64 system the registry keys for MSDTC will only be accessible from an x64 shell.
  8. #See http://gallery.technet.microsoft.com/ScriptCenter/en-us/6062bbfc-53bf-4f92-994d-08f18c8324c0 for details and workaround
  9. #This script just checks for condition rather than workaround issue.
  10.  
  11. $is64 = [bool](gwmi win32_operatingsystem -computer $computerName | ?{$_.caption -like "*x64*" -or $_.OSArchitecture -eq'64-bit'})
  12. $isShell32 = [bool]((Get-Process -Id $PID | ?{$_.path -like "*SysWOW64*"}) -or !([IntPtr]::Size -eq 8))
  13.  
  14. if ($is64 -and $isShell32)
  15. {Write-Warning "Unable to open registry keys because $computerName is running an x64 OS. Script must be run from a PowerShell x64 shell" }
  16. else
  17. {
  18.     $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computerName)
  19.     $msdtcKey = $reg.OpenSubKey("SOFTWARE\\Microsoft\\MSDTC")
  20.     $securityKey = $msdtcKey.OpenSubKey("Security")
  21.     new-object psobject -property @{ComputerName=$computerName;AllowOnlySecureRpcCalls=[bool]$msdtcKey.GetValue('AllowOnlySecureRpcCalls');TurnOffRpcSecurity=[bool]$msdtcKey.GetValue('TurnOffRpcSecurity');
  22.                       NetworkDtcAccessAdmin=[bool]$securityKey.GetValue('NetworkDtcAccessAdmin');NetworkDtcAccessClients=[bool]$securityKey.GetValue('NetworkDtcAccessClients');
  23.                       NetworkDtcAccessInbound=[bool]$securityKey.GetValue('NetworkDtcAccessInbound');NetworkDtcAccessOutbound=[bool]$securityKey.GetValue('NetworkDtcAccessOutbound');
  24.                       NetworkDtcAccessTransactions=[bool]$securityKey.GetValue('NetworkDtcAccessTransactions');XaTransactions=[bool]$securityKey.GetValue('XaTransactions')}
  25. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me