PoshCode Archive  Artifact Content

Artifact b880f16fca1f9052ce90310dd52e3f188d9f058850cf36980a0a73eacf3c12e0:

  • File isMSDTC.ps1 — part of check-in [1a8263fceb] at 2018-06-10 13:04:15 on branch trunk — Checks whether MSDTC is enabled for network access. By default MSDTC network access is disabled. This feature is needed by SQL Server Linked Servers (user: Chad Miller size: 2367)

# encoding: ascii
# api: powershell
# title: isMSDTC.ps1
# description: Checks whether MSDTC is enabled for network access. By default MSDTC network access is disabled. This feature is needed by SQL Server Linked Servers
# version: 0.1
# type: script
# author: Chad Miller
# license: CC0
# x-poshcode-id: 2027
# x-archived: 2016-11-08T06:00:57
# x-published: 2010-07-28T12:28:00
#
#
#MSDTC is needed by SQL Server Linked Servers
#This script checks whether MSDTC has been configured for network access
#See KB http://support.microsoft.com/default.aspx?scid=kb;en-us;816701 for steps to enable
#All values except AllowOnlySecureRpcCalls should be true
param($computerName=$env:computerName)

#On an x64 system the registry keys for MSDTC will only be accessible from an x64 shell.
#See http://gallery.technet.microsoft.com/ScriptCenter/en-us/6062bbfc-53bf-4f92-994d-08f18c8324c0 for details and workaround
#This script just checks for condition rather than workaround issue.

$is64 = [bool](gwmi win32_operatingsystem -computer $computerName | ?{$_.caption -like "*x64*" -or $_.OSArchitecture -eq'64-bit'})
$isShell32 = [bool]((Get-Process -Id $PID | ?{$_.path -like "*SysWOW64*"}) -or !([IntPtr]::Size -eq 8))

if ($is64 -and $isShell32)
{Write-Warning "Unable to open registry keys because $computerName is running an x64 OS. Script must be run from a PowerShell x64 shell" }
else
{
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computerName)
    $msdtcKey = $reg.OpenSubKey("SOFTWARE\\Microsoft\\MSDTC")
    $securityKey = $msdtcKey.OpenSubKey("Security")
    new-object psobject -property @{ComputerName=$computerName;AllowOnlySecureRpcCalls=[bool]$msdtcKey.GetValue('AllowOnlySecureRpcCalls');TurnOffRpcSecurity=[bool]$msdtcKey.GetValue('TurnOffRpcSecurity');
                      NetworkDtcAccessAdmin=[bool]$securityKey.GetValue('NetworkDtcAccessAdmin');NetworkDtcAccessClients=[bool]$securityKey.GetValue('NetworkDtcAccessClients');
                      NetworkDtcAccessInbound=[bool]$securityKey.GetValue('NetworkDtcAccessInbound');NetworkDtcAccessOutbound=[bool]$securityKey.GetValue('NetworkDtcAccessOutbound');
                      NetworkDtcAccessTransactions=[bool]$securityKey.GetValue('NetworkDtcAccessTransactions');XaTransactions=[bool]$securityKey.GetValue('XaTransactions')}
}