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 ***************************************************************
将在后续的工作中一一给大家分享。
项目背景:
在测试中使用一个公网证书,每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 ***************************************************************
相关文章推荐
- PowerShell 运维菜鸟系列-02-批量取n台Windows KEY(2018年大年初一奉献)
- Lync 项目经验-32-批量为n台服务器导入PFX证书-实战(图解)
- PowerShell 运维菜鸟系列-04-批量-启用用户-启用企业语音-设置分机号(项目中)
- Exchange Server 2010续定证书系列3-将续定后证书导入服务器
- Exchange Server 2010续定证书系列5-将续定后证书导入其它服务器
- PowerShell 运维菜鸟系列-03-设置-所有用户-OWA-时区-语言-跳过-时区设置)
- 程序员的智囊库系列之1--服务器与运维
- IIS服务器证书的导入 IIS 5、IIS 6、IIS 7
- Lync 2013边缘服务器部署6—导入证书
- Microsoft Windows 2008 IIS 7.0 -PFX证书导入
- CA服务器开开发(一)---颁发证书,生成pfx证书安装文件
- Lync 2013边缘服务器部署6—导入证书
- HTTPS 服务器的架设 - web 网站证书的导出、导入和删除
- Provisioning Services 7.6 入门到精通系列之十一:批量导入目标设备
- Exchange系列—为客户端访问服务器配置证书 推荐
- IIS服务器证书的导入(IIS 5、IIS 6、IIS 7 )
- Powershell与运维之服务器管理(一) 利用Powershell管理HP服务器 推荐
- 批量将本地sql导入到服务器mysql数据库中,和将服务器中的sql导出到本地
- [Shell脚本工具]-01批量检测服务器接口状态码
- Exchange Server 2016管理系列课件01.批量创建测试域账户