更改計算機名及加域腳本

這是根據咱們公司工做流程及需求寫的,沒有用第三方軟件,全用系統自帶的命令完成的,XP,win7,win8均可以用!把腳本原文件放在C盤或其它目錄,建立快捷方式到開機啓動項就能夠了,第一次運行,輸入一些參數,後面就不用管了,能夠根據本身公司具體狀況再更改,只是寫的很差,腳本底子沒有,瞎捉摸的dom


@echo off
echo 要設置IP嗎?
set /p shuru4=請輸入y/n:
::if %shuru4%==y (goto ip) else (goto ks)
if %shuru4%==y (set /p ip=請輸入7網段屬於你的IP最後一位:) else (echo 你不打算設置IP)
echo 要更改計算機名嗎?
set /p shuru1=請輸入y/n:
if %shuru1%==y (set /p cmpname=請輸入你的計算機名稱:) else (echo 你不許備改計算機名)
echo 要加域嗎?
set /p shuru8=請輸入y/n:
if %shuru8%==y (set /p zz=請輸入你所在的部門名稱:) else (echo 你不想要加域)
if defined ip (goto :ip) else (goto ks)ide

:iptoken

@echo 設置IP
::set /p ip=請輸入7網段屬於你的IP最後一位:
netsh interface ip set address name=本地鏈接 source=static addr=192.168.7.%ip% mask=255.255.255.0 gateway=192.168.7.1 gwmetric=auto
netsh interface ip set dns name=本地鏈接 source=static addr=192.168.100.206 register=primary
netsh interface ip add dns name=本地鏈接 addr=192.168.100.202 index=2dns


:ksip

if exist retuvlue.txt (goto jd) else (goto gm)內存

:gm
if defined cmpname (goto gm1) else (goto jd)rem

:gm1工作流

net config workstation |find "工做站域 DNS " > name1.txtit

::findstr .* name1.txt &&echo full || echo kong
for %%a in (name1.txt) do if %%~za==0 (goto gm3)io

for /f "tokens=4 delims= " %%b in (name1.txt) do set q=%%b
if %q%==greatstar.com (goto gm2) else (goto gm3)

:gm2

wmic computersystem where name="%computername%" call rename name="%cmpname%" username="wfl" password="wfl" >retuvlue.txt

for /f "delims=" %%o in ('findstr Return retuvlue.txt') do set rv=%%o
echo %rv% >jg.txt
for /f "tokens=3 delims= " %%i in (jg.txt) do set e=%%i
echo %e% > fh.txt
for /f "tokens=1 delims=;" %%j in (fh.txt) do set aa=%%j
if %aa%==0 (echo 計算機名更改爲功 >retuvlue.txt && goto cq) else (echo 計算機名更改失敗,請再嘗試一遍 && goto gm2)

:gm3


::更改計算機名
wmic computersystem where name="%computername%" call rename name="%cmpname%" >retuvlue.txt

for /f "delims=" %%l in ('findstr Return retuvlue.txt') do set fhz=%%l
echo %fhz% >jg.txt
for /f "tokens=3 delims= " %%i in (jg.txt) do set n=%%i
echo %n% > fh.txt
for /f "tokens=1 delims=;" %%j in (fh.txt) do set m=%%j
if %m%==0 (echo 計算機名更改爲功 >retuvlue.txt && goto cq) else (echo 計算機名更改失敗,請再嘗試一遍 && goto gm3)


:cq
echo @echo off >temp.txt
echo set zz=%zz% >>temp.txt
setlocal enabledelayedexpansion

for /f "tokens=*" %%i in (jdomain.bat) do (
set /a n+=1
if !n! gtr 56 echo %%i>>temp.txt
)

shutdown -r -f -t 5
move temp.txt jdomain.bat

echo 正在重啓中...
pause>nul
exit

:jd
rem 加域
if exist retuvlue.txt (goto pd)  else (goto xunwen)

