power shell远程_PowerShell远程管理02——Powershell远程管理的几种方式

上一节,我们简单介绍了,PowerShell远程管理所依赖的三个服务。这一节我们来学习下PowerShell远程管理的几种方式。

上一节:PowerShell远程管理01——Powershell远程管理依赖的服务及配置

Powershell应该有五种远程管理的方式

分别是:

使用交互式会话

使用远程执行命令 (Invoke-command -ScriptBlock {})

使用远程运行脚本(Invoke-command -FilePath )

建立持久连接 (New-PSSession)

其他支持远程执行的命令( [-ComputerName ])

1、使用交互式会话

使用“Enter-PSSession RemoteComputer”启动一个交互式会话,然后可以在会话中执行Powershell命令,如同在此服务本地执行Powershell一样。

# 基本结构如下

Enter-PSSession -Credential $Credential

Exit-PSSession

实际操作记录如下:

PS C:\> Enter-PSSession -ComputerName "sz-test1119.test.local"

[sz-test1119.test.local]: PS C:\Users\xxx\Documents>

[sz-test1119.test.local]: PS C:\Users\xxx\Documents> cd c:\

[sz-test1119.test.local]: PS C:\>

[sz-test1119.test.local]: PS C:\>

[sz-test1119.test.local]: PS C:\> Get-Service "winrm"

Status Name DisplayName

------ ---- -----------

Running winrm Windows Remote Management (WS-Manag...

[sz-test1119.test.local]: PS C:\> Exit-PSSession

2、使用远程执行命令 (Invoke-command -ScriptBlock {})

借助于“Invoke-command”的“-ComputerName”参数和“-ScriptBlock”参数直接在本地写Powershell命令块在远程服务器执行.

# 基本命令结构

Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-UICulture} -Credential $Credential

PS C:\> Invoke-Command -Credential $cred -ComputerName "sz-test1122.test.local"

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值