【发布时间】:2016-04-23 09:26:35
【问题描述】:
我正在尝试在 Windows Server 2008 R2 VM 上使用 PowerShell 创建 IIS 应用程序和应用程序池。 powershell脚本如下:
Param(
[string] $branchName,
[string] $sourceFolder
)
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script. `nPlease re-run this script as an Administrator."
Exit
}
$appPool = $branchName
$site = "Default Web Site"
#Add APPPool
New-WebAppPool -Name $appPool -Force
#Create Applications
New-WebApplication -Name $branchName -Site $site -PhysicalPath $sourceFolder - ApplicationPool $appPool -Force
如果我在 PowerShell ISE 中运行脚本,它工作正常,但如果我从命令行(或使用命令行的批处理文件)运行它,我会收到错误
New-WebAppPool 一词未被识别为 cmdlet 的名称...等等。
有没有办法可以在 ISE 中安装 Web 管理 cmdlet,但不能在命令行中安装?
【问题讨论】:
-
请显示您正在运行的确切代码以及代码产生的确切错误。同时显示
$PSVersionTable的输出。 -
您可能需要显式导入 cmdlet:
Import-Module WebAdministration
标签: powershell batch-file iis powershell-ise cmdlets