Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need help converting batch to Powershell

$
0
0

Batch will create a record based on the number of the hostname. Example: If servername is "Hostname20" the record will be added with IP 20.20.20.20.

if %lsv% EQU 08 set lsv=8
if %lsv% EQU 09 set lsv=9

set /a lsv=%lsv%+0

C:\Windows\System32\dnscmd %sv% /recordadd <record> A %lsv%.%lsv%.%lsv%.%lsv%

I tried this but, this is not what I want. 

    if ($server -match "1") {$lsv="1"}
    if ($server -match "2") {$lsv="2"}
    if ($server -match "3") {$lsv="3"}
    if ($server -match "4") {$lsv="4"}
    if ($server -match "5") {$lsv="5"}
    if ($server -match "6") {$lsv="6"}
    if ($server -match "7") {$lsv="7"}
    if ($server -match "8") {$lsv="8"}
    if ($server -match "9") {$lsv="9"}
    dnscmd $server /recordadd test.tst test A "$lsv.$lsv.$lsv.$lsv" | out-file -Append $results

Need some logic so that the A record is created with IP address matching the host number in the host name.

Example: hostname12 should create 12.12.12.12

Hostname99 should create 99.99.99.99.


99upgrade


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>