将XmlElement对象转换为PSCustomObject

时间:2018-12-17 15:19:19

标签: powershell

我正在使用一个工具,该工具将从客户环境中收集数据,然后将这些收集的数据收集到PSCustomObjects中,然后使用Export-Clixml将对象转储为XML文件。

问题出在某些对象中,Export-Clixml将转储数据,并且在使用Import-Clixml时,这些对象将具有#text值,而不是实际值。

例如:

我正在使用PowerNsx从NSX Manager获取证书信息,然后将其添加到PSCustomObject

$NsxManagerCertificate = Get-NsxManagerCertificate
$TestObject = [PSCustomObject] {
     NsxManagerCertificate = $NsxManagerCertificate
}
Export-Clixml -InputObject $TestObject -Path E:\TestDump.xml

如果我检查了变量输出,您将获得真实数据:

C:\Users\Administrator> $NsxManagerCertificate


subjectCn            : CGSR-NSX.nfv.gss
issuerCn             : CGSR-NSX.nfv.gss
version              : 3
serialNumber         : 49044a14
signatureAlgo        : SHA256WITHRSA
signature            : 0b 5d c7 cb ab 58 0d 9a ff 03 e9 0a e5 91 61 64 16 22 c7 c2 21 28 50 f2 ad 02 21 e9 48 4e f6 72 d3 91 f1 19 3e 3e 25 3a fd 28 ab 81 e2 6c d1 35 51 dc 13 c4 22 f3 cb 53 db 6d c5 0c fe ff 6b 0b cd fc 17 d2 d5 bd d0 b8 13 e2 
                       53 e7 2b 1e 8a 84 ee 54 f4 dc b3 7d 1a 70 4b 71 12 42 6b 2c b5 1c 65 85 94 9d f5 00 7c 28 0f 6f 5b 15 b4 fe 67 e2 fa 4c 10 6c 31 a4 4a df 48 f2 c1 a1 66 e5 d2 0a 80 3e f4 02 c3 75 95 4c e0 d8 5b 90 74 9a 85 56 b4 f2 9e 2b 
                       c3 c7 f4 71 fa 43 b2 c2 1e 65 a6 0b 8b eb fc 39 77 bd 04 39 b4 99 64 81 d5 0d 81 88 a9 33 63 72 9f a4 b3 d7 c5 33 97 14 d5 be 3f 8e a9 de fd 0f 1c 3d 63 fd 0c ff e2 12 03 59 53 f1 a5 96 cb a6 03 23 4b ef 71 38 0e 96 fb 85 
                       4d 4c a8 8b 48 50 a6 e0 ff c6 f9 25 b5 8f d4 d2 0c 82 4c ff 9f e3 ef 9a e9 44 57 c5 3c 06 b8 b5 f9 2e
notBefore            : 1527008785000
notAfter             : 1842368785000
issuer               : CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US
subject              : CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US
publicKeyAlgo        : RSA
publicKeyLength      : 2048
rsaPublicKeyModulus  : 00 a5 7d 07 71 38 f5 39 fd 64 61 15 4a a6 ec 2a 51 d6 1b 49 08 6b 37 74 ae 8e 5e 21 db a5 48 73 e1 45 5b 02 5c 60 0c 9c 49 77 45 a4 43 f9 2b 05 a8 02 3b cb e7 17 89 18 79 38 5b a0 1d 77 3b c3 90 3d 39 8c 5e 25 90 80 d0 a0 
                       df f1 32 52 4c 46 8b 86 1f 67 5b 1a ee 56 3e d0 bf cc 45 5d 7a b8 f7 65 d0 4b 92 94 9f 1f 22 0d ae a6 d2 cb e6 00 92 f6 41 1b 52 4b 1d ba dc 24 04 e3 f5 2c c5 26 f0 d0 2c 02 b4 6b c2 f0 12 e7 20 c5 fe 4f d2 8f 12 8d 2d 2c 
                       3e 8a cb 63 f7 d9 37 0c fd 43 53 e3 14 cd 51 b5 68 0d e7 59 ad a3 8e 28 53 72 d1 97 65 f2 bf fb 6c 78 63 d8 57 fe 8f 6b 89 53 ac a2 0c 0d 83 bd be d5 14 7b 4c cf 15 22 60 17 1e 1f f7 28 7f 64 ac 28 a7 26 d3 bc c7 5a c0 42 
                       e6 34 00 57 62 99 6a 0c 4c 54 a4 6e b7 b8 73 43 1d 65 f7 b8 cd fc 99 75 8c 49 f1 0f 72 70 1b 4c 47 0e 7b
