Help to run these commands in powershell

Welcome Forums General PowerShell Q&A Help to run these commands in powershell

Viewing 2 reply threads
  • Author
    Posts
    • #201180
      Participant
      Topics: 1
      Replies: 1
      Points: 34
      Rank: Member

      Hello, I am trying to create a script like the following using powershell, in fact I tried these commands and changing the “@SET / P Data = Enter IP_ADDRESS SUBNET_MASK GATEWAY:” for “$ Data = Read-Host -Prompt” Enter IP_ADDRESS SUBNET_MASK GATEWAY: “” without getting results.

      I need help, thanks

       

      @SET /P Data=IntroduceIP_ADDRESS SUBNET_MASK GATEWAY:

      netsh interface ipv4 set address name=”Ethernet” static %Datos%
      netsh interface ipv4 add dns “Ethernet” address=10.70.11.48 index=1
      netsh interface ipv4 add dns “Ethernet” address=10.70.11.42 index=2
      netsh interface ipv4 add dns “Ethernet” address=10.41.1.154 index=3
      netsh interface ipv4 add dns “Ethernet” address=10.70.122.14 index=4
      netsh interface ipv4 add dns “Ethernet” address=10.70.122.11 index=5
      netsh interface ipv4 add dns “Ethernet” address=10.41.1.153 index=6

      pause

      ipconfig /flushdns

      ipconfig /registerdns

      netsh interface ipv4 show config “Ethernet”

      pause

    • #201255
      Participant
      Topics: 11
      Replies: 1445
      Points: 1,784
      Helping Hand
      Rank: Community Hero

      The first thing I would recommend is that you use actual Powershell cmdlets, not DOS commands. Powershell has been around for a while now and you will be remiss to find cmdlets, examples, blogs that don’t perform common networking tasks. Take a look at the following blog:

      https://www.thomasmaurer.ch/2016/02/basic-networking-powershell-cmdlets-cheatsheet-to-replace-netsh-ipconfig-nslookup-and-more/

    • #201348
      Participant
      Topics: 1
      Replies: 1
      Points: 34
      Rank: Member

      I have already seen that to configure the IP is as follows

      NewNetIPAddress InterfaceAlias “Ethernet” IPv4Address 10.0.1.95 PrefixLength “24” DefaultGateway 10.0.1.1

      but I could put the netmask in the “255.255.255.0” format instead of “24”

       

      And I seen to configure DNS servers

      Set-DnsClientServerAddress -InterfaceAlias “Ethernet” -ServerAddresses “10.70.11.48”,”10.70.11.42″, …

       

      I can put next

      $IP=Read-Host “write the ip

      $GATEWAY=Read-Host “write the gateway

      NewNetIPAddress InterfaceAlias “Ethernet” IPv4Address $IP PrefixLength “24” DefaultGateway $GATEWAY

       

      P.S: IP, network mask and gateway could be ordered on the same line, as in the example of netsh

      • This reply was modified 3 weeks, 2 days ago by egoitzro.
Viewing 2 reply threads
  • You must be logged in to reply to this topic.