1

現在、いくつかの管理レポート用にPowershell Web サーバー PoSH ( http://poshserver.net/ ) を試しています。しかし、出力をフォーマットする方法がわかりません。

最初から:管理者権限で、デフォルトのショートカットでコンソールを起動します。Import-Module PoSHServer次に、と入力しStart-PoSHServerます。Web サーバーが起動したら、本体セクションに $(command) という 1 行のコードを含む単純な index.ps1 ファイルを作成します。

たとえば、Get-Service Mpssvcコマンドを使用したいのですが、得られるものは次のとおりです。

System.ServiceProcess.ServiceController

私は試してみGet-Service MpsSvc | Select Name,Statusます。出力:

@{Name=MpsSvc; Status=Running}

コマンドレットについても同じことですGet-Process。プロセスのリストを含む出力がありますが、次のように表示されます: System.Diagnostics.Process (AcroRd32)...

ただし、(Posh デモンストレーション Web ページで使用されている) のような一部の cmlet はGet-Date正常に動作し、「通常の」出力が得られます。

ドキュメントを読みましたが、そのために役立つ例はありません。

「クリーン」でコンソールのような出力を取得するために、powershell コードをどのように記述できますか?

4

1 に答える 1

1

I just downloaded and installed Posh-Server yesterday after reading this post.

If you want output to look like console inside a web-page you are probably looking at this from the wrong angle, you need to think string not console. Your code is supposed to be running inside of a here-string, in the example. So I got the hint here that the standard console formatter does not apply, posh-server will use whatever it wants to to turn your returned object into a STRING!. Your code output will get turned into a string using whatever formatter it deems applies unless you explicitly return a string - which the example script does correctly do. So try this on the console

get-process "power*" | out-string -width 80

And then try it in your posh-server script. You probably really wanted this:

Get-Service MpsSvc | Select Name,Status | out-string -width 120

Hope that helps - I think the lack of examples in this project is a good thing because this is really a very simplistic web-server; lots of conceptual thinking required before you even start :) .

于 2013-10-02T08:06:50.717 に答える