3

「フル」のリモート実行スペースを許可するようにIISを既に構成しているとすると、Powershellが「%」が見つからないという例外を解決するにはどうすればよいですか。

次に、問題のあるステートメントをコメントアウトするfor..eachと、New-Objectが見つかりませんと表示されます。

インポートがありませんか?コメントに基づいて、WinRMの構成、またはExchange2010の役割のアクセス許可が欠落している可能性があります。

public static void testExchangeMBScript()
{
  PSCredential credential = new PSCredential(@"domain\me", createPassword("pw"));

WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "exchangehost.company.com", 80, "/Powershell", "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);

connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;

Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);

try
{
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();

    string ps1 = "Get-MailboxDatabase -Status";
    string PSFull = @" $Databases = Get-MailboxDatabase -Status
    foreach($Database in $Databases) {
        $DBSize = $Database.DatabaseSize
        $MBCount = @(Get-MailboxStatistics -Database $Database.Name).Count

        $AllMBStats = Get-MailboxStatistics -Database $Database.Name    
     $MBItemAssocCount = $AllMBStats   |   %{$_.AssociatedItemCount.value} |  Measure-Object -Average   -Sum
     $MBDeletedCount =   $AllMBStats   |   %{$_.DeletedItemCount.value} |  Measure-Object -Average   -Sum
     $MBItemCount =      $AllMBStats   |   %{$_.ItemCount.value} |  Measure-Object -Average  -Sum
     $MBDeletedItemSize= $AllMBStats   |   %{$_.TotalDeletedItemSize.value.ToMb() } |  Measure-Object -Average  -Sum
     $MBItemSize   =     $AllMBStats   |   %{$_.TotalItemSize.value.ToMb()} |  Measure-Object -Average    -Sum      

        New-Object PSObject -Property @{
Server = $Database.Server.Name
DatabaseName = $Database.Name
UserCount = $MBCount
""DatabaseSize (GB)"" = $DBSize.ToGB()
""AverageMailboxSize (MB)"" =  $MBItemSize.Average
""WhiteSpace (MB)"" = $Database.AvailableNewMailboxSpace.ToMb()
ItemCount = $MBItemCount.Sum
""LogicalSize (MB)"" =   $MBItemSize.Sum
        }
    }
";
    pipeline.Commands.AddScript(PSFull);



    // This method cannot be called multiple times on a given pipeline. The state of the 
    // pipeline must be NotStarted when Invoke is called. When this method is called, it
    // changes the state of the pipeline to Running. 
    // see http://msdn.microsoft.com/en-us/library/windows/desktop/ms569128(v=vs.85).aspx
    if (pipeline.PipelineStateInfo.State == PipelineState.NotStarted)
    {
        Collection<PSObject> results = pipeline.Invoke();
    }
}
catch (RemoteException re)
{

    // if: Assignment statements are not allowed in restricted language mode or a Data section.
    // then: configure IIS application settings PSLanguageMode = FullLanguage
}
catch (Exception e)
{

}
        }
4

2 に答える 2

1

リモートセッションは、制約のある実行スペースです。スクリプトに必要なコマンドレットを使用することはできません。制約のないローカル実行スペースを使用し、そこから、invoke-commandを使用してリモート実行スペースでExchange管理コマンドレットを実行する必要があると思います。

$ AllMBStats = invoke-command {Get-MailboxStatistics -Database $ databasename} -argumentlist $ database.name -connectionuri "http://exchangehost.company.com/powershell"

次に、ローカル実行スペースでそれからのリターンを処理します。

于 2012-02-12T16:34:36.387 に答える
0

ローカルランスペースを作成し、そのPS1内からExchange2010コマンドをインポートしてみてください

http://blogs.technet.com/b/exchange/archive/2009/11/02/3408653.aspx

于 2012-02-15T23:39:55.783 に答える