What is the equivalent command using Cim instance ?
wmic cpu list /format:list
With Powershell , you can use like this :
Get-CimInstance Win32_Processor
If you want to get all infos about CPU, you can use this command :
Get-CimInstance Win32_Processor | Select *
And if you want to get and choose a specific property, just type this command to look what you want to select as property :
Get-CimInstance Win32_Processor | Get-Member
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object ICloneable.Clone()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetCimSessionComputerName Method string GetCimSessionComputerName()
GetCimSessionInstanceId Method guid GetCimSessionInstanceId()
GetHashCode Method int GetHashCode()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)...
GetType Method type GetType()
ToString Method string ToString()
AddressWidth Property uint16 AddressWidth {get;}
Architecture Property uint16 Architecture {get;}
AssetTag Property string AssetTag {get;}
Availability Property uint16 Availability {get;}
Caption Property string Caption {get;}
Characteristics Property uint32 Characteristics {get;}
ConfigManagerErrorCode Property uint32 ConfigManagerErrorCode {get;}
ConfigManagerUserConfig Property bool ConfigManagerUserConfig {get;}
CpuStatus Property uint16 CpuStatus {get;}
CreationClassName Property string CreationClassName {get;}
CurrentClockSpeed Property uint32 CurrentClockSpeed {get;}
CurrentVoltage Property uint16 CurrentVoltage {get;}
DataWidth Property uint16 DataWidth {get;}
Description Property string Description {get;}
DeviceID Property string DeviceID {get;}
ErrorCleared Property bool ErrorCleared {get;}
ErrorDescription Property string ErrorDescription {get;}
ExtClock Property uint32 ExtClock {get;}
Family Property uint16 Family {get;}
InstallDate Property CimInstance#DateTime InstallDate {get;}
L2CacheSize Property uint32 L2CacheSize {get;}
L2CacheSpeed Property uint32 L2CacheSpeed {get;}
L3CacheSize Property uint32 L3CacheSize {get;}
L3CacheSpeed Property uint32 L3CacheSpeed {get;}
LastErrorCode Property uint32 LastErrorCode {get;}
Level Property uint16 Level {get;}
LoadPercentage Property uint16 LoadPercentage {get;}
Manufacturer Property string Manufacturer {get;}
MaxClockSpeed Property uint32 MaxClockSpeed {get;}
Name Property string Name {get;}
NumberOfCores Property uint32 NumberOfCores {get;}
NumberOfEnabledCore Property uint32 NumberOfEnabledCore {get;}
NumberOfLogicalProcessors Property uint32 NumberOfLogicalProcessors {get;}
OtherFamilyDescription Property string OtherFamilyDescription {get;}
PartNumber Property string PartNumber {get;}
PNPDeviceID Property string PNPDeviceID {get;}
PowerManagementCapabilities Property uint16[] PowerManagementCapabilities {get;}
PowerManagementSupported Property bool PowerManagementSupported {get;}
ProcessorId Property string ProcessorId {get;}
ProcessorType Property uint16 ProcessorType {get;}
PSComputerName Property string PSComputerName {get;}
Revision Property uint16 Revision {get;}
Role Property string Role {get;}
SecondLevelAddressTranslationExtensions Property bool SecondLevelAddressTranslationExtensions {get;}
SerialNumber Property string SerialNumber {get;}
SocketDesignation Property string SocketDesignation {get;}
Status Property string Status {get;}
StatusInfo Property uint16 StatusInfo {get;}
Stepping Property string Stepping {get;}
SystemCreationClassName Property string SystemCreationClassName {get;}
SystemName Property string SystemName {get;}
ThreadCount Property uint32 ThreadCount {get;}
UniqueId Property string UniqueId {get;}
UpgradeMethod Property uint16 UpgradeMethod {get;}
Version Property string Version {get;}
VirtualizationFirmwareEnabled Property bool VirtualizationFirmwareEnabled {get;}
VMMonitorModeExtensions Property bool VMMonitorModeExtensions {get;}
VoltageCaps Property uint32 VoltageCaps {get;}
PSConfiguration PropertySet PSConfiguration {AddressWidth, DataWidth, DeviceID, ExtClock, L2CacheSize, L2CacheSpeed, MaxClockSpeed, PowerManagementSupport...
PSStatus PropertySet PSStatus {Availability, CpuStatus, CurrentVoltage, DeviceID, ErrorCleared, ErrorDescription, LastErrorCode, LoadPercentage,...
And for example you want to select some of them :
Get-CimInstance Win32_Processor |
Select Caption,Manufacturer,Name,NumberOfLogicalProcessors,NumberOfCores,NumberOfEnabledCore,ProcessorType,DeviceID,AddressWidth,Architecture,CpuStatus,CurrentClockSpeed,CurrentVoltage,LoadPercentage,MaxClockSpeed
Related
I am receiving a large block of JSON information from an API call.
This example lists 2 of the items received; normally, this list will contain hundreds.
The JSON received is:
{
"data":[
{
"id":"2324682","type":"organizations","attributes":
{
"psa-integration":null,
"name":"Client1",
"alert":null,
"description":null,
"organization-type-id":null,
"organization-type-name":null,
"organization-status-id":null,
"organization-status-name":null,
"my-glue-account-id":null,
"primary":true,
"quick-notes":null,
"short-name":"P",
"created-at":"2017-09-25T17:21:26.000Z",
"updated-at":"2018-02-09T17:25:34.000Z",
"my-glue-account-status":null,
"logo":"client1.jpg"
},"relationships":{"adapters-resources":{"data":[]}}},
{
"id":"2388378","type":"organizations","attributes":
{
"psa-integration":null,
"name":"Client2",
"alert":null,
"description":null,
"organization-type-id":53460,
"organization-type-name":"E123",
"organization-status-id":17054,
"organization-status-name":"Active",
"my-glue-account-id":null,
"primary":false,
"quick-notes":null,
"short-name":null,
"created-at":"2017-10-16T19:36:30.000Z",
"updated-at":"2018-08-21T19:06:47.000Z",
"my-glue-account-status":null,
"logo":"client2.jpg"
},"relationships":{"adapters-resources":{"data":[]}}}],
"meta":
{
"current-page":1,
"next-page":2,
"prev-page":null,
"total-pages":16,
"total-count":31,
"filters":
{
"id":{"permitted-values":[]},
"name":{"permitted-values":[]},
"organization-type-id":{"permitted-values":
[{"value":39230,"data":{"name":"client"}},{"value":39231,"data": {"name":"CLient2"}},{"value":39232,"data":{"name":"Internal"}}, {"value":39233,"data":{"name":"Other"}},{"value":39234,"data":{"name":"Partner"}},{"value":39235,"data":{"name":"Prospect"}},{"value":39236,"data":{"name":"Vendor"}},{"value":53460,"data":{"name":"newname"}}]},"organization-status-id":{"permitted-values":[{"value":17054,"data":{"name":"Active"}},{"value":17055,"data":{"name":"Inactive"}}]},"created-at":{"permitted-values":[]},"updated-at":{"permitted-values":[]},"my-glue-account-id":{"permitted-values":[]}}},"links":{"self":"https://api.itglue.com/organizations?page%5Bnumber%5D=1\u0026page%5Bsize%5D=2\u0026sort=id","next":"https://api.itglue.com/organizations?page%5Bnumber%5D=2\u0026page%5Bsize%5D=2\u0026sort=id","last":"https://api.itglue.com/organizations?page%5Bnumber%5D=16\u0026page%5Bsize%5D=2\u0026sort=id"}}
So far I have tried creating classes for the data, but it seems to give me no information.
In order to process the data, I had to change all the properties names, because many contain a dash:
For example, Created-at is now Created_at
I used jsonutils.com to create the VB.Net classes.
I load the JSON into a string called Change_String.
If anyone can explain what I'm doing wrong, I would appreciate it
Dim changed_string as string = "JSON INPUT _ instead of -"
Dim obj As Attributes
obj = JsonConvert.DeserializeObject(Of Attributes)(changed_string)
msgbox(obj.name)
Classes:
Public Class Attributes
Public Property psa_integration As Object
Public Property name As String
Public Property alert As Object
Public Property description As Object
Public Property organization_type_id As Integer?
Public Property organization_type_name As String
Public Property organization_status_id As Integer?
Public Property organization_status_name As String
Public Property my_glue_account_id As Object
Public Property primary As Boolean
Public Property quick_notes As String
Public Property short_name As String
Public Property created_at As String
Public Property updated_at As String
Public Property my_glue_account_status As Object
Public Property logo As String
End Class
Public Class AdaptersResources
Public Property data As Object()
End Class
Public Class Relationships
Public Property adapters_resources As AdaptersResources
End Class
Public Class Datum
Public Property id As String
Public Property type As String
Public Property attributes As Attributes
Public Property relationships As Relationships
End Class
Public Class Id
Public Property permitted_values As Object()
End Class
Public Class Name
Public Property permitted_values As Object()
End Class
Public Class Data
Public Property name As String
End Class
Public Class PermittedValue
Public Property value As Integer
Public Property data As Data
End Class
Public Class OrganizationTypeId
Public Property permitted_values As PermittedValue()
End Class
Public Class OrganizationStatusId
Public Property permitted_values As PermittedValue()
End Class
Public Class CreatedAt
Public Property permitted_values As Object()
End Class
Public Class UpdatedAt
Public Property permitted_values As Object()
End Class
Public Class MyGlueAccountId
Public Property permitted_values As Object()
End Class
Public Class Filters
Public Property id As Id
Public Property name As Name
Public Property organization_type_id As OrganizationTypeId
Public Property organization_status_id As OrganizationStatusId
Public Property created_at As CreatedAt
Public Property updated_at As UpdatedAt
Public Property my_glue_account_id As MyGlueAccountId
End Class
Public Class Meta
Public Property current_page As Integer
Public Property next_page As Object
Public Property prev_page As Object
Public Property total_pages As Integer
Public Property total_count As Integer
Public Property filters As Filters
End Class
Public Class Links
End Class
Public Class Organizations
Public Property data As Datum()
Public Property meta As Meta
Public Property links As Links
End Class
I gave it a second look.
The classes generated by the online service are not exactly spectacular.
This is a modified class structure that should provide the correct results.
I compacted everything in a single class named JSON_Organizations, which contains all the classes needed by the JSON deserializer.
All the properties are renamed using JSON Attributes, so the bad names are taken care of.
Sample converter:
Imports Newtonsoft.Json
Dim JSONObject As String = "[The JSON Object]"
Dim Organizations As JSON_Organizations.RootObject = New JSON_Organizations.RootObject
Organizations = JsonConvert.DeserializeObject(Of JSON_Organizations.RootObject)(JSONObject)
The JSON_Organizations container class:
Imports Newtonsoft.Json
Public Class JSON_Organizations
Public Class RootObject
<JsonProperty("data")>
Public Property Data As Datum()
<JsonProperty("meta")>
Public Property Meta As Meta
<JsonProperty("links")>
Public Property Links As Links
End Class
Public Class Datum
<JsonProperty("id")>
Public Property Id As String
<JsonProperty("type")>
Public Property Type As String
<JsonProperty("attributes")>
Public Property Attributes As Attributes
<JsonProperty("relationships")>
Public Property Relationships As Relationships
End Class
Public Class Attributes
<JsonProperty("psa-integration")>
Public Property PsaIntegration As Object
<JsonProperty("name")>
Public Property Name As String
<JsonProperty("alert")>
Public Property Alert As Object
<JsonProperty("description")>
Public Property Description As Object
<JsonProperty("organization-type-id")>
Public Property OrganizationTypeId As Integer?
<JsonProperty("organization-type-name")>
Public Property OrganizationTypeName As String
<JsonProperty("organization-status-id")>
Public Property OrganizationStatusId As Integer?
<JsonProperty("organization-status-name")>
Public Property OrganizationStatusName As String
<JsonProperty("my-glue-account-id")>
Public Property MyGlueAccountId As Object
<JsonProperty("primary")>
Public Property Primary As Boolean
<JsonProperty("quick-notes")>
Public Property QuickNotes As Object
<JsonProperty("short-name")>
Public Property ShortName As String
<JsonProperty("created-at")>
Public Property CreatedAt As DateTimeOffset
<JsonProperty("updated-at")>
Public Property UpdatedAt As DateTimeOffset
<JsonProperty("my-glue-account-status")>
Public Property MyGlueAccountStatus As Object
<JsonProperty("logo")>
Public Property Logo As String
End Class
Public Class Relationships
<JsonProperty("adapters-resources")>
Public Property AdaptersResources As AdaptersResources
End Class
Public Class AdaptersResources
<JsonProperty("data")>
Public Property Data As List(Of Object)
End Class
Public Class Links
<JsonProperty("self")>
Public Property Self As String
<JsonProperty("next")>
Public Property NextLink As String
<JsonProperty("last")>
Public Property Last As String
End Class
Public Class Meta
<JsonProperty("current-page")>
Public Property CurrentPage As Long
<JsonProperty("next-page")>
Public Property NextPage As Long
<JsonProperty("prev-page")>
Public Property PrevPage As Object
<JsonProperty("total-pages")>
Public Property TotalPages As Long
<JsonProperty("total-count")>
Public Property TotalCount As Long
<JsonProperty("filters")>
Public Property Filters As Filters
End Class
Public Class Filters
<JsonProperty("id")>
Public Property Id As CreatedAt
<JsonProperty("name")>
Public Property Name As CreatedAt
<JsonProperty("organization-type-id")>
Public Property OrganizationTypeId As CreatedAt
<JsonProperty("organization-status-id")>
Public Property OrganizationStatusId As CreatedAt
<JsonProperty("created-at")>
Public Property CreatedAt As CreatedAt
<JsonProperty("updated-at")>
Public Property UpdatedAt As CreatedAt
<JsonProperty("my-glue-account-id")>
Public Property MyGlueAccountId As CreatedAt
End Class
Public Class CreatedAt
<JsonProperty("permitted-values")>
Public Property PermittedValues As List(Of PermittedValue)
End Class
Public Class PermittedValue
<JsonProperty("value")>
Public Property Value As Integer
<JsonProperty("data")>
Public Property Data As Data
End Class
Public Class Data
<JsonProperty("name")>
Public Property Name As String
End Class
End Class
I have this DataContract, which is an array of strings:
[System.Xml.Serialization.XmlArrayAttribute(Order = 19)]
[System.Xml.Serialization.XmlArrayItemAttribute("CardNumber", typeof(string), IsNullable = false)]
[DataMember]
public string[] Cards {get; set; }
As I read, it should be serialized like this:
<Cards>
<CardNumber>123123</CardNumber>
</Cards>
but I'm still getting:
<Cards>
<string>123123</string>
</Cards>
What's wrong with it?
You can use CollectionDataContract instead.
First, create a class:
[CollectionDataContract(ItemName="CardNumber")]
public class CardsList : List<string> { }
And then, replace this line:
[DataMember]
public string[] Cards {get; set; }
By this:
[DataMember(Name="Cards")]
public CardsList Cards {get; set; };
Hope it helps.
I used to EF Code First From Database to generate classes based on an existing database. I need to map the relationship between these 2 classes.I suspect I have to set a foreign key but don't what to set the foreign key too.
Partial Public Class be_Posts
<Key>
Public Property PostRowID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(255)>
Public Property Title As String
Public Property Description As String
Public Property PostContent As String
Public Property DateCreated As Date?
Public Property DateModified As Date?
<StringLength(50)>
Public Property Author As String
Public Property IsPublished As Boolean?
Public Property IsCommentEnabled As Boolean?
Public Property Raters As Integer?
Public Property Rating As Single?
<StringLength(255)>
Public Property Slug As String
Public Property IsDeleted As Boolean
End Class
Partial Public Class be_PostTag
<Key>
Public Property PostTagID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
Public Property PostRowID As Integer
<StringLength(50)>
Public Property Tag As String
End Class
Seems straight forward, but i may be missing something. haven't coded in VB in a while so forgive any typos.
You'll want to add a Foreign Key relationship on the PostRowID values on your two tables.
I believe it should look something like this when you're done.
Partial Public Class be_Posts
<Key>
Public Property PostRowID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(255)>
Public Property Title As String
Public Property Description As String
Public Property PostContent As String
Public Property DateCreated As Date?
Public Property DateModified As Date?
<StringLength(50)>
Public Property Author As String
Public Property IsPublished As Boolean?
Public Property IsCommentEnabled As Boolean?
Public Property Raters As Integer?
Public Property Rating As Single?
<StringLength(255)>
Public Property Slug As String
Public Property IsDeleted As Boolean
End Class
Partial Public Class be_PostTag
<Key>
Public Property PostTagID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
Public Property PostRowID As Integer
<StringLength(50)>
Public Property Tag As String
<ForeignKey("PostRowID")>
Public Property PostRow As be_Posts
End Class
Here is an article that references a simple example of defining this FK relationship with Code First, the examples are in C# but should translate fairly well.
I have a fully working MVC4 web site to which today I am trying to add a Web API though without success.
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace/>
<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Type 'System.Data.Entity.Infrastructure.DbQuery`1[[LeasingWeb.Models.Car, LeasingWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' with data contract name 'ArrayOfCar:http://schemas.datacontract.org/2004/07/LeasingWeb.Models' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
</ExceptionMessage>
<ExceptionType>
System.Runtime.Serialization.SerializationException
</ExceptionType>
<StackTrace>
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at WriteCarDBToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract ) at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph) at System.Net.Http.Formatting.XmlMediaTypeFormatter.<>c__DisplayClass7.<WriteToStreamAsync>b__6() at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)
</StackTrace>
</InnerException>
</Error>
My objects are these:
public class Image
{
public int ID { get; set; }
[Required(ErrorMessage="Please select a car")]
[ForeignKey("Car")]
public int CarID { get; set; }
[DisplayName("Picture")]
[Required]
[FileExtensions(ErrorMessage = "Please specify a valid image file (.jpg, .jpeg, .gif or .png)", Extensions = ("jpg,png,jpeg"))]
public string Name { get; set; }
public virtual Car Car { get; set; }
}
public class Car
{
public int ID { get; set; }
[Required]
[DisplayName("Car Model")]
public string Name { get; set; }
[Required]
public string Company { get; set; }
[Required]
[DisplayName("Car Type")]
[ForeignKey("CarType")]
public int CarTypeID { get; set; }
[Required]
[Range(1,5)]
[DisplayName("Number Of Doors")]
public float NumDoors { get; set; }
[Required]
[Range(0, Int32.MaxValue)]
public float Acceleration { get; set; }
public virtual CarType CarType { get; set; }
}
public class CarType
{
[Key]
public int ID { get; set; }
[Required]
[DataType(DataType.Text)]
public string Type { get; set; }
}
And an object that holds them both:
public class CarDB
{
public IQueryable<Car> Cars { get; set; }
public IEnumerable<Image> Images { get; set; }
}
The API Controller:
public CarDB Get(int ID = -1)
{
CarDB car = new CarDB();
if (ID == -1)
{
car = new CarDB { Cars = db.Cars.Include(c => c.CarType), Images = db.Images };
}
else
{
car = new CarDB { Cars = db.Cars.Where(c => c.ID == ID).Include(c => c.CarType), Images = db.Images.Where(c => c.CarID == ID) };
}
return car;
}
Thanks to anyone that can help.
The issue here is the Cars member on the CarDB object. The DataContractSerializer special cases collection interfaces like IEnumerable and IList, but it doesn't special case derived interfaces like IQueryable. For these interfaces, they're treated as if the type were object and any implementations must be declared as known types.
You can try fixing this by changing the IQueryable<Car> member to IEnumerable<Car>.
I had this problem with legacy code using 30 tables with about 40 Foreign Keys with Lazy Loading. I found it easier, rather than adding more annotations to all the database classes, to just create a ViewModel with the fields that I wanted to be returned.
If the data being returned is complex, then I suggest using automapper.
Can't I use ref in WCF to return data ?
This is my WCF file.
public myDataset SearchInfo(string accountName, string accountId, ref
int totalRecords)
Although totalRecords is a non-zero number, I always get 0.
I have to get both myDataset and totalRecords.
How should I try?
I am new to WCF.
Thanks in advance.
UPDATE :
It works well. My bad !!!
If you're trying to return multiple values, it's probably better to add a data contract with a data member for each value (dataset and total records in your case).
[DataContract]
public class SearchInfoResult
{
[DataMember]
public myDataSet DataSet {get; set;}
[DataMember]
public int TotalRecords {get; set;}
}