-
Notifications
You must be signed in to change notification settings - Fork 3
/
bts-ports.ps1
132 lines (118 loc) · 2.87 KB
/
bts-ports.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#
# declare our parameters: the action to take
#
param(
[string] $action=$(throw 'need action'),
[string] $name,
[string] $status
)
#
# Helper function to list all WMI objects of
# a given type
#
function bts-list-objs($kind)
{
get-wmiobject $kind `
-namespace 'root\MicrosoftBizTalkServer'
}
#
# display all information about a receive port
#
function bts-display-recv-port($port)
{
$portname = $port.Name
$portname
$recvlocs = get-wmiobject MSBTS_ReceiveLocation `
-namespace 'root\MicrosoftBizTalkServer' `
-filter "ReceivePortName='$portName'"
$recvlocs | ft Name, AdapterName, InboundTransportURL, IsDisabled
}
#
# display all information about a send port group
#
function bts-display-send-port-group($group)
{
$groupname = $group.Name
$ports = get-wmiobject MSBTS_SendPortGroup2SendPort `
-namespace 'root\MicrosoftBizTalkServer' `
-filter "SendPortGroupName='$groupName'"
$groupname
foreach ($port in $ports) { "`t" + $port.SendPortName }
}
#
# enable or disable the specified
# receive location
#
function bts-set-recv-loc-status($name, $status)
{
$recvloc = get-wmiobject MSBTS_ReceiveLocation `
-namespace 'root\MicrosoftBizTalkServer' `
-filter "Name='$name'"
switch ( $status )
{
'disable' { [void]$recvloc.Disable() }
'enable' { [void]$recvloc.Enable() }
}
}
#
# controls a send port
#
function bts-set-send-port-status($name, $status)
{
$sendport = get-wmiobject MSBTS_sendPort `
-namespace 'root\MicrosoftBizTalkServer' `
-filter "Name='$name'"
switch ( $status )
{
'start' { [void]$sendport.Start() }
'stop' { [void]$sendport.Stop() }
'enlist' { [void]$sendport.Enlist() }
'unenlist' { [void]$sendport.UnEnlist() }
}
}
function is-valid-opt($check, $options)
{
foreach ( $val in $options )
{
if ( $check -eq $val ) {
return $true
}
}
}
#
# main script
#
switch ( $action )
{
'list-send-ports' {
bts-list-objs('MSBTS_SendPort') | ft Name, PTAddress, Status
}
'list-send-port-groups' {
bts-list-objs('MSBTS_SendPortGroup') | %{ bts-display-send-port-group($_) }
}
'list-recv-ports' {
bts-list-objs('MSBTS_ReceivePort') | %{ bts-display-recv-port($_) }
}
'set-recv-loc-status' {
if ( !(is-valid-opt $status ('enable', 'disable')) )
{
throw 'invalid status'
}
if ( ($name -eq '') -or ($name -eq $null) )
{
throw 'you must supply the receive location name'
}
bts-set-recv-loc-status $name $status
}
'set-send-port-status' {
if ( !(is-valid-opt $status ('start', 'stop', 'enlist', 'unenlist')) )
{
throw 'invalid status'
}
if ( ($name -eq '') -or ($name -eq $null) )
{
throw 'you must supply the send port name'
}
bts-set-send-port-status $name $status
}
}