rsaPublicKeyExponent : 10001
sha1Hash             : 05:69:31:14:c9:41:0d:30:d6:52:e6:83:e8:6a:56:ad:1e:84:a5:37
md5Hash              : 1c:cb:26:9b:2b:b5:09:6f:b1:cd:91:00:c3:f7:34:9f
isCa                 : false
isValid              : true


C:\Users\Administrator> $TestObject.NsxManagerCertificate


subjectCn            : CGSR-NSX.nfv.gss
issuerCn             : CGSR-NSX.nfv.gss
version              : 3
serialNumber         : 49044a14
signatureAlgo        : SHA256WITHRSA
signature            : 0b 5d c7 cb ab 58 0d 9a ff 03 e9 0a e5 91 61 64 16 22 c7 c2 21 28 50 f2 ad 02 21 e9 48 4e f6 72 d3 91 f1 19 3e 3e 25 3a fd 28 ab 81 e2 6c d1 35 51 dc 13 c4 22 f3 cb 53 db 6d c5 0c fe ff 6b 0b cd fc 17 d2 d5 bd d0 b8 13 e2 
                       53 e7 2b 1e 8a 84 ee 54 f4 dc b3 7d 1a 70 4b 71 12 42 6b 2c b5 1c 65 85 94 9d f5 00 7c 28 0f 6f 5b 15 b4 fe 67 e2 fa 4c 10 6c 31 a4 4a df 48 f2 c1 a1 66 e5 d2 0a 80 3e f4 02 c3 75 95 4c e0 d8 5b 90 74 9a 85 56 b4 f2 9e 2b 
                       c3 c7 f4 71 fa 43 b2 c2 1e 65 a6 0b 8b eb fc 39 77 bd 04 39 b4 99 64 81 d5 0d 81 88 a9 33 63 72 9f a4 b3 d7 c5 33 97 14 d5 be 3f 8e a9 de fd 0f 1c 3d 63 fd 0c ff e2 12 03 59 53 f1 a5 96 cb a6 03 23 4b ef 71 38 0e 96 fb 85 
                       4d 4c a8 8b 48 50 a6 e0 ff c6 f9 25 b5 8f d4 d2 0c 82 4c ff 9f e3 ef 9a e9 44 57 c5 3c 06 b8 b5 f9 2e
notBefore            : 1527008785000
notAfter             : 1842368785000
issuer               : CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US
subject              : CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US
publicKeyAlgo        : RSA
publicKeyLength      : 2048
rsaPublicKeyModulus  : 00 a5 7d 07 71 38 f5 39 fd 64 61 15 4a a6 ec 2a 51 d6 1b 49 08 6b 37 74 ae 8e 5e 21 db a5 48 73 e1 45 5b 02 5c 60 0c 9c 49 77 45 a4 43 f9 2b 05 a8 02 3b cb e7 17 89 18 79 38 5b a0 1d 77 3b c3 90 3d 39 8c 5e 25 90 80 d0 a0 
                       df f1 32 52 4c 46 8b 86 1f 67 5b 1a ee 56 3e d0 bf cc 45 5d 7a b8 f7 65 d0 4b 92 94 9f 1f 22 0d ae a6 d2 cb e6 00 92 f6 41 1b 52 4b 1d ba dc 24 04 e3 f5 2c c5 26 f0 d0 2c 02 b4 6b c2 f0 12 e7 20 c5 fe 4f d2 8f 12 8d 2d 2c 
                       3e 8a cb 63 f7 d9 37 0c fd 43 53 e3 14 cd 51 b5 68 0d e7 59 ad a3 8e 28 53 72 d1 97 65 f2 bf fb 6c 78 63 d8 57 fe 8f 6b 89 53 ac a2 0c 0d 83 bd be d5 14 7b 4c cf 15 22 60 17 1e 1f f7 28 7f 64 ac 28 a7 26 d3 bc c7 5a c0 42 
                       e6 34 00 57 62 99 6a 0c 4c 54 a4 6e b7 b8 73 43 1d 65 f7 b8 cd fc 99 75 8c 49 f1 0f 72 70 1b 4c 47 0e 7b
