您的位置:首页 > 运维架构 > Shell

PowerShell 运维菜鸟系列-01-批量为n台服务器导入PFX证书(2017年除夕奉献)

2018-02-15 21:58 555 查看
作为PowerShell菜鸟,我用PowerShell已有n年了,不怎么使用,但积累不少实用的PowerShell脚本。
将在后续的工作中一一给大家分享。

项目背景:
在测试中使用一个公网证书,每3个月需要更新一次,重新申请、重新颁发、重新导入、重新分配。
但重新导入的时候,如果十台、二十台导入很繁琐,同时也花时间。
本次测试花了我2天时间,从2018年2月14日星期三到2018年2月15日星期四。
本博文写于2018年02月15日 20:00(2018年除夕之夜)。边看春节联欢晚会,边写博文。

1. 准备证书文件












2. 准备CSV-For-All Computers






3. 准备PowerShell-For-All Computers






#param( [string] $importfile = $(Read-Host -prompt "Please enter a file name"))
#$importedComputers = Import-CSV $importfile

$importedComputers = Import-CSV .\ComputerNames.csv
foreach ($importedComputer in $importedComputers)
{
Enter-PSSession -ComputerName $importedComputer.nComputerName

$pfxpath = 'C:\Cert\i-x-Cloud.com.pfx'
$password01 = '1'

Add-Type -AssemblyName System.Security
$cred01 = ConvertTo-SecureString "1" -AsPlainText -Force

$Username = 'i-x-Cloud\administrator'
$Password = 'Aa123456'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

Invoke-Command -ComputerName $importedComputer.nComputerName -ScriptBlock { Import-PfxCertificate -Exportable -FilePath 'C:\Cert\i-x-Cloud.com.pfx' Cert:\LocalMachine\my -Password (ConvertTo-SecureString -String '1' -AsPlainText -Force)} -credential $Cred
}
注意:
A.$importedComputers = Import-CSV .\ComputerNames.csv 读取本地位置的csv中的计算机名到脚本中。
B.$importedComputer.nComputerName 读取CSV中nComputerName中列。
C.$pfxpath = 'C:\Cert\i-x-Cloud.com.pfx' 读取本地PFX证书
D. -Password (ConvertTo-SecureString -String '1' -AsPlainText -Force) 读取PFX的证书的密码
E. Invoke-Command -ComputerName $importedComputer.nComputerName 在远程服务器上执行PowerShell脚本

4. 运行PowerShell



执行



5. 针对菜鸟,有几个难点:
A. 如何实现将PFX证书导入到任何Windows Server 2012 R2加域服务器。
B. 如何实现将PFX证书的密码传入到远程服务器中执行。
C. 将PFX证书放在本地C盘之中,如C:\Cert\i-x-Cloud.com.pfx,目的读取方便。放在\\011-DC01.i-x-Cloud.com\Cert\i-x-Cloud.com.pfx,会存在一个问题,通过网络读取,需要解决用户名和密码的问题。未考虑如何去解决,后续如果有机会,再去解决。如果你解决了,可以奉献给我,我更新到本博文中,方便大家。

如果有问题,请联系QQ群:
企业统一沟通平台实战 65235615

本讲师线下视频课程:(咨询:3313395633(QQ))课程一:《大企业Skype for Business Server 2015/Lync Server 2013部署实战》课程二:《大企业云桌面部署实战》课程三:《跟菜鸟学Cisco UC部署实战》 本讲师其它视频课程:套餐:***************************************************************《私有云部署实战》-5个云计算产品(含:Mircrosoft,Linux)(套餐)http://edu.51cto.com/pack/view/id-516.html ***************************************************************《私有云-部署实战-1-微软-第1代-SSP20》《私有云-部署实战-2-微软-第2代-SC2012R2》《私有云-部署实战-3-微软-第3代-WAP》《私有云-部署实战-4-Linux-Cloudstack 4.3》《私有云-部署实战-5-Linux-OpenStack-juno》******************************************************************************************************************************《私有云-基本功能-PK-微软-And-Linux》***************************************************************http://edu.51cto.com/course/course_id-4875.html ******************************************************************************************************************************从零开始一步一步学习Lync Server 2013(套餐)http://edu.51cto.com/pack/view/id-65.html ***************************************************************包括:第 01 阶段-规划第 02 阶段-自动-管理-虚拟机第 03 阶段-准备-基础-架构第 04 阶段-部署-基础-环境第 05 阶段-部署-企业语音第 06 阶段-部署-呼叫管理功能***************************************************************《在多林环境中部署 Lync Server 2013》http://edu.51cto.com/course/course_id-5896.html ******************************************************************************************************************************《Skype for Business Server 2015-企业内部-部署》http://edu.51cto.com/course/course_id-4158.html 《Skype for Business Server 2015-企业外部-部署》http://edu.51cto.com/course/course_id-5890.html ***************************************************************
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Lync Skype for