我正在使用一个工具,该工具将从客户环境中收集数据,然后将这些收集的数据收集到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
答案 0 :(得分:1)
Export-Clixml
有一个import React, { Component } from 'react';
import $ from 'jquery';
class Upload extends Component {
constructor(props) {
super(props);
this.state = {
selectedFile: null,
prevImgURL: '',
imgPrev: false
};
this.imageChange = this.imageChange.bind(this);
}
fileUpload() {
if($("#new_post_image").click()) {
this.setState({imgPrev: true});
}
}
imageChange(e) {
e.preventDefault();
let reader = new FileReader();
let file = e.target.files[0];
reader.onloadend = () => {
this.setState({
selectedFile: file,
prevImgURL: reader.result
});
}
reader.readAsDataURL(file);
}
render() {
return(
<div>
<form>
<input
id="new_post_image"
type="file"
onChange={this.imageChange}
name="image"
accept="image/*"
/>
<button
type="button"
onClick={this.fileUpload.bind(this)}
>Preview Image</button>
<div>
{this.state.imgPrev ? this.state.selectedFile : null}
</div>
</form>
</div>
);
}
}
export default Upload;
参数,不幸的是默认为2。
由于您的最高对象是1级,而您的-Depth
是2级,看来您可能需要增加该值!
NsxmanagerCertificate
您可以尝试使用数字(3个对您来说可能是个好选择),或者只是随风而行,随它而去。