r/PowerShell • u/jack_ery21 • Dec 09 '25
Question Set DNS through powershell
Hey guys So I have an odd problem, I’m sure anyone else who also uses FortiClient may also have this too.
When FortiClient disconnects, on rare occasions it doesn’t remove the internal dns on the wifi adapter so the laptop becomes useless and needs a tech to physically go fix it by setting the dns back to automatic.
We use NinjaOne and I want to make a script that will be accessible by the end user using the SysTray feature, they can run pre-made automations.
Doing some testing today and I was looking at using Set-DNSClientServerAddress, but wasn’t having much luck.
Full command I used was Set-DnsClientServerAddress -InterfaceIndex 14 -ResetServerAddresses
This said it worked, but the settings were still there. Am I missing something?
Interface index was correct, checked that.
Device is Windows 11. FortiClient VPN only 7.4.0 (has been happening since V6, so not version relevant)
Thanks
View all comments
Show parent comment
1
u/jack_ery21 Dec 10 '25
I was testing on a laptop at first, don't worry, I'd have the script check which InterfaceIndex it is before releasing it. Whether it was me or the laptop yesterday but just tried it on mine and it was working as expected. Given I was rushed yesterday so must have been doing something silly.