windows server常用操作

【1】基本操作

netsh 修改IP地址和DNS

Rem 设置名称叫 本地连接的网卡,静态地址为 192.168.0.1 后面是子网掩码、网关netsh interface ip set address "本地连接" static 192.168.0.1 255.255.255.0 192.168.0.254 1    
Rem 设置名称叫 本地连接的网卡 DNS 为 202.194.40.1,第2行的 add dns 为添加第二DNS
netsh interface ip set dns "本地连接" static 202.194.40.1
netsh interface ip add dns "本地连接" 202.194.40.2 2Rem 设置名称叫 本地连接的网卡 其IP地址模式为 DHCP 分配netsh interface ip set address "本地连接" dhcp

wmic修改计算机名

wmic computersystem where "name='%computername%'" call rename "Someyouwana"

Rem netdom 也可以,但这是交互式的
netdom /renamecomputer %computername% /newname:input_new_computer_name

netdom join 加入,退出域

复制代码
NETDOM JOIN machine /Domain:domain [/OU:ou path] [/UserD:user]
           [/PasswordD:[password | *]]
           [UserO:user] [/PasswordO:[password | *]]
           [/REBoot[:Time in seconds]]

 
NETDOM REMOVE machine /Domain:domain [/UserD:user]
           [/PasswordD:[password | *]]
           [UserO:user] [/PasswordO:[password | *]]
           [/REBoot[:Time in seconds]]
复制代码

案例:加入、退出域

@echo off
netdom join %computername% /domain:tech.com /UserD:techadministrator /PasswordD:ASD!@#123 /REBoot:5

@echo off
netdom remove %computername% /domain:tech.com /UserD:techadministrator /PasswordD:ASD!@#123 /REBoot:5

ps:get/install/remove-windowsfeature 安装,查看,卸载角色、角色服务、功能

get-Windowsfeature Name,要是不写name就是全部,写name就是制定的服务
add-WindowsFeature Name -whatif,模拟安装这个服务可能发生的情况,以及是否需要重启之类的,但实际上不会进行任何操作
Install-WindowsFeature -name name1,name2 -Restart # 安装功能 name1,name2 这里可以写多个,以逗号分隔,如该行例子,-Restart 是安装完后自动重启,可以去掉该参数
remove-WindowsFeature name # 卸载功能

-whatif :模拟执行,检查、查看情况,并没有实际执行
-Restart :执行命令完后,重启计算机

get-windowsfeature  name,要是不写name就是全部,写name就是制定的服务

      

  

add-windowsfeature name -whatif,模拟安装这个服务可能发生的情况,以及是否需要重启之类的,但实际上不会进行任何操作

remove-windowsfeature name -whatif

  

 install-windwsfeature name , remove-windowsfeature name

  

get/set-executionpolicy 查看/设置 PS脚本是否允许执行

get-executionpolicy    # Unrestricted,Restricted
set-executionpolicy Unrestricted/Restricted

PS:dir env:/Get-Childitem env: 查看获取windows环境变量

  

 怎么获取呢?

  PS:$env:computername   DOS: %computername%

   

原文地址:https://www.cnblogs.com/gered/p/14085546.html