Help correcting code to be successful

Continously Test-NetConnection until PingSucceeded = True so I can be notified via email and then force the NIC to be disabled.

fucntion disableNic () {
Send-MailMessage -To GOOGLE EMAIL -Subject ‘Lab 1 computer connected to internet’ -Body “LAB 1 CONNECTED TO WIFI” -Credential (Get-Credential) -SMTPServer -port 587 -from EMAIL
Get-NetAdapter | ?{ $_.status -eq “UP” } | Disable-NetAdapter -Confirm:$false

while (1 -eq 1) {
if (Test-Netconnect -Quiet) -4q $True {

Welcome to the forum. :wave:t4:

What’s your question?

And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

Hi and thank you.

Yes, I am looking to create a script where it does the following: 1) Continuously check for an internet connection (Even if the computer is turned off or restarted). 2) Sends a notification via email 3) Disables Ethernet and Wi-Fi connection. 4) restarts the script again.


OK. And what is your question? You should ask a specific question about a particular piece of you code you wrote yourself and you have an issue with.

Please keep in mind - this forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

Thanks for taking the time and for being patient with me. What am I doing wrong here?

Please do not post images of code or error messages. Instead post the plain text and format it as code.

There are several issues with your code. I’d recommend to do a big step back and start with learning the very basics of PowerShell first. This will save you from a lot of wasted time and frustrations.

You should ALWAYS read the complete help including the examples for the cmdlets you’re about to use to learn how to use them

Amlost everything. :smirk: Test-NetConnection does not have a parameter -Quiet. The syntax for your if statement is wrong. You should consider adding a pause to decrease the load you put on your computer for this task.

Do you offer tutoring? lol. and/or recommend any resources.

I already linked 2 resources! :man_shrugging:t4: Did you read them? … completely? … including the examples?

Start with learning the very basics first

I completely missed that. I apologize. I’m sorry you’re so frustrated.

Thanks for all your help. I truly appreciate it.