您的位置:首页 > 其它

工作组环境下管理windows.

2014-07-23 11:24 232 查看
此处指的是windows7

1.防火墙设置

开启wmi,remote admin,防火墙远程管理

可以使用命令行

netsh advfirewall export "C:\temp\WFconfiguration.wfw"
netsh advfirewall import "C:\temp\WFconfiguration.wfw"

2.修改Powershell执行策略

Set-ExecutionPolicy RemoteSigned
可以用脚本从批处理调用,参考http://stackoverflow.com/questions/932291/calling-powershell-cmdlets-from-windows-batch-file
http://www.computerperformance.co.uk/powershell/powershell_cmdlet.htm

Starting with Powershell version 2, you can run a Powershell script like so...
powershell -ExecutionPolicy RemoteSigned -File "C:\Path\Script.ps1" "Parameter with spaces" Parameter

3.安装powershell3.0

查看版本办法
PS下$host
或则

$psvertiontable

检查winrm版本

winrm id

4.在提权的命令行下建立管理员账号,加入管理员组

net user test * /add /comment:"test user" /expires:never /fullname:"xx”

net localgroup administrators test /add

查看用户和组,net user test

net localgroup administrators

5.命名网卡连接LAN0,LAN1,LAN-free,设置网络环境为专用网络

6.配置winRM

前提:提权的command下运行

被管理端:

winrm quickconfig



远程执行指令的两种方式

winrm –r:computername command

icm hostname {powershell-command}

icm是Invoke-Command的简写

client(发起访问的一方)配置(不在powershell下):
6.1 WinRM quickconfig  //配置winrm服务,防火墙例外设置,启动winrm listener
6.2 winrm set winrm/config/client @{TrustedHosts=”remote-computer-name”} //设置信任的客户端
(另一种方式

# Enabled Trusted Hosts for Universial Access
cd wsman:
cd localhost\client
Set-Item TrustedHosts * -force
restart-Service winrm
)
6.3 确定winrm在运行:[b]get-service winrm[/b]
6.4 enable-psremoting –force (不确定是否要执行,应该是在被管理端执行)
参见:http://tech.ccidnet.com/art/302/20100701/2102911_1.html
http://technet.microsoft.com/en-us/library/hh849694.aspx

当执行该cmdlet时执行了以下操作,其中包括:
1. 启动或重新启动(如果已启动) WinRM 服务。
2. 将 WinRM 服务类型设置为自动启动。
3. 在本地计算机上创建一个侦听器以接受任意 IP 地址上的请求。
4. 对 WS-Management 流量启用防火墙例外(仅适用于 http),如果要启用PS远程管理,此时网络位置不能被设置为public,因为Windows 防火墙例外不能在网络位置是public时被启用。
5.启用所有注册的PS线程配置信息。
The Enable-PSRemoting cmdlet performs the following operations:
-- Runs the Set-WSManQuickConfig cmdlet, which performs the following tasks:
----- Starts the WinRM service.
----- Sets the startup type on the WinRM service to Automatic.
----- Creates a listener to accept requests on any IP address.
----- Enables a firewall exception for WS-Management communications.
----- Registers the Microsoft.PowerShell and Microsoft.PowerShell.Workflow session configurations, if it they are not already registered.
----- Registers the Microsoft.PowerShell32 session configuration on 64-bit computers, if it is not already registered.
----- Enables all session configurations.
----- Changes the security descriptor of all session configurations to allow remote access.
----- Restarts the WinRM service to make the preceding changes effective.
默认情况下,PowerShell远程管理使用5985(http)和5986(https)端口
当给Enable-PSRemoting cmdlet增加-force参数后执行将会在静默状态下启用远程管理,PowerShell远程管理是不能通过远程启用的。
如果远程管理被启用了,可以使用下面的cmdlet查看:
PS C:\ > Enter-PSSession –ComputerName localhost
用户将会看到如下图2所示的提示符:


6.5 winrs -r:Remote-computer-name whoami  //测试winrm连接,此处用whoami直接用本机用户名
winrs -r:Remote-computer-name ipconfig //在远程被管理端测试ipconfig
进入Powershell,
6.6 Get-Process | Sort-Object -Property CPU -Descending | Select -First 10 //本机的前10个进程
icm Remote-computer-name {Get-Process | Sort-Object -Property CPU -Descending | Select -First 10} //被管理的远端主机的前10个进程
一对多管理:

Invoke-Command -ComputerName WinServ-wfe, SQL-Server2008 -ScriptBlock {Get-Process}

Invoke-Command -ComputerName (get-content c:\scripts\servers.txt) -ScriptBlock {Get-Process}
这种方式也被称之为散开式或一对多远程管理。用户能用一条命令在多台主机上执行相同的命令。

脚本块中所有的命令和变量均会在远程计算机上运行。如果用户采用类似于-ScriptBlock {Get-Process –Name $procName},PowerShell认为远程计算机线程中$procName变量已经定义过了。用户能通过使用Invoke-Command命令,将本地计算机上的变量传递到远程线程。
2.2 传递变量到远程线程
前面的例子中,用户可以传递要寻找的进程名作为变量。ArgumentList参数能帮助用户传递到远程线程中:
$procName = "powershell"
Invoke-Command -ComputerName (get-content c:\scripts\servers.txt) ` -ScriptBlock {param ($Name) Get-Process -Name $Name} –ArgumentList $procName
上面的例子中可以显示如何使用-ArgumentList参数传递本地变量到远程线程。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: