Jump to content

cant use variable in powershell to setup DHCP


smurfexe

Recommended Posts

Posted

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

  • 6 months later...
Posted

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

 

Posted

Why are you bumping?

Posted September 27, 2022

Posted

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.

Archived

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

  • Recently Browsing   0 members

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