internal static PowerShell GetPowerShell(object data) { PSObject psObject = PSObject.AsPSObject(data); if (psObject == null) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.CantCastRemotingDataToPSObject, new object[] { data.GetType().FullName }); } return(PowerShell.FromPSObjectForRemoting(GetPropertyValue <PSObject>(psObject, "PowerShell"))); }