如何在PowerShell中检查所需的NWAdmin命令-url作为参数?

时间:2014-08-14 05:25:47

标签: powershell sharepoint

通过powershell,我想执行NWAdmin命令。我写了如下所示的简单命令。

$spWebURL = Read-Host "Enter Web Application URL:"
$spWebApp = Get-SPWebApplication $spWebURL
$NWAdminCommand = Read-Host "Enter NWAdmin Command to perform request action:"
if(Test-Path(".\NWAdmin.exe"))
{ 
foreach ($SPSite in $spWebApp.Sites)
{
    foreach($SPWeb in $SPSite.AllWebs)
    {
        $SiteURL= $SPWeb.URL;

        $NWAdminCommandTest=".\NWAdmin.exe -o $NWAdminCommand -url $SiteURL";

        iex $NWAdminCommandTest;

    }
}
}

NWAdmin命令格式如下所示。

NWAdmin.exe -o PurgeWorkflowData [-workflowName workflowName] [-state[All|Running|Completed|Cancelled|Error]] [-url teamsiteUrl [-listName listName]] [-deletedLists] 

如何检查用户是否输入 PurgeWorkflowData 作为命令,是否需要NWAdmin命令 -url 作为参数?

1 个答案:

答案 0 :(得分:0)

我不确定我最后是否理解了这个问题但您可以在第二个PurgeWorkflowdata

中使用-eq来检查是否有人ForEach作为命令

这是你可以玩的一些代码

$spWebURL = Read-Host "Enter Web Application URL:"
$spWebApp = Get-SPWebApplication $spWebURL
$NWAdminCommand = Read-Host "Enter NWAdmin Command to perform request action:"
if(Test-Path(".\NWAdmin.exe"))
{ 
    foreach ($SPSite in $spWebApp.Sites)
    {
        foreach($SPWeb in $SPSite.AllWebs)
        {
            if ($NWAdminCommand -eq 'PurgeWorkflowData')
            {
                Write-Host "User entered the magical command PurgeWorkFlowData <do stuff here>"
            }
            else
            {
                $SiteURL= $SPWeb.URL;

                $NWAdminCommandTest=".\NWAdmin.exe -o $NWAdminCommand -url $SiteURL";

                iex $NWAdminCommandTest;
            }
        }
    }
}