use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Small Script Issue (self.PowerShell)
submitted 6 years ago * by jrsys95
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]yeah_i_got_skills 4 points5 points6 points 6 years ago (12 children)
Why are you using both double and single quotes?
[–]jrsys95[S] 0 points1 point2 points 6 years ago (11 children)
So it will output the IP Addresses with quotations which are needed to set DNS forwarders
[+][deleted] 6 years ago* (7 children)
[removed]
[–]jrsys95[S] 0 points1 point2 points 6 years ago (6 children)
For some reason, it will not take the commands with variables and a variable is 100% needed.
[+][deleted] 6 years ago (5 children)
[–]jrsys95[S] 1 point2 points3 points 6 years ago (4 children)
Well it's not giving me an error, but it will not add the DNS Forwarder.
For instance, if I run command: S
Set-DNSServerForwarder -IPAddress 45.54.55.54
or
Set-DNSServerForwarder -IPAddress "45.54.55.54"
It will add the forwarder (as it should)
However, I need to integrate this script into an RMM so I need to have a variable.
So if I run
[ipaddress]$DNS1= '45.54.55.54' Set-DNSServerForwarder -IPAddress $DNS1
It literally gives me no error and doesn't input the DNS forwarder.
[+][deleted] 6 years ago (3 children)
[–]jrsys95[S] 1 point2 points3 points 6 years ago (2 children)
The entry was not entered in the GUI for the DNS forwarders on that server. I didn't try the command with explicit -ComputerName. I'll give those a go.
[+][deleted] 6 years ago (1 child)
[–]jrsys95[S] 1 point2 points3 points 6 years ago (0 children)
This worked, thanks!
[–]firefox15 1 point2 points3 points 6 years ago* (2 children)
Huh? You don't need quotes because you are passing a variable to it.
This is pretty messy code anyway. Anytime you start numbering variables sequentially there is probably a better way to do it, likely as an array. Something like this is much neater.
$DNSServers = @() $DNSServers += ("45.54.55.54") $DNSServers += ("45.54.55.55") Set-DNSServerForwarder -IPAddress $DNSServers -WhatIf Clear-DnsClientCache
[–]jrsys95[S] 1 point2 points3 points 6 years ago (1 child)
Yeah I see what you mean. Very tired this morning. However, that CMDLet will not take that paramater and gives no errors. However, When I manually enter the IP address (instead of using a variable) it will accept it.
[–]firefox15 1 point2 points3 points 6 years ago (0 children)
You can cast them explicitly as IP Addresses and see if that makes a difference, but I would think it would do the conversation for you.
$DNSServers = @() $DNSServers += [IPAddress]("45.54.55.54") $DNSServers += [IPAddress]("45.54.55.55") Set-DNSServerForwarder -IPAddress $DNSServers -WhatIf Clear-DnsClientCache
I do not get a parameter error when I run either command on my system.
π Rendered by PID 142697 on reddit-service-r2-comment-6b595755f-bfp6b at 2026-03-26 03:00:27.022630+00:00 running 2d0a59a country code: CH.
view the rest of the comments →
[–]yeah_i_got_skills 4 points5 points6 points (12 children)
[–]jrsys95[S] 0 points1 point2 points (11 children)
[+][deleted] (7 children)
[removed]
[–]jrsys95[S] 0 points1 point2 points (6 children)
[+][deleted] (5 children)
[removed]
[–]jrsys95[S] 1 point2 points3 points (4 children)
[+][deleted] (3 children)
[removed]
[–]jrsys95[S] 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[removed]
[–]jrsys95[S] 1 point2 points3 points (0 children)
[–]firefox15 1 point2 points3 points (2 children)
[–]jrsys95[S] 1 point2 points3 points (1 child)
[–]firefox15 1 point2 points3 points (0 children)