Remote execution of PowerShell script on BizTalk servers - biztalk

I am trying to run a PowerShell script to return the status of host instances on a BizTalk server from my local machine. When I tried this script from the BizTalk server I am able to get the information, however I am not able to run that script using invoke command.ps remoting is already enabled because I can run a basic write-host using the invoke command. No result is getting displayed when I run it remotely. The script I used and the output I am getting are below.
Invoke-command -ComputerName XXXXXXXXXXXXXX -ScriptBlock{
write-host "HELLO"
Write-Host "`nHost Instance Information ("$hostInstances.Count")" -fore DarkGray
foreach ($hostInstance in $hostInstances) {
switch ($hostInstance.servicestate) {
1 { $hostInstanceState = "Stopped" }
2 { $hostInstanceState = "Start pending" }
3 { $hostInstanceState = "Stop pending" }
4 { $hostInstanceState = "Running" }
5 { $hostInstanceState = "Continue pending" }
6 { $hostInstanceState = "Pause pending" }
7 { $hostInstanceState = "Paused" }
8 { $hostInstanceState = "Unknown" }
}
switch ($hostInstance.HostType) {
1 { $hostInstanceType = "In-process" }
2 { $hostInstanceType = "Isolated" }
}
if ($hostInstanceState -eq "Running") {
Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
Write-Host $hostInstanceState -fore green
}
elseif ($hostInstanceState -eq "Stopped") {
if ($hostInstance.IsDisabled -eq $true ) {
Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
Write-Host $hostInstanceState "(Disabled)" -fore red
}
else {
Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
Write-Host $hostInstanceState -fore Red
}
}
else {
if ($hostInstanceType -eq "In-process") {
Write-Host $hostInstance.hostname "($hostInstanceType)" "- " -NoNewline
Write-Host $hostInstanceState "(Disabled:$($hostInstance.IsDisabled))" -fore DarkYellow
}
else {
Write-Host $hostInstance.hostname "($hostInstanceType)"
}
}
}
}
Output is :
PS C:\windows\system32> C:\Users\SRamadugu\Desktop\bizzzzz.ps1
HELLO
Host Instance Information ( )
()
Tracking Host(s)

Have you enabled Powershell Remote Commands on your BizTalk server?
Powershell Remoting

You have to import module BizTalkFactory.PowerShell.Extensions.dll on remote:
Invoke-command -ComputerName XXXXXXXXXXXXXX -ScriptBlock {
Import-Module $remoteBizTalkPowerShellExtensionsPath -force
...

Related

how to make kamailio serial forking?

######################################################################################
I am a beginner in kamailio server development, and I want to make serial forking, but that doesn't work.
My kamailio server replies Too Many Hops (code: 483) and end the call.
can someone helps me please.
######################################################################################
I use this code :
request_route {
# per request initial checks
route(REQINIT);
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans()) {
t_relay();
}
exit;
}
# handle retransmissions
if (!is_method("ACK")) {
if(t_precheck_trans()) {
t_check_trans();
exit;
}
t_check_trans();
}
if (is_method("INVITE|SUBSCRIBE")) {
record_route();
}
if(is_method("REGISTER"))
save("location");
# test serial forking
if (method=="INVITE") {
if(!t_is_set("branch_route")) route(SERIAL);
};
if(lookup("location")){
if (!t_relay()) {
sl_reply_error();
}
exit;
}
}
route[SERIAL]{
$ru = "sip:1001#192.168.50.131:5060";
xlog("ALERT : new request uri $ru \n");
t_on_failure("1");
t_relay();
}
failure_route[1] {
if(t_is_canceled()) {
exit;
}
xlog(" an other alternative \n");
if(t_check_status("486|408")){
$ru = "sip:1002#192.168.50.131:5060";
xlog(" an other uri $ru \n");
t_on_failure("2");
t_relay();
exit;
}
}
failure_route[2] {
if(t_is_canceled()) {
exit;
}
xlog( "nobody available \n");
t_reply("500", "Server error");
}
# Per SIP request initial checks
route[REQINIT] {
# no connect for sending replies
set_reply_no_connect();
#!ifdef WITH_ANTIFLOOD
# flood detection from same IP and traffic ban for a while
# be sure you exclude checking trusted peers, such as pstn gateways
# - local host excluded (e.g., loop to self)
if(src_ip!=myself) {
if($sht(ipban=>$si)!=$null) {
# ip is already blocked
xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
exit;
}
if (!pike_check_req()) {
xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
$sht(ipban=>$si) = 1;
exit;
}
}
#!endif
if($ua =~ "friendly-scanner|sipcli|sipvicious|VaxSIPUserAgent") {
# silent drop for scanners - uncomment next line if want to reply
# sl_send_reply("200", "OK");
exit;
}
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if(is_method("OPTIONS") && uri==myself && $rU==$null) {
sl_send_reply("200","Keepalive");
exit;
}
if(!sanity_check("17895", "7")) {
xlog("Malformed SIP request from $si:$sp\n");
exit;
}
}
Problem is that in your config your serial forking route runs before looking into Kamailio location DB. So after first fork to 1001#192.168.50.131 you need somehow to route call to part where Kamailio looks into location DB, in default config it is route(LOCATION). Something like this:
route[SERIAL]{
$ru = "sip:1001#192.168.50.131:5060";
xlog("ALERT : new request uri $ru \n");
t_on_failure("1");
route(location);
}
Don't forget to add route(location) to your config.

