[英]Get IIS Bindings from many webservers using powershell remoting, invoke command and module webadministration
Right now I made a small script to see my actual webbindings on a server. 现在,我做了一个小脚本,以查看服务器上的实际Web绑定。
Import-Module WebAdministration;
$today = Get-Date -format M.d.yyyy
$machine = hostname
function IISRport
{
Get-ChildItem -path IIS:\Sites | out-file "\\server01\d$\_utils\PowerShell Scripts\IISexport\IISExport$machine$today.txt"
}
IISReport
This wil outfile my IIS bindings to txt which works brilliant. 这将使我的IIS绑定胜过txt,效果很好。 I now need to invoke that command to several other servers and save the output file on one server. 现在,我需要对其他几台服务器调用该命令,并将输出文件保存在一台服务器上。 since the machine name will be diffrent I expect as many outputs as servers. 由于机器名称将有所不同,因此我希望输出与服务器一样多。
I tried for example the following : 我尝试例如以下内容:
icm -comp server02 {get-childitem -path IIS:\Sites}
But than the imported Module webadministration is not working, since I only loaded on one server. 但是比导入的模块webadministration无法正常工作,因为我仅在一台服务器上加载。 So I tried to load that remotely using : 所以我尝试使用以下方式远程加载该文件:
icm -comp server02 {import-module webadministration}
without success. 没有成功。
How to achieve that? 如何实现呢?
This will get the data from all machines defined in $machines
and output to \\\\server01\\d$_utils\\PowerShell Scripts\\IISexport\\ . 这将从$machines
machines中定义的所有计算机中获取数据,然后输出到\\\\ server01 \\ d $ _utils \\ PowerShell Scripts \\ IISexport \\中 。
$today = Get-Date -format M.d.yyyy
$machines = @("server01","server02")
foreach($machine in $machines) {
icm -comp $machine { param($machine,$today)
import-module webadministration;
Get-ChildItem -path IIS:\Sites |
out-file "\\server01\d$\_utils\PowerShell Scripts\IISexport\IISExport$machine$today.txt"
} -ArgumentList $machine,$today
}
You can of course change the output path( and import list of machines from a file,AD or some other source). 当然,您可以更改输出路径(并从文件,AD或其他来源导入机器列表)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.