Jump to content

cant use variable in powershell to setup DHCP


Recommended Posts

hi. im trying to setup a DHCP server with powershell using variables. but with variables it doesnt work and without it does. is it possible that i cant use varibles?


this is the script so far.

$DHCPNAME = "Scope171186"
$defaultgateway = ""

Install-WindowsFeature "DHCP" –IncludeManagementTools

add-DhcpServerV4Scope -Name "DHCP Scope" -StartRange $DHCPSTARTRANGE -EndRange $DHCPENDRANGE -SubnetMask $DHCPSUBNETMASK

Link to comment
Share on other sites

  • 6 months later...

Is that the literal script, or are you using functions? Note that variables within a function will not be available outside of a function unless set to global.

Also, are you sure that's correct syntax? When setting a variable, I don't believe you place a $ at the beginning, only when you are calling it, so;

VARIABLE = "blabla"


Link to comment
Share on other sites

I have to ask; what's the time limit to not answer an open thread in the forums? Hunting down people that tries to answer questions really annoys me sometimes. If the thread hasn't been active for 8 years, I get it, but otherwise... who cares if it tries to add to the understanding of a topic.

And, the $ char is totally OK to use when defining/populating a variable using PowerShell. In bash (or such) on the other hand, you use it without the $ char when it's defined/populated.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...