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

作为PowerShell菜鸟,我用PowerShell已有n年了,不怎么使用,但积累不少实用的PowerShell脚本。

将在后续的工作中一一给大家分享。

项目背景:

在测试中使用一个公网证书,每3个月需要更新一次,重新申请、重新颁发、重新导入、重新分配。

但重新导入的时候,如果十台、二十台导入很繁琐,同时也花时间。

本次测试花了我2天时间,从2018年2月14日星期三到2018年2月15日星期四。

本博文写于2018年02月15日 20:00(2018年除夕之夜)。边看春节联欢晚会,边写博文。

1. 准备证书文件

979b86424cc430bbb79c662de48f1c19.png

59cddd3ee1cafd7e81b9201ff920f623.png

b414ee57469fc0a2f9e6080ec4975484.png

672564636c7be92caf709969d9d94736.png

2. 准备CSV-For-All Computers

3d97ce34686baa3921ce061a676db755.png

08f32a3ccd88fc5165c26adb00e8de28.png

3. 准备PowerShell-For-All Computers

4dee3ea31eb76b90728b42d63db17df8.png

115a974aa8fb960ce02f29b7e16a8d83.png

#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

f38369f20dbe6492a2f93b04e1efb4e5.png

执行

f787623d6934b924e40b20a7d0b11eab.png

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)(套餐)

***************************************************************

《私有云-部署实战-1-微软-第1代-SSP20》

《私有云-部署实战-2-微软-第2代-SC2012R2》

《私有云-部署实战-3-微软-第3代-WAP》

《私有云-部署实战-4-Linux-Cloudstack 4.3》

《私有云-部署实战-5-Linux-OpenStack-juno》

***************************************************************

***************************************************************

《私有云-基本功能-PK-微软-And-Linux》

***************************************************************

***************************************************************

***************************************************************

从零开始一步一步学习Lync Server 2013(套餐)

***************************************************************

包括:

第 01 阶段-规划

第 02 阶段-自动-管理-虚拟机

第 03 阶段-准备-基础-架构

第 04 阶段-部署-基础-环境

第 05 阶段-部署-企业语音

第 06 阶段-部署-呼叫管理功能

***************************************************************

《在多林环境中部署 Lync Server 2013》

***************************************************************

***************************************************************

《Skype for Business Server 2015-企业内部-部署》

《Skype for Business Server 2015-企业外部-部署》

***************************************************************

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值