Soldato
I think I know why PS throws a wobbly as there could be an instance where the property contains more values than another but in this case every property will contain the same number of values.
cmdlet returns the following:
I need to pull out the values, otherwise when I pass the output to another environment, it returns the cmdlet name. So,
returns
but,
fails as I suspect for the assumption above. It would seem a really simply thing to do but brainboy here cannot fathom it
The preference would be to keep the headers as well but I'll take just getting the value data.
TIA!
E: oops
so piping to Out-String seems an obvious winner but thinking about it, I probably do want to drop the headers. Ultimately I'm running a query to return all open sessions for a specific user with a view to then perform actions on that session e.g. disconnect, logoff etc.
eh Format-Table -HideTableHeaders works but the formatting isn't great.
Morphed into something else now, somewhat c# related. I'm calling a script with an argument/parameter ..
In this instance I'm just trying to verify the argument is passed to the script;
I'm guessing the syntax is incorrect as it just returns "username -" as opposed to the expected "username - TestuserName"
Replacing AddScript with AddCommand worked!
cmdlet returns the following:
Code:
CatalogName ClientName DesktopGroupName BrokeringUserName
----------- ---------- ---------------- -----------------
BANANA SIRRUS BANANA_GROUP DOMAIN\USERNAME
APPLE EARTH APPLE_GROUP DOMAIN\USERNAME
Code:
Select-Object -ExpandProperty CatalogName
Code:
BANANA
APPLE
Code:
Select-Object -ExpandProperty CatalogName, ClientName,DesktopGroupName, BrokeringUserName
The preference would be to keep the headers as well but I'll take just getting the value data.
TIA!
E: oops
so piping to Out-String seems an obvious winner but thinking about it, I probably do want to drop the headers. Ultimately I'm running a query to return all open sessions for a specific user with a view to then perform actions on that session e.g. disconnect, logoff etc.
eh Format-Table -HideTableHeaders works but the formatting isn't great.
Morphed into something else now, somewhat c# related. I'm calling a script with an argument/parameter ..
Code:
// Add the script to the PowerShell object
// shell.Commands.AddScript(Input.Text);
shell.Commands.AddScript("D:\\Local_Scripts\\sessioncall.ps1");
// Add Params
// shell.Commands.AddParameter(null,User.Identity.Name);
shell.Commands.AddParameter(null,"TestuserName");
// Execute the script
var results = shell.Invoke();
Code:
$username= "$($args[0])"
#param($username)
Write-Output "username - $username" | Out-String
Replacing AddScript with AddCommand worked!
Code:
// Add the script to the PowerShell object
// shell.Commands.AddScript(Input.Text);
// shell.Commands.AddScript("D:\\Local_Scripts\\sessioncall.ps1");
shell.Commands.AddCommand("D:\\Local_Scripts\\sessioncall.ps1");
// Add Params
// shell.Commands.AddParameter(null,User.Identity.Name);
shell.Commands.AddParameter("Username", User.Identity.Name);
// shell.Commands.AddArgument(User.Identity.Name);
// Execute the script
var results = shell.Invoke();
Last edited: