通过Powershell登录远程机器

时间:2018-01-10 18:21:29

标签: powershell deployment automation

我一直在寻找一些我认为相对简单的东西,但我没有找到答案。我正在编写一个Powershell脚本作为开发人员,让IT Ops员工将我们的一个Web应用程序自动部署到生产服务器。目前,该脚本要求Ops在运行脚本之前通过Windows资源管理器手动登录到远程目标服务器。我想让脚本自动尝试连接到指定的服务器,并提示谁运行它以获取凭据。是否有Powershell命令登录服务器而无需指定共享路径?

1 个答案:

答案 0 :(得分:0)

不确定这是否符合您的要求,但它是我用于远程安装Microsoft SCCM客户端的Powershell脚本。它使用PsExec,因此这是一个要求。也许这会让你开始,你可以从那里找到你的前进道路。

$Computer = Read-Host -Prompt 'Input Computer Name'

If (Test-Connection -ComputerName $Computer -Count 1 -ea 0 -Quiet) {
net use S: \\$Computer\C$
New-Item -ItemType Directory -Path S:\SCCM
Copy-Item C:\SCCM\*.* S:\SCCM
C:\Sysinternals\PsExec.exe \\$Computer C:\SCCM\ccmsetup.exe /source:"C:\SCCM" /[your server details] /forceinstall

Remove-Item S:\SCCM\*.* -Recurse
Remove-Item S:\SCCM -Recurse
net use S: /Delete

} else {
"$Computer is not online"
}

只要使用提升的权限运行此脚本,我就没有安装失败,也不需要任何远程登录。