PowerShell with Excel

MSerg

New Member
Joined
Aug 16, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello. I want to make a list of TCP hosts in an Excel book and test connection by Test-NetConnection. It looks as follow -
Dim a
Dim b As Boolean

Set a = CreateObject("WScript.Shell")
b = a.Run("powershell TNC 192.168.26.10 -CommonTCPPort RDP -InformationLevel Quiet", 0, True)


it works, powershell runs, TNC works and returns True/False if port is opened or closed.
But! it doesn't return correct result to b. It always returnes FALSE if syntax is correct and TRUE if syntax is wrong.
It does not return the result of test connection. Whether the port is open or closed b is FALSE.

If anyone knows how to make TNC return the correct answer please tell me
 
The problem was the 'T' at the end of the command:
Command = "powershell TNC 192.168.26.10 -CommonTCPPort RDP -InformationLevel Quiet T"

The PowerShell error is "Test-NetConnection : A positional parameter cannot be found that accepts argument 'T'."

With the 'T' removed, the result of the command is correctly copied to the clipboard:
VBA Code:
    Command = "powershell TNC 192.168.26.10 -CommonTCPPort RDP -InformationLevel Quiet"
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Ahh, thank you kindly for looking into it for me. In my excitement(? haste?), I failed at the basic task of copy/paste" :)
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top