Soldato
Another silly pickle with Powershell and c#.
I have an array built from the output of a cmdlet which looks like this:
Member
This array is generated via PowerShell and then parsed via this call and class (the offending columns are commented out).
It throws a wobbly as it is unable to parse System.String or SessionState (ENV and SessionState(?!)) as standard strings. I would imagine the easiest solution here would simply be to change the member types of the offending columns BUT I cannot seem to find an easy or obvious way to do this without losing the array structure. Even when converting the lot to an array string it then defines all columns as System.string.
Possibly backside about face but are you able to redefine object definitions within an array to String (as opposed to System.String).
TIA!
I have an array built from the output of a cmdlet which looks like this:
Code:
UserFullName : usera
BrokeringTime : 29/02/2020 06:47:11
ClientName : clienta
DesktopGroupName : SHARED_PRD
SessionState : Active
Uid : 1234567
MachineName : Servera
ENV : UK
UserFullName : usera
BrokeringTime : 29/02/2020 06:57:11
ClientName : clientb
DesktopGroupName : SHARED_PRD
SessionState : Active
Uid : 7654321
MachineName : Serverb
ENV : US
Code:
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
BrokeringTime NoteProperty datetime BrokeringTime=29/02/2020 06:47:11
ClientName NoteProperty string ClientName=clienta
DesktopGroupName NoteProperty string DesktopGroupName=SHARED_PRD
ENV NoteProperty System.String ENV=UK
MachineName NoteProperty string MachineName=Servera
SessionState NoteProperty SessionState SessionState=Active
Uid NoteProperty long Uid=1234567
UserFullName NoteProperty string UserFullName=usera
Code:
r => new MyClass
{
UserFullName = (string)r.Properties["UserFullName"].Value,
BrokeringTime = (DateTime)r.Properties["BrokeringTime"].Value,
ClientName = (string)r.Properties["ClientName"].Value,
DesktopGroupName = (string)r.Properties["DesktopGroupName"].Value,
//SessionState = (string)r.Properties["SessionState"].Value,
Uid = (Int64)r.Properties["Uid"].Value,
MachineName = (string)r.Properties["MachineName"].Value,
//ENV = (string)r.Properties["ENV"].Value,
}
);
internal class MyClass
{
public string UserFullName { get; set; }
public DateTime BrokeringTime { get; set; }
public string ClientName { get; set; }
public string DesktopGroupName { get; set; }
public string SessionState { get; set; }
public Int64 Uid { get; set; }
public string MachineName { get; set; }
public string ENV { get; set; }
}
Possibly backside about face but are you able to redefine object definitions within an array to String (as opposed to System.String).
TIA!