如何在c#中使用powershell哈希表。 [英] How to use powershell hash table in c#.
问题描述
大家好,
我想在c#中使用以下powershell命令并获得所需的输出。
Powershell脚本:
foreach(获取邮箱中的$ a){get-activesyncdevicestatistics -mailbox $ a.identity |选择DeviceFriendlyName,Devicetype,DeviceUserAgent,@ {Name =User Name; expression = {$ a.displayname}}}
-------- -------------------------------------------------- --------------
我已经制作了如下代码,但需要你的帮助来处理选择带有哈希表的部分。请告诉我,如何在下面的代码中包含选择DeviceFriendlyName,Devicetype,DeviceUserAgent,@ {Name =User Name; expression = {$ a.displayname}}}。
----------------------------------------- -----------------------------------
C#代码:
Hi All,
I want to use the below powershell command in c# and get the desired output.
Powershell script:
foreach($a in get-mailbox){get-activesyncdevicestatistics -mailbox $a.identity | Select DeviceFriendlyName, Devicetype, DeviceUserAgent,@{Name="User Name";expression={$a.displayname}}}
------------------------------------------------------------------------
I have made the code as below, but need your help to work on Select part with hash table. Please let me know, how I can include the "Select DeviceFriendlyName, Devicetype, DeviceUserAgent,@{Name="User Name";expression={$a.displayname}}}" in the below code.
----------------------------------------------------------------------------
C# code:
PowerShellpowershell = PowerShell.Create();
PSCommandcommand = newPSCommand();
command.AddCommand("Get-Mailbox");
command.AddCommand("where-object");
command.AddParameter("Filterscript", scriptBlock.Create("!$_.name.startswith(\"DiscoverySearchMailbox\")"));
powershell.Commands = command;
powershell.Runspace = CreateRunSpace.GetRunSpace();
varresult = powershell.Invoke();
PSCommandcommand1 = newPSCommand();
command1.AddCommand("write-output");
command1.AddParameter("InputObject", result);
command1.AddCommand("Foreach-Object");
command1.AddParameter("Process", ScriptBlock.Create("Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity"));
powershell.Commands = command1;
powershell.Runspace = CreateRunSpace.GetRunSpace();
var result1 = powershell.Invoke();
推荐答案
a in get-mailbox){get-activesyncdevicestatistics -mailbox
a in get-mailbox){get-activesyncdevicestatistics -mailbox
a.identity |选择DeviceFriendlyName,Devicetype,DeviceUserAgent,@ {Name =User Name; expression = {
a.identity | Select DeviceFriendlyName, Devicetype, DeviceUserAgent,@{Name="User Name";expression={
a.displayname}}}
------------------------------------------------ ------------------------
我已经制作了如下代码,但需要你的工作帮助选择带有哈希表的零件。请告诉我,我如何能够包含选择DeviceFriendlyName,Devicetype,DeviceUserAgent,@ {Name =User Name; expression = {
a.displayname}}}
------------------------------------------------------------------------
I have made the code as below, but need your help to work on Select part with hash table. Please let me know, how I can include the "Select DeviceFriendlyName, Devicetype, DeviceUserAgent,@{Name="User Name";expression={
这篇关于如何在c#中使用powershell哈希表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!