So, I want to execute the calculated PowerShell properties (hope the correct name) from C #.
My CmdLet in the PS (Exchange) console looks like this:
Get-Something -ResultSize unlimited |Select-Object DisplayName,@{name="RenamedColumn;expression={$_.Name}},ToBeExpanded -Expand ToBeExpanded |Select-Object DisplayNameRenamedColumn,ToBeExpandedGuid
This works fine, the problem occurs when I try to execute it with C #.
My code is as follows:
List<string> parameters = new List<string>()
{
"DisplayName","@{{name=\"RenamedColumn\";expression={{$_.Name }} }}","ToBeExpanded"
};
List<string> parameters2 = new List<string>()
{
"DisplayName","RenamedColumn","ToBeExpanded","ToBeExpandedGuid"
};
powershell.AddCommand("Get-Something");
powershell.AddParameter("ResultSize","unlimited");
powershell.AddCommand("Select-Object");
powershell.AddParameter("Property",parameters);
powershell.AddParameter("ExpandProperty","ToBeExpanded");
powershell.AddCommand("Select-Object");
powershell.AddParameters("Property",parameters2);
result = powershell.Invoke();
Then my result contains ToBeExpandedGuidnull. So I tried the command without a second choice, and it shows me that it has a column:
@{{name=\"RenamedColumn\";expression={{$_.Name }} }}
So, I thought powershell would not recognize this renaming ... Now my question is, how can I use something like this with C #? Is there any solution?
source
share