rsaPublicKeyExponent : 10001
sha1Hash             : 05:69:31:14:c9:41:0d:30:d6:52:e6:83:e8:6a:56:ad:1e:84:a5:37
md5Hash              : 1c:cb:26:9b:2b:b5:09:6f:b1:cd:91:00:c3:f7:34:9f
isCa                 : false
isValid              : true

但是,如果您检查xml文件,则会得到#text而不是读取的数据

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Management.Automation.PSCustomObject</T>
      <T>System.Object</T>
    </TN>
    <MS>
      <Obj N="NsxManagerCertificate" RefId="1">
        <TN RefId="1">
          <T>System.Xml.XmlElement</T>
          <T>System.Xml.XmlLinkedNode</T>
          <T>System.Xml.XmlNode</T>
          <T>System.Object</T>
        </TN>
        <IE>
          <Obj RefId="2">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="3">
                <TN RefId="2">
                  <T>System.Xml.XmlText</T>
                  <T>System.Xml.XmlCharacterData</T>
                  <T>System.Xml.XmlLinkedNode</T>
                  <T>System.Xml.XmlNode</T>
                  <T>System.Object</T>
                </TN>
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">CGSR-NSX.nfv.gss</S>
            </Props>
          </Obj>
          <Obj RefId="4">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="5">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">CGSR-NSX.nfv.gss</S>
            </Props>
          </Obj>
          <Obj RefId="6">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="7">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">3</S>
            </Props>
          </Obj>
          <Obj RefId="8">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="9">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">49044a14</S>
            </Props>
          </Obj>
          <Obj RefId="10">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="11">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">SHA256WITHRSA</S>
            </Props>
          </Obj>
          <Obj RefId="12">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="13">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">0b 5d c7 cb ab 58 0d 9a ff 03 e9 0a e5 91 61 64 16 22 c7 c2 21 28 50 f2 ad 02 21 e9 48 4e f6 72 d3 91 f1 19 3e 3e 25 3a fd 28 ab 81 e2 6c d1 35 51 dc 13 c4 22 f3 cb 53 db 6d c5 0c fe ff 6b 0b cd fc 17 d2 d5 bd d0 b8 13 e2 53 e7 2b 1e 8a 84 ee 54 f4 dc b3 7d 1a 70 4b 71 12 42 6b 2c b5 1c 65 85 94 9d f5 00 7c 28 0f 6f 5b 15 b4 fe 67 e2 fa 4c 10 6c 31 a4 4a df 48 f2 c1 a1 66 e5 d2 0a 80 3e f4 02 c3 75 95 4c e0 d8 5b 90 74 9a 85 56 b4 f2 9e 2b c3 c7 f4 71 fa 43 b2 c2 1e 65 a6 0b 8b eb fc 39 77 bd 04 39 b4 99 64 81 d5 0d 81 88 a9 33 63 72 9f a4 b3 d7 c5 33 97 14 d5 be 3f 8e a9 de fd 0f 1c 3d 63 fd 0c ff e2 12 03 59 53 f1 a5 96 cb a6 03 23 4b ef 71 38 0e 96 fb 85 4d 4c a8 8b 48 50 a6 e0 ff c6 f9 25 b5 8f d4 d2 0c 82 4c ff 9f e3 ef 9a e9 44 57 c5 3c 06 b8 b5 f9 2e</S>
            </Props>
          </Obj>
          <Obj RefId="14">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="15">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">1527008785000</S>
            </Props>
          </Obj>
          <Obj RefId="16">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="17">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">1842368785000</S>
            </Props>
          </Obj>
          <Obj RefId="18">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="19">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US</S>
            </Props>
          </Obj>
          <Obj RefId="20">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="21">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US</S>
            </Props>
          </Obj>
          <Obj RefId="22">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="23">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">RSA</S>
            </Props>
          </Obj>
          <Obj RefId="24">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="25">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">2048</S>
            </Props>
          </Obj>
          <Obj RefId="26">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="27">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">00 a5 7d 07 71 38 f5 39 fd 64 61 15 4a a6 ec 2a 51 d6 1b 49 08 6b 37 74 ae 8e 5e 21 db a5 48 73 e1 45 5b 02 5c 60 0c 9c 49 77 45 a4 43 f9 2b 05 a8 02 3b cb e7 17 89 18 79 38 5b a0 1d 77 3b c3 90 3d 39 8c 5e 25 90 80 d0 a0 df f1 32 52 4c 46 8b 86 1f 67 5b 1a ee 56 3e d0 bf cc 45 5d 7a b8 f7 65 d0 4b 92 94 9f 1f 22 0d ae a6 d2 cb e6 00 92 f6 41 1b 52 4b 1d ba dc 24 04 e3 f5 2c c5 26 f0 d0 2c 02 b4 6b c2 f0 12 e7 20 c5 fe 4f d2 8f 12 8d 2d 2c 3e 8a cb 63 f7 d9 37 0c fd 43 53 e3 14 cd 51 b5 68 0d e7 59 ad a3 8e 28 53 72 d1 97 65 f2 bf fb 6c 78 63 d8 57 fe 8f 6b 89 53 ac a2 0c 0d 83 bd be d5 14 7b 4c cf 15 22 60 17 1e 1f f7 28 7f 64 ac 28 a7 26 d3 bc c7 5a c0 42 e6 34 00 57 62 99 6a 0c 4c 54 a4 6e b7 b8 73 43 1d 65 f7 b8 cd fc 99 75 8c 49 f1 0f 72 70 1b 4c 47 0e 7b</S>
            </Props>
          </Obj>
          <Obj RefId="28">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="29">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">10001</S>
            </Props>
          </Obj>
          <Obj RefId="30">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="31">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">05:69:31:14:c9:41:0d:30:d6:52:e6:83:e8:6a:56:ad:1e:84:a5:37</S>
            </Props>
          </Obj>
          <Obj RefId="32">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="33">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">1c:cb:26:9b:2b:b5:09:6f:b1:cd:91:00:c3:f7:34:9f</S>
            </Props>
          </Obj>
          <Obj RefId="34">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="35">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">false</S>
            </Props>
          </Obj>
          <Obj RefId="36">
            <TNRef RefId="1" />
            <IE>
              <Obj RefId="37">
                <TNRef RefId="2" />
                <ToString>#text</ToString>
              </Obj>
            </IE>
            <Props>
              <S N="#text">true</S>
            </Props>
          </Obj>
        </IE>
        <Props>
          <S N="subjectCn">CGSR-NSX.nfv.gss</S>
          <S N="issuerCn">CGSR-NSX.nfv.gss</S>
          <S N="version">3</S>
          <S N="serialNumber">49044a14</S>
          <S N="signatureAlgo">SHA256WITHRSA</S>
          <S N="signature">0b 5d c7 cb ab 58 0d 9a ff 03 e9 0a e5 91 61 64 16 22 c7 c2 21 28 50 f2 ad 02 21 e9 48 4e f6 72 d3 91 f1 19 3e 3e 25 3a fd 28 ab 81 e2 6c d1 35 51 dc 13 c4 22 f3 cb 53 db 6d c5 0c fe ff 6b 0b cd fc 17 d2 d5 bd d0 b8 13 e2 53 e7 2b 1e 8a 84 ee 54 f4 dc b3 7d 1a 70 4b 71 12 42 6b 2c b5 1c 65 85 94 9d f5 00 7c 28 0f 6f 5b 15 b4 fe 67 e2 fa 4c 10 6c 31 a4 4a df 48 f2 c1 a1 66 e5 d2 0a 80 3e f4 02 c3 75 95 4c e0 d8 5b 90 74 9a 85 56 b4 f2 9e 2b c3 c7 f4 71 fa 43 b2 c2 1e 65 a6 0b 8b eb fc 39 77 bd 04 39 b4 99 64 81 d5 0d 81 88 a9 33 63 72 9f a4 b3 d7 c5 33 97 14 d5 be 3f 8e a9 de fd 0f 1c 3d 63 fd 0c ff e2 12 03 59 53 f1 a5 96 cb a6 03 23 4b ef 71 38 0e 96 fb 85 4d 4c a8 8b 48 50 a6 e0 ff c6 f9 25 b5 8f d4 d2 0c 82 4c ff 9f e3 ef 9a e9 44 57 c5 3c 06 b8 b5 f9 2e</S>
          <S N="notBefore">1527008785000</S>
          <S N="notAfter">1842368785000</S>
          <S N="issuer">CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US</S>
          <S N="subject">CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US</S>
          <S N="publicKeyAlgo">RSA</S>
          <S N="publicKeyLength">2048</S>
          <S N="rsaPublicKeyModulus">00 a5 7d 07 71 38 f5 39 fd 64 61 15 4a a6 ec 2a 51 d6 1b 49 08 6b 37 74 ae 8e 5e 21 db a5 48 73 e1 45 5b 02 5c 60 0c 9c 49 77 45 a4 43 f9 2b 05 a8 02 3b cb e7 17 89 18 79 38 5b a0 1d 77 3b c3 90 3d 39 8c 5e 25 90 80 d0 a0 df f1 32 52 4c 46 8b 86 1f 67 5b 1a ee 56 3e d0 bf cc 45 5d 7a b8 f7 65 d0 4b 92 94 9f 1f 22 0d ae a6 d2 cb e6 00 92 f6 41 1b 52 4b 1d ba dc 24 04 e3 f5 2c c5 26 f0 d0 2c 02 b4 6b c2 f0 12 e7 20 c5 fe 4f d2 8f 12 8d 2d 2c 3e 8a cb 63 f7 d9 37 0c fd 43 53 e3 14 cd 51 b5 68 0d e7 59 ad a3 8e 28 53 72 d1 97 65 f2 bf fb 6c 78 63 d8 57 fe 8f 6b 89 53 ac a2 0c 0d 83 bd be d5 14 7b 4c cf 15 22 60 17 1e 1f f7 28 7f 64 ac 28 a7 26 d3 bc c7 5a c0 42 e6 34 00 57 62 99 6a 0c 4c 54 a4 6e b7 b8 73 43 1d 65 f7 b8 cd fc 99 75 8c 49 f1 0f 72 70 1b 4c 47 0e 7b</S>
          <S N="rsaPublicKeyExponent">10001</S>
          <S N="sha1Hash">05:69:31:14:c9:41:0d:30:d6:52:e6:83:e8:6a:56:ad:1e:84:a5:37</S>
          <S N="md5Hash">1c:cb:26:9b:2b:b5:09:6f:b1:cd:91:00:c3:f7:34:9f</S>
          <S N="isCa">false</S>
          <S N="isValid">true</S>
        </Props>
      </Obj>
    </MS>
  </Obj>
</Objs>

然后使用Import-Clixml获取数据,您会发现它们的值是#text(我认为这是在每个对象中仅读取#text值)

C:\Users\Administrator> $TestImport = Import-Clixml -Path E:\TestDump.xml

 C:\Users\Administrator> $TestImport

NsxManagerCertificate          
---------------------          
{#text, #text, #text, #text...}



 C:\Users\Administrator> $TestImport.NsxManagerCertificate
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text
#text

经过大量检查,我能够解决此问题,并且我想能够在这里找到主要问题。 $ NsxManagerCertificate对象的类型为XmlElement

C:\ Users \ Administrator> $ NsxManagerCertificate.GetType()

IsPublic IsSerial名称BaseType
-------- -------- ---- --------
正确False XmlElement System.Xml.XmlLinkedNode

如果我按如下所示在新的PSCustomObject中重新创建它,然后将其导出,然后将其导入,则会像吊饰一样扭曲。

$NsxsubjectCn = $NsxManagerCertificateGet.subjectCn
$NsxissuerCn = $NsxManagerCertificateGet.issuerCn
$Nsxversion = $NsxManagerCertificateGet.version
$NsxserialNumber = $NsxManagerCertificateGet.serialNumber
$NsxsignatureAlgo = $NsxManagerCertificateGet.signatureAlgo
$Nsxsignature = $NsxManagerCertificateGet.signature
$NsxnotBefore = $NsxManagerCertificateGet.notBefore
$NsxnotAfter = $NsxManagerCertificateGet.notAfter
$Nsxissuer = $NsxManagerCertificateGet.issuer
$Nsxsubject = $NsxManagerCertificateGet.subject
$NsxpublicKeyAlgo = $NsxManagerCertificateGet.publicKeyAlgo
$NsxpublicKeyLength = $NsxManagerCertificateGet.publicKeyLength
$NsxrsaPublicKeyModulus = $NsxManagerCertificateGet.rsaPublicKeyModulus
$NsxrsaPublicKeyExponent = $NsxManagerCertificateGet.rsaPublicKeyExponent
$Nsxsha1Hash = $NsxManagerCertificateGet.sha1Hash
$Nsxmd5Hash = $NsxManagerCertificateGet.md5Hash
$NsxisCa = $NsxManagerCertificateGet.isCa
$NsxisValid = $NsxManagerCertificateGet.isValid

$NsxManagerCertificate = [PSCustomObject] @{
    subjectCn = $NsxsubjectCn
    issuerCn = $NsxissuerCn
    version = $Nsxversion
    serialNumber = $NsxserialNumber
    signatureAlgo = $NsxsignatureAlgo
    signature = $Nsxsignature
    notBefore = $NsxnotBefore
    notAfter = $NsxnotAfter
    issuer = $Nsxissuer
    subject = $Nsxsubject
    publicKeyAlgo = $NsxpublicKeyAlgo
    publicKeyLength = $NsxpublicKeyLength
    rsaPublicKeyModulus = $NsxrsaPublicKeyModulus
    rsaPublicKeyExponent = $NsxrsaPublicKeyExponent
    sha1Hash = $Nsxsha1Hash
    md5Hash = $Nsxmd5Hash
    isCa = $NsxisCa
    isValid = $NsxisValid
}

C:\Users\Administrator> Export-Clixml -InputObject $NsxManagerCertificate -Path E:\TestExport.xml

 C:\Users\Administrator> $CheckImportTest = Import-Clixml -Path E:\TestExport.xml

 C:\Users\Administrator> $CheckImportTest


subjectCn            : CGSR-NSX.nfv.gss
issuerCn             : CGSR-NSX.nfv.gss
version              : 3
serialNumber         : 49044a14
signatureAlgo        : SHA256WITHRSA
signature            : 0b 5d c7 cb ab 58 0d 9a ff 03 e9 0a e5 91 61 64 16 22 c7 c2 21 28 50 f2 ad 02 21 e9 48 4e f6 72 d3 91 f1 19 3e 3e 25 3a fd 28 ab 81 e2 6c d1 35 51 dc 13 c4 22 f3 cb 53 db 6d c5 0c fe ff 6b 0b cd fc 17 d2 d5 bd d0 b8 13 e2 
                       53 e7 2b 1e 8a 84 ee 54 f4 dc b3 7d 1a 70 4b 71 12 42 6b 2c b5 1c 65 85 94 9d f5 00 7c 28 0f 6f 5b 15 b4 fe 67 e2 fa 4c 10 6c 31 a4 4a df 48 f2 c1 a1 66 e5 d2 0a 80 3e f4 02 c3 75 95 4c e0 d8 5b 90 74 9a 85 56 b4 f2 9e 2b 
                       c3 c7 f4 71 fa 43 b2 c2 1e 65 a6 0b 8b eb fc 39 77 bd 04 39 b4 99 64 81 d5 0d 81 88 a9 33 63 72 9f a4 b3 d7 c5 33 97 14 d5 be 3f 8e a9 de fd 0f 1c 3d 63 fd 0c ff e2 12 03 59 53 f1 a5 96 cb a6 03 23 4b ef 71 38 0e 96 fb 85 
                       4d 4c a8 8b 48 50 a6 e0 ff c6 f9 25 b5 8f d4 d2 0c 82 4c ff 9f e3 ef 9a e9 44 57 c5 3c 06 b8 b5 f9 2e
notBefore            : 1527008785000
notAfter             : 1842368785000
issuer               : CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US
subject              : CN=CGSR-NSX.nfv.gss,OU=NSX,O=VMware Inc.,L=Palo Alto,ST=CA,C=US
publicKeyAlgo        : RSA
publicKeyLength      : 2048
rsaPublicKeyModulus  : 00 a5 7d 07 71 38 f5 39 fd 64 61 15 4a a6 ec 2a 51 d6 1b 49 08 6b 37 74 ae 8e 5e 21 db a5 48 73 e1 45 5b 02 5c 60 0c 9c 49 77 45 a4 43 f9 2b 05 a8 02 3b cb e7 17 89 18 79 38 5b a0 1d 77 3b c3 90 3d 39 8c 5e 25 90 80 d0 a0 
                       df f1 32 52 4c 46 8b 86 1f 67 5b 1a ee 56 3e d0 bf cc 45 5d 7a b8 f7 65 d0 4b 92 94 9f 1f 22 0d ae a6 d2 cb e6 00 92 f6 41 1b 52 4b 1d ba dc 24 04 e3 f5 2c c5 26 f0 d0 2c 02 b4 6b c2 f0 12 e7 20 c5 fe 4f d2 8f 12 8d 2d 2c 
                       3e 8a cb 63 f7 d9 37 0c fd 43 53 e3 14 cd 51 b5 68 0d e7 59 ad a3 8e 28 53 72 d1 97 65 f2 bf fb 6c 78 63 d8 57 fe 8f 6b 89 53 ac a2 0c 0d 83 bd be d5 14 7b 4c cf 15 22 60 17 1e 1f f7 28 7f 64 ac 28 a7 26 d3 bc c7 5a c0 42 
                       e6 34 00 57 62 99 6a 0c 4c 54 a4 6e b7 b8 73 43 1d 65 f7 b8 cd fc 99 75 8c 49 f1 0f 72 70 1b 4c 47 0e 7b
rsaPublicKeyExponent : 10001
sha1Hash             : 05:69:31:14:c9:41:0d:30:d6:52:e6:83:e8:6a:56:ad:1e:84:a5:37
md5Hash              : 1c:cb:26:9b:2b:b5:09:6f:b1:cd:91:00:c3:f7:34:9f
isCa                 : false
isValid              : true

$CheckImportTest.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                                                                  
-------- -------- ----                                     --------                                                                                                                                                                                  
True     False    PSCustomObject                           System.Object   

主要问题是:是否有更简单的方法将对象的XmlElement类型转换为PSCustomObject

0 个答案:

没有答案