Jump to content

Powershell, power woaws

Go to solution Solved by UK-Gary,

For all those who'd like the answer -

 

$log = do # Do this
{
    # Store the result of TNC in this variable to be tested until(...) is False
    $tnc = Test-NetConnection -ComputerName [Address] -Port [port] |
    Select-Object @{
        Name = 'TimeStamp'
        Expression = { [datetime]::Now.ToString('u') }
    }, RemoteAddress, RemotePort, TcpTestSuceeded

    # Return this variable so it's captured in $log Variable to export the log later
    $tnc 
    Start-Sleep -Seconds 5
}
until ($tnc.TcpTestSuceeded) # Until this property is $False

$log | Export-Csv path/to/logfile.csv -NoTypeInformation

Hi, 

I would like to run a powershell script where I can loop a command until it comes back false.

tnc -ComputerName [Address] -port [port]
Start-Sleep -s 5 

 

The script is run every 5 seconds 

 

ComputerName     : [Address]
RemoteAddress    : IP
RemotePort       : Port
InterfaceAlias   : WiFi
SourceAddress    : [Address]
TcpTestSucceeded : True

 

I need this to run every 5 seconds but only show on false then extract to a doc and continue running.

I don't know if this is possible, but any help
 

Link to comment
https://linustechtips.com/topic/1391093-powershell-power-woaws/
Share on other sites

Link to post
Share on other sites

You could use the Task Scheduler, to run the script every 5 seconds; you'd need to implement some if condition in the script, in case it returns false, and a command to execute to log or report the info

DESKTOP PC - CPU-Z VALIDi5 4690K @ 4.70 GHz | 47 X 100.2 MHz | ASUS Z97 Pro Gamer | Enermax Liqmax II 240mm | EVGA GTX 1070Ti OC'd

HOME SERVER | HP ProLiant DL380 G7 | 2x Intel Xeon X5650 | 36GB DDR3 RDIMM | 5x 4TB LFF Seagate Constellation 7.2K | Curcial MX500 250GB | Ubuntu Server 20.04

Link to comment
https://linustechtips.com/topic/1391093-powershell-power-woaws/#findComment-15121557
Share on other sites

Link to post
Share on other sites

For all those who'd like the answer -

 

$log = do # Do this
{
    # Store the result of TNC in this variable to be tested until(...) is False
    $tnc = Test-NetConnection -ComputerName [Address] -Port [port] |
    Select-Object @{
        Name = 'TimeStamp'
        Expression = { [datetime]::Now.ToString('u') }
    }, RemoteAddress, RemotePort, TcpTestSuceeded

    # Return this variable so it's captured in $log Variable to export the log later
    $tnc 
    Start-Sleep -Seconds 5
}
until ($tnc.TcpTestSuceeded) # Until this property is $False

$log | Export-Csv path/to/logfile.csv -NoTypeInformation
Link to comment
https://linustechtips.com/topic/1391093-powershell-power-woaws/#findComment-15121597
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×