Jump to content

cant use variable in powershell to setup DHCP


smurfexe

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"
$DHCPSTARTRANGE = "172.16.2.100"
$DHCPENDRANGE = "172.16.2.151"
$DHCPSUBNETMASK = "255.255.255.0"
$defaultgateway = "172.16.2.10"
$DNSSERVER = "172.16.2.10"

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"
echo $VARIABLE

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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