How to get network connection status in apple watch standalone application?

Using NWPathMonitor, I get network information in watch simulator (with usesInterfaceType) and it showing right status, but in real device it's not working. It alway showing no network. I developed independent watch application. Please check below code that I write for this:
let monitor = NWPathMonitor()
monitor.pathUpdateHandler = { path in
if path.status == .satisfied {
print("We're connected!")
if path.usesInterfaceType(.wifi) {
print("It's WiFi!")
} else if path.usesInterfaceType(.cellular) {
print("3G/4G FTW!!!")
} else if path.usesInterfaceType(.wiredEthernet) {
print("wiredEthernet")
}else if path.usesInterfaceType(.loopback) {
print("loopback")
}else if path.usesInterfaceType(.other) {
print("other")
}
}
else {
print("No connection.")
}
}
let queue = DispatchQueue(label: "InternetConnectionMonitor")
monitor.start(queue: queue)

how to determine if the mount successful in QT code

I have this function on mounting a smb:// connection. What if there is an error that is not in my condition. Is there a better way to determine if the mount is sucessful or not? Im using ubuntu 11.04 and qt 4.7.3
bool mwDM::mountFolder()
{
QString smbUsername,smbPassword,serverPath,mountPath;
QProcess connectSamba;
QString terminalCommand,linuxPassword;
QDir dir("/mnt/backup");
smbUsername=ReadINIStr(iniPath,"Server","Username","");
smbPassword=ReadINIStr(iniPath,"Server","Password","");
serverPath=ReadINIStr(iniPath,"Server","Hostname","");
serverPath="//" + serverPath;
mountPath="/mnt/backup";
linuxPassword=ReadINIStr(iniPath,"Server","AdminPassword","");
terminalCommand="echo "+linuxPassword+" | sudo -S mount -t cifs -o username="+smbUsername+",password="+smbPassword+" "+serverPath+ " "+mountPath;
connectSamba.start("sh",QStringList() << "-c" << terminalCommand );
if(!connectSamba.waitForStarted())
{
LogWrite("Failed to start mount command", Qt::red);
}
if(!connectSamba.waitForFinished() )
{
LogWrite("Failed to finish mount command", Qt::red);
}
QString connectSamba_stderr = connectSamba.readAllStandardError();
qDebug() << "connectSamba_stderr" << connectSamba_stderr;
if(connectSamba_stderr.contains("is not a valid block device"))
{
LogWrite("Hostname is invalid", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("3 incorrect password attempts"))
{
LogWrite("Admin password is incorrect", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("wrong fs type, bad option, bad superblock on"))
{
LogWrite("Hostname is invalid", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("Invalid argument"))
{
LogWrite("Mount error(22): Invalid argument", Qt::red);
return false;
}
else if(!dir.exists())
{
LogWrite("Directory doesn't exists", Qt::red);
return false;
}
else
{
return true;
}
}
You can check last error of a QProcess by using error and state functions (Documentation for "error" Documentation for "state").
"What if there is an error that is not in my condition."
You can add something like this in your code:
else if(connectSamba.state() == QProcess::NotRunning && connectSamba.error() >= 0)
{
LogWrite("Unknown error", Qt::red);
return false;
}
Or, if you want to give more specific information, you can create a condition for each error code separately. Here's a list of codes.
Alternatively, don't add the above block to the error checking code. Instead, create a slot to which you connect the error signal of connectSamba class:
// add this line below "QProcess connectSamba;" line in mwDm::mountFolder
connect(&connectSamba, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError));
// after that, use your original error checking code in mountFolder
// slot code
void mwDm::onError(QProcess::ProcessError)
{
//use switch-case or if to check type of error if you want
processErrorOccurred = true; // processErrorOccurred is a member of mwDm
}

tcl script for ping not working

I have a tcl code which invokes ping command and returns its response , code is as follows
proc ping-igp {} {
foreach i {
127.0.0.1
200.200.200.1
} {
if { [regexp "0% loss" [eval exec "ping $i -n 1" ]]} { puts “$i”} else { puts “$i failed” }
}
}
But while executing it I get o/p as follows,
% proc ping-igp {} {
foreach i {
127.0.0.1
200.200.200.1
} {
if { [regexp "0% loss" [eval exec "ping $i -n 1" ]]} { puts "$i"} else { puts "
$i failed" }
}
}
% ping-igp
"127.0.0.1"
Pinging 200.200.200.1 with 32 bytes of data:
Request timed out.
Ping statistics for 200.200.200.1:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
child process exited abnormally
%
I want to know when I'm unable to ping 200.200.200.1 why my code doesn't process else clause and give o/p " 200.200.200.1 failed " in end . I'm matching "0% loss"
Many Thanx.
You need to catch the exec call to ping, in case it returns an error. Here's your code modified to use catch.
proc ping-igp {} {
foreach i {
127.0.0.1
200.200.200.1
} {
if {[catch {exec ping $i -n 1} result]} { set result 0 }
if { [regexp "0% loss" $result]} { puts "$i"} else { puts "$i failed" }
}
}
Running it now gives:
% ping-igp
127.0.0.1
200.200.200.1 failed
%
Here is something I created for my own use: a ping proc for Tcl. It is not perfect, but works:
package require Tclx; # Needed for lassign and wait
# Pings a host and returns 0 if OK, non-zero otherwise
proc ping {host} {
# TODO: Use different command for Windows OS
set childPid [exec ping -c 1 $host > /dev/null 2>#1 &]
lassign [wait $childPid] pid howItEnded exitCode
return $exitCode
}
# Test the ping proc
set hostList {google.com 10.0.0.99 foo.bar}
foreach host $hostList {
set code [ping $host]
puts [format "%4d %s" $code $host]
}
Sample output:
$ tclsh ping_test.tcl
0 google.com
2 10.0.0.99
68 foo.bar
proc ping_device { router ip_address max_tries } {
set tries 0
while {$tries <= $max_tries} {
if {[catch {exec ping $ip_address -c 5} result]} {
puts "Ping command failed on Linux machine"
incr tries
if {$tries > $max_tries} {
ats_log -error "Giving up on ping"
return 0
}
continue
}
if {[regexp {([1-5]+) *[packets]? *received} $result - packets]} {
puts "Able to ping device: $router and\
successfully received $packets packets"
return 1
} else {
puts "Not Able to ping device: $router"
incr tries
}
}
puts "Giving up on ping, returning 0"
return 0
}

How to retrieve vista's network status (e.g. "Local Only", "Local and Internet") in powershell

I have a flaky NIC that drops out from time to time, especially after resuming from hibernation. A drop-out corresponds to Vista's network status showing in the notification area as "Local Only". Is there a way of retrieving these status values (e.g. "Limited Connectivity", "Local Only", "Local and Internet") programmatically?
I am writing a powershell script that polls to see if the connection is down, and if so, resets the adapter. Currently I am trying to detect the connection state by pinging my ISP's DNS server. However, since the OS is already correctly identifying this condition, it would be much simpler if I could just retrieve this value.
Thanks!
Try this function:
PS> function Get-NetworkStatus {
$t = [Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
$networkListManager = [Activator]::CreateInstance($t)
$connections = $networkListManager.GetNetworkConnections()
function getconnectivity {
param($network)
switch ($network.GetConnectivity()) {
0x0000 { 'disconnected' }
{ $_ -band 0x0001 } { 'IPV4_NOTRAFFIC' }
{ $_ -band 0x0002 } { 'IPV6_NOTRAFFIC' }
{ $_ -band 0x0010 } { 'IPV4_SUBNET' }
{ $_ -band 0x0020 } { 'IPV4_LOCALNETWORK' }
{ $_ -band 0x0040 } { 'IPV4_INTERNET' }
{ $_ -band 0x0100 } { 'IPV6_SUBNET' }
{ $_ -band 0x0200 } { 'IPV6_LOCALNETWORK' }
{ $_ -band 0x0400 } { 'IPV6_INTERNET' }
}
}
$connections |
% {
$n = $_.GetNetwork();
$name = $n.GetName();
$category = switch($n.GetCategory()) { 0 { 'public' } 1 { 'private' } 2 { 'domain' } }
$connectivity = getConnectivity $n
new-object PsObject -property #{Name=$name; Category=$category; Connectivity=$connectivity }
}
}
PS> Get-NetworkStatus
Name Connectivity Category
---- ------------ --------
Neznámá síť {IPV4_NOTRAFFIC, IPV6_NOTRAFFIC} public
stefan {IPV6_NOTRAFFIC, IPV4_INTERNET} private
If you pipe $connections and output from GetNetwork() to Get-Member you will find some more useful methods.

Resources