:pd
for /f "delims=" %%x in (retuvlue.txt) do set fhz=%%x
if %fhz%==加域成功 (goto jdok) else (if %fhz%==計算機名更改爲功 (goto jd1) else (goto xuanze))


:xunwen
echo 須要加域嗎?
set /p shuru3=請輸入y/n:
if %shuru3%==y (goto jd1) else (goto xiande)


:jd1
if defined zz (goto zb) else (echo 你沒有選擇要加入到的部門 && set /p zz=請輸入你所在的部門名稱:)

:zb

echo 正在加域,請勿關閉...

set sleep=ping 127.0.0.1 -n
%sleep% 25 >nul
wmic computersystem where "name='%COMPUTERNAME%'" call joindomainorworkgroup fjoinoptions=3 name="greatstar.com" username="wfl" password="wfl" accountou="ou=%zz%;ou=巨星科技;ou=計算機;dc=greatstar;dc=com" > retuvlue.txt

for /f "delims=" %%x in ('findstr Return retuvlue.txt') do set fhz=%%x
echo %fhz% >jg.txt
for /f "tokens=3 delims= " %%w in (jg.txt) do set b=%%w
echo %b% > fh1.txt
for /f "tokens=1 delims=;" %%k in (fh1.txt) do set q=%%k
if %q%==0 (echo 加域成功 > retuvlue.txt && goto cq1) else (goto jd2)

:cq1
shutdown -r -f -t 0
echo 正在重啓中...
pause>nul

:jdok
net config workstation |find "工做站域 DNS " > name.txt
for /f "tokens=4 delims= " %%a in (name.txt) do set p=%%a
if %p%==greatstar.com (echo 你已經成功加入域%p% && goto shanchu1) else (goto jd2)


:jd2
echo 加域失敗,從新嘗試加域嗎?
set /p shuru=請輸入y/n:
if %shuru%==y (goto jd1) else (goto tc)

:shanchu
echo 要刪除加域文件嗎?
set /p shuru2=請輸入y/n:
if %shuru2%==y (goto shanchu1) else (goto tc)

:xuanze
echo 1:改計算機名
echo 2:加域
echo 3:退出
set /p xz=請輸入你想執行的操做序號:
if %xz% equ 1  (goto gm1) else (if %xz% equ 2 (goto jd1) else (goto xiande))


:shanchu1
del retuvlue.txt /q
del retuvlue1.txt /q
del jg.txt /q
del name.txt /q
del name1.txt /q
del fh.txt /q
del fh1.txt /q
del jg1.txt /q
del jdomain.bat /q
exit

:xiande
echo 你好無聊
pause
del retuvlue.txt /q
del retuvlue1.txt /q
del jg.txt /q
del name.txt /q
del name1.txt /q
del fh.txt /q
del fh1.txt /q
del jg1.txt /q

:tc
del retuvlue.txt /q
del retuvlue1.txt /q
del jg.txt /q
del name.txt /q
del name1.txt /q
del fh.txt /q
del fh1.txt /q
del jg1.txt /q
exit




::fjoinoptions=1是默認,加入工做組,2是在域裏建立一個賬戶,4***一個域內存在的賬戶,32容許加入到新域,即便此計算機已經加入到一個域,不過好像如今沒有32了,只有3,32不起做用


::accountou加入到指定OU,若是不指定或指定accoutou=null則默認加入computers
::accountou="ou=計算機;dc=greatstar;dc=com"

::加入或更改工做組
::wmic computersystem where name="%COMPUTERNAME%" call joindomainorworkgroup name="workgroup"

:+退域
::wmic computersystem where name="%COMPUTERNAME%" call unjoindomainorworkgroup username="greatstar\wfl" password="wfl" funjoinoptions=0這個是默認操做,若是是2,能夠退域後禁用計算機賬號,但不能***,但我試了後沒什麼用,仍是不能禁用賬戶

::unjoindomainorworkgroup後面的均可以不寫

相關文章
相關標籤/搜索