Làm cách nào để tạo Hồ bơi Ứng dụng trên IIS 6.0 bằng tập lệnh PowerShell?Tạo một Hồ bơi Ứng dụng IIS 6.0 bằng Powershell
Đây là những gì tôi đã đưa ra cho đến nay ...
$appPool = [wmiclass] "root\MicrosoftIISv2:IIsApplicationPool"
Cảm ơn
Làm cách nào để tạo Hồ bơi Ứng dụng trên IIS 6.0 bằng tập lệnh PowerShell?Tạo một Hồ bơi Ứng dụng IIS 6.0 bằng Powershell
Đây là những gì tôi đã đưa ra cho đến nay ...
$appPool = [wmiclass] "root\MicrosoftIISv2:IIsApplicationPool"
Cảm ơn
Nó không phải là quá trình rõ ràng nhất, nhưng đây là những gì làm việc cho tôi ..
$AppPoolSettings = [wmiclass]'root\MicrosoftIISv2:IISApplicationPoolSetting'
$NewPool = $AppPoolSettings.CreateInstance()
$NewPool.Name = 'W3SVC/AppPools/MyAppPool'
$Result = $NewPool.Put()
Bạn có thể gặp lỗi khi gọi hàm Put(), nhưng gọi đó là lần thứ hai (hoặc thứ ba) sẽ làm cho nó hoạt động. Điều này là do sự cố với PowerShell V1 và WMI.
Tôi nghĩ rằng tôi có thể chia sẻ tập lệnh mà tôi đã đưa ra. Nhờ vào Steven và leon.
# Settings
$newApplication = "MaxSys.Services"
$poolUserName = "BRISBANE\svcMaxSysTest"
$poolPassword = "ThisisforT3sting"
$newVDirName = "W3SVC/1/ROOT/" + $newApplication
$newVDirPath = "C:\" + $newApplication
$newPoolName = $newApplication + "Pool"
#Switch the Website to .NET 2.0
C:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -sn W3SVC/
# Create Application Pool
$appPoolSettings = [wmiclass] "root\MicrosoftIISv2:IISApplicationPoolSetting"
$newPool = $appPoolSettings.CreateInstance()
$newPool.Name = "W3SVC/AppPools/" + $newPoolName
$newPool.PeriodicRestartTime = 0
$newPool.IdleTimeout = 0
$newPool.MaxProcesses = 2
$newPool.WAMUsername = $poolUserName
$newPool.WAMUserPass = $poolPassword
$newPool.AppPoolIdentityType = 3
$newPool.Put()
# Do it again if it fails as there is a bug with Powershell/WMI
if (!$?)
{
$newPool.Put()
}
# Create the virtual directory
mkdir $newVDirPath
$virtualDirSettings = [wmiclass] "root\MicrosoftIISv2:IIsWebVirtualDirSetting"
$newVDir = $virtualDirSettings.CreateInstance()
$newVDir.Name = $newVDirName
$newVDir.Path = $newVDirPath
$newVDir.EnableDefaultDoc = $False
$newVDir.Put()
# Do it a few times if it fails as there is a bug with Powershell/WMI
if (!$?)
{
$newVDir.Put()
}
# Create the application on the virtual directory
$vdir = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IISWebVirtualDir" -filter "Name = '$newVDirName'"
$vdir.AppCreate3(2, $newPoolName)
# Updated the Friendly Name of the application
$newVDir.AppFriendlyName = $newApplication
$newVDir.Put()
@robert wagner - Tôi sẽ thay đổi xử lý lỗi của bạn thành DO {$ newVDir.Put()} WHILE (! $?) Sau đó, bạn sẽ không cần phải có nút Put() đầu tiên. Vòng lặp do/while sẽ tiếp tục thực hiện việc đặt cho đến khi không có lỗi. Chỉ là một gợi ý. –
Nó có thể bị kẹt trong một vòng lặp vô hạn, nhưng đó là một ý nghĩ. –
bạn luôn có thể có một bộ đếm nhỏ, chỉ thử lại tối đa số lần. – jrista
Tất cả đều tốt! Tôi đã sửa đổi mã để có một lệnh gọi rõ ràng tới lệnh $ newPool.Put() sau lỗi ban đầu. Cảm ơn bạn đã giúp đỡ!
Cảm ơn bạn, hoạt động rất tốt. Tôi nghĩ rằng tôi đã cố gắng đó, nhưng đã được đưa ra bởi lỗi đặt. –
Rất vui khi nó làm việc cho bạn. Lỗi đó là loại mất tập trung, nhưng đây chỉ là V1 của PowerShell. –