【发布时间】:2016-05-09 16:06:17
【问题描述】:
我有 2 个脚本如下,用于获取 IIS 网站。
IIS 6 -
$website = Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" | Select ServerComment | Format-Table -HideTableHeaders | out-file c:\website.txt
$b = Get-Content -Path C:\website.txt
$b | ForEach {$_.TrimEnd()} | ? {$_.trim() -ne '' } > C:\website.txt
$b = Get-Content -Path C:\website.txt
@(ForEach ($a in $b) {$a.Replace(' ', '')}) > C:\website.txt
Get-Content C:\website.txt
IIS 7+
Import-Module webadministration
$a = Get-Website | Select-Object Name
$a | ForEach-Object {
$_.name = $_.name.replace(" ","")
}
$a | Format-Table -HideTableHeaders | Out-File $DeviceDrive\Apps\NetprobeNT\Auto-monitor\Website.txt
$b = Get-Content -Path $DeviceDrive\Apps\NetprobeNT\Auto-monitor\Website.txt
$b | ForEach {$_.TrimEnd()} | ? {$_.trim() -ne '' } > $DeviceDrive\Apps\NetprobeNT\Auto-monitor\Website.txt
$b = Get-Content -Path $DeviceDrive\Apps\NetprobeNT\Auto-monitor\Website.txt
@(ForEach ($a in $b) {$a.Replace(' ', '')}) > $DeviceDrive\Apps\NetprobeNT\Auto-monitor\Website.txt
我有一个用于 IIS 6(Windows 2003 主机)的不同脚本,因为 webadministration 模块不适用于 II6。
我需要添加一个if 语句,该语句将添加逻辑以运行依赖于主机操作系统的正确代码,以及是否存在 W3SVC 服务(万维网发布服务)(运行或停止)。有点像
如果存在 W3SVC
检查主机操作系统
IF 操作系统 = Windows 2003
运行 II6 代码
别的
运行II7+代码
我不知道从哪里开始这个脚本。 PowerShell 和脚本对我来说是新的,这是我正在创建的第一个脚本的一部分。任何帮助将不胜感激。
我可以获得主机操作系统,但对如何将逻辑放入其中以获得所需的结果感到困惑。
(Get-WmiObject Win32_OperatingSystem).Name
【问题讨论】:
标签: powershell iis powershell-2.0