工作组环境下管理windows.

此处指的是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-on-target-computer.jpg

远程执行指令的两种方式

winrm –r:computername command

icm hostname {powershell-command}

icm是Invoke-Command的简写

(不在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在运行:get-service winrm
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所示的提示符:

2041947.jpg

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参数传递本地变量到远程线程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Microsoft Windows PowerShell 是一种新的命令行外壳和脚本语言,用于进行系统治理和自动化。Windows PowerShell 建立在 .NET Framework 的基础上,IT 专业人员可通过命令或脚本来治理计算机,从而通过系统自动化来提高工作效率。 Windows PowerShell 包括: * 129 个命令行工具(称为“cmdlet”),用于执行常见系统治理任务,如治理服务、进程、事件日志、证书、注册表以及使用 Windows Management Instrumentation (WMI)。 * 采用标准命名约定和通用参数的命令行工具,易于把握和使用;以及用于对数据和对象进行排序、筛选以及格式设置的简便工具。 * 对现有脚本语言、现有命令行工具以及多种 Windows 版本的支持,其中包括 Windows XP、Windows Server 2003、Windows Vista 以及 Windows Server(代码名称为“Longhorn”)。 * 方便的功能,使用户能够浏览数据存储(如注册表和证书存储),就像面对文件系统一样。 * 用于治理位于不同存储中以及采用不同格式的 Windows 数据的标准实用程序,这些数据包括 Active Directory (ADSI)、Windows Management Instrumentation (WMI)、组件对象模型 (COM) 对象、ActiveX 数据对象 (ADO)、HTML 和 XML。 * 在命令行进行的高级表达式分析和 .NET 对象处理,其中包括对对象进行流水线处理以帮助提高 IT 专业人员的工作效率。 * 可扩展的接口,使独立软件供给商和企业开发人员能够构建自定义 cmdlet 以满足特有的应用程序和系统治理要求。 安装本更新程序后,可能需要重新启动计算机。我们根据 Windows Vista 许可条款向您提供本更新程序并授予您使用许可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值