我根本没有真正编写过任何 Windows 脚本,所以我不知道如何完成这个脚本。无论如何,基本上我们想要做的是有一个脚本,它将接受关于哪个 IIS AppPool 回收的参数。我对 Google 进行了一些研究,但在让事情正常运行方面并没有取得太大的成功。
这是我现在正在尝试的:
$appPoolName = $args[0]
$appPool = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPools" Where-Object {$_.Name -eq "W3SVC/APPPOOLS/$appPoolName"}
$appPool.Recycle()
和我得到的错误:
Get-WmiObject : A parameter cannot be found that matches parameter name '$_.Name -eq "W3SVC/APPPOOLS/$appPoolName"'.
无论如何,如果我也知道如何调试这样的东西会很好。我已经通过执行 gwmi -namespace "root\MicrosoftIISv2" -list 修复了原始脚本的一个错误。任何其他类似的提示都会很棒。
谢谢!
更新:这里有更多信息
$appPool = gwmi -namespace "root\MicrosoftIISv2" -class "IISApplicationPools" | Get-Member
. TypeName: System.Management.ManagementObject#root\MicrosoftIISv2\IIsApplicationPools
Name MemberType Definition
---- ---------- ----------
Caption Property System.String Caption {get;set;}
Description Property System.String Description {get;set;}
InstallDate Property System.String InstallDate {get;set;}
Name Property System.String Name {get;set;}
Status Property System.String Status {get;set;}
__CLASS Property System.String __CLASS {get;set;}
__DERIVATION Property System.String[] __DERIVATION {get;set;}
__DYNASTY Property System.String __DYNASTY {get;set;}
__GENUS Property System.Int32 __GENUS {get;set;}
__NAMESPACE Property System.String __NAMESPACE {get;set;}
__PATH Property System.String __PATH {get;set;}
__PROPERTY_COUNT Property System.Int32 __PROPERTY_COUNT {get;set;}
__RELPATH Property System.String __RELPATH {get;set;}
__SERVER Property System.String __SERVER {get;set;}
__SUPERCLASS Property System.String __SUPERCLASS {get;set;}
ConvertFromDateTime ScriptMethod System.Object ConvertFromDateTime();
ConvertToDateTime ScriptMethod System.Object ConvertToDateTime();
Delete ScriptMethod System.Object Delete();
GetType ScriptMethod System.Object GetType();
Put ScriptMethod System.Object Put();
gwmi -namespace "root\MicrosoftIISv2" -class "IISApplicationPools"
__GENUS : 2
__CLASS : IIsApplicationPools
__SUPERCLASS : CIM_LogicalElement
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : IIsApplicationPools.Name="W3SVC/AppPools"
__PROPERTY_COUNT : 5
__DERIVATION : {CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : IRON
__NAMESPACE : root\MicrosoftIISv2
__PATH : \\IRON\root\MicrosoftIISv2:IIsApplicationPools.Name="W3SVC/A
ppPools"
Caption :
Description :
InstallDate :
Name : W3SVC/AppPools
Status :