using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Management.Automation; using System.Management.Automation.Provider; using Intel.Management.Mei; using Intel.Management.Wsman; namespace Intel.Management.PSModule.Amt { class AmtDriveInfo : DriveInfo { string _version; public AmtDriveInfo(PSDriveInfo driveInfo,AmtDriveParameters driveParams, AmtDriveProvider provider) : base(driveInfo) { WsmanConnection conn = ConnectionManager.ActiveSession; if (conn == null) { //Sending null to the connection and after than get the certificate by the certificate name and then set it in teh connection conn = Intel.Management.PSModule.Amt.CredentialManager.GetConnection(driveParams.ComputerName,Credential, driveParams.TLS, driveParams.AcceptSelfSignedCert, driveParams.AsMaster, null, null); if(!string.IsNullOrEmpty(driveParams.CertificateName))//Set client certificate by certifcate name. conn.Options.SetClientCertificateByCertificateName(driveParams.CertificateName); } IManagedInstance idnty= conn.Identify(); if (idnty.GetProperty("ProductVersion").IsNull) _version = "Unknown"; else _version = idnty.GetProperty("ProductVersion").ToString(); _root = new AmtRootService(driveInfo.Name, conn); DriveItem item = GetItemFromPath(driveInfo.Root); if (item == null) throw new PSArgumentException(Intel.Management.PSModule.Properties.Resources.INVALID_ROOT_PATH); } public string Version { get { return _version; } } public static object GetBaseObject(object input) { object result = input; if (input is PSObject) { result = ((PSObject)input).BaseObject; } return result; } public static Guid FormatGuid(string guidString) { return new Guid(ConvertGUIDStringToByteArray(guidString)); } public static DateTime FormatDate(IWsmanItem dateItem) { string dateValue = "2010-03-25T00:00:00Z"; if (dateItem.IsObject) { dateValue = dateItem.Object.Text; } else if (dateItem.IsString) { dateValue = dateItem.ToString(); } dateValue = dateValue.Replace("-", string.Empty).Replace("T", string.Empty).Replace(":", string.Empty); System.IO.StringReader reader = new System.IO.StringReader(dateValue); char[] buff = new char[4]; //read year reader.Read(buff, 0, buff.Length); int year = int.Parse(new string(buff)); buff = new char[2]; //read month reader.Read(buff, 0, buff.Length); int month = int.Parse(new string(buff)); //read day reader.Read(buff, 0, buff.Length); int day = int.Parse(new string(buff)); //read hour reader.Read(buff, 0, buff.Length); int hour = int.Parse(new string(buff)); //read minutes reader.Read(buff, 0, buff.Length); int minute = int.Parse(new string(buff)); //read seconds reader.Read(buff, 0, buff.Length); int second = int.Parse(new string(buff)); return new DateTime(year, month, day, hour, minute, second); } /// /// Prior to Release 5.1 platformGUID return half of the numbers reversed. /// this function return the GUID in correct format /// Converts string with 32 contiguous digits GUID format into a 16 length byte array /// /// String with 32 contiguous digits GUID format /// A 16 length byte array representing the given string public static byte[] ConvertGUIDStringToByteArray(string guidString) { string newGuid = guidString.Replace("-", ""); byte[] guidByteArray = new byte[newGuid.Length / 2]; for (int i = 0; i < guidByteArray.Length; i++) { Byte.TryParse( newGuid.Substring((i * 2), 2), NumberStyles.AllowHexSpecifier, null, out guidByteArray[i]); } return guidByteArray; } } }