public override string ToString() { string className; CimProperty item = this.CimInstanceProperties["Caption"]; string value = null; if (item != null) { value = item.Value as string; } string str = ", "; CimKeyedCollection <CimProperty> cimInstanceProperties = this.CimInstanceProperties; string str1 = string.Join <CimProperty>(str, cimInstanceProperties.Where <CimProperty>((CimProperty p) => CimFlags.Key == (p.Flags & CimFlags.Key))); if (!string.IsNullOrEmpty(str1) || !string.IsNullOrEmpty(value)) { if (!string.IsNullOrEmpty(value)) { if (!string.IsNullOrEmpty(str1)) { object[] objArray = new object[3]; objArray[0] = this.CimSystemProperties.ClassName; objArray[1] = str1; objArray[2] = value; className = string.Format(CultureInfo.InvariantCulture, System.Management.Automation.Strings.CimInstanceToStringFullData, objArray); } else { object[] className1 = new object[2]; className1[0] = this.CimSystemProperties.ClassName; className1[1] = value; className = string.Format(CultureInfo.InvariantCulture, System.Management.Automation.Strings.CimInstanceToStringNoKeys, className1); } } else { object[] objArray1 = new object[2]; objArray1[0] = this.CimSystemProperties.ClassName; objArray1[1] = str1; className = string.Format(CultureInfo.InvariantCulture, System.Management.Automation.Strings.CimInstanceToStringNoCaption, objArray1); } } else { className = this.CimSystemProperties.ClassName; } return(className); }
public static DnsRecord asDnsRecord(this PSObject obj, string zoneName, bool get) { // Here's what comes from Server 2012 in the TypeNames: // "Microsoft.Management.Infrastructure.CimInstance#root/Microsoft/Windows/DNS/DnsServerResourceRecord" // "Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/DNS/DnsDomain" // "Microsoft.Management.Infrastructure.CimInstance#DnsServerResourceRecord" // "Microsoft.Management.Infrastructure.CimInstance#DnsDomain" // "Microsoft.Management.Infrastructure.CimInstance" // "System.Object" string if (!obj.TypeNames.Contains("Microsoft.Management.Infrastructure.CimInstance#DnsServerResourceRecord")) { Log.WriteWarning("asDnsRecord: wrong object type {0}", obj.TypeNames.FirstOrDefault()); return(null); } string strRT = (string)obj.Properties["RecordType"].Value; DnsRecordType tp; if (!RecordTypes.recordFromString.TryGetValue(strRT, out tp)) { return(null); } /*// Debug code below: * obj.dumpProperties(); * CimInstance rd = (CimInstance)obj.Properties[ "RecordData" ].Value; * rd.dumpProperties(); //*/ CimKeyedCollection <CimProperty> data = ((CimInstance)obj.Properties["RecordData"].Value).CimInstanceProperties; string host = CorrectHost(zoneName, (string)obj.Properties["HostName"].Value); switch (tp) { // The compiler should create a Dictionary<> from dis switch case DnsRecordType.A: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = data["IPv4Address"].Value as string, }); } case DnsRecordType.AAAA: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = data["IPv6Address"].Value as string, }); } case DnsRecordType.CNAME: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = RemoveTrailingDot(data["HostNameAlias"].Value as string), }); } case DnsRecordType.MX: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = RemoveTrailingDot(data["MailExchange"].Value as string), MxPriority = (UInt16)data["Preference"].Value, }); } case DnsRecordType.NS: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = RemoveTrailingDot(data["NameServer"].Value as string), }); } case DnsRecordType.TXT: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = data["DescriptiveText"].Value as string, }); } case DnsRecordType.SOA: { string PrimaryServer = data["PrimaryServer"].Value as string; string ResponsiblePerson = data["ResponsiblePerson"].Value as string; UInt32?sn = (UInt32?)data["SerialNumber"].Value; return(new DnsSOARecord() { RecordType = tp, RecordName = host, PrimaryNsServer = PrimaryServer, PrimaryPerson = ResponsiblePerson, SerialNumber = (sn.HasValue) ? sn.Value.ToString() : null, }); } case DnsRecordType.SRV: { return(new DnsRecord() { RecordType = tp, RecordName = host, RecordData = RemoveTrailingDot(data["DomainName"].Value as string), SrvPriority = (UInt16)data["Priority"].Value, SrvWeight = (UInt16)data["Weight"].Value, SrvPort = (UInt16)data["Port"].Value, }); } case DnsRecordType.CAA: case DnsRecordType.UNKNOWN: { DnsRecordType type; if (get) { type = DnsRecordType.CAA; } else { type = DnsRecordType.UNKNOWN; } return(new DnsRecord() { RecordType = type, RecordName = host, RecordData = data["Data"].Value as string, }); } } return(null); }