gpt4 book ai didi

parsing - 使用模板的 ConvertFrom-String 未按预期解析

转载 作者:行者123 更新时间:2023-12-03 00:45:08 28 4
gpt4 key购买 nike

我正在尝试利用新的 ConvertFrom-String Windows Management Production Preview 5 中的命令行开关.

我有一个我试图从中解析数据的字符串的 $Sample 以及我正在使用的 $Template

我正在获取所需的大部分数据,但由于某种原因没有获取全部数据。

我读过一篇number of blog articles关于该主题,并且无法使用 ConvertFrom-String Buddy 进行解析但我无法让它提取我需要的所有数据。

您能否让我深入了解一下我可能做错了什么,导致捕获了大部分数据但未捕获全部数据?

预先感谢您提供的任何帮助或见解。

PowerShell 版本:

PS C:\Users\alozano\Desktop> $psversiontable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
5 0 10514 6

这是正在运行的 powershell 代码:

$Sample = @"
JJK072821.12Z1220126.23630-01.S.JABI
+20.0 DARKNESS
6 IPS PRINT SPEED
+000 TEAR OFF
APPLICATOR PRINT MODE
NON-CONTINUOUS MEDIA TYPE
WEB SENSOR TYPE
DIRECT-THERMAL PRINT METHOD
812 PRINT WIDTH
1874 LABEL LENGTH
9.0IN 228MM MAXIMUM LENGTH
DISABLED SUPPLIES WARNING
MAINT. OFF EARLY WARNING
CONNECTED USB COMM.
READY EXTERNAL 5V
BIDIRECTIONAL PARALLEL COMM.
RS232 SERIAL COMM.
9600 BAUD
8 BITS DATA BITS
NONE PARITY
XON/XOFF HOST HANDSHAKE
NONE PROTOCOL
000 NETWORK ID
NORMAL MODE COMMUNICATIONS
<~> 7EH CONTROL PREFIX
<^> 5EH FORMAT PREFIX
<,> 2CH DELIMITER CHAR
ZPL II ZPL MODE
ACTIVE COMMAND OVERRIDE
NO MOTION MEDIA POWER UP
NO MOTION HEAD CLOSE
OFF BACKFEED
+080 LABEL TOP
+0000 LEFT POSITION
OFF VERIFIER PORT
MODE 1 APPLICATOR PORT
ENABLED ERROR ON PAUSE
PULSE MODE START PRINT SIG
FEED MODE RESYNCH MODE
DISABLED REPRINT MODE
048 WEB S.
079 MEDIA S.
065 RIBBON S.
100 TAKE LABEL
050 MARK S.
000 MARK MED S.
002 TRANS GAIN
040 TRANS BASE
086 TRANS BRIGHT
082 RIBBON GAIN
000 MARK GAIN
DPCSWFX. MODES ENABLED
.......M MODES DISABLED
832 8/MM FULL RESOLUTION
V53.17.21Z <- FIRMWARE
1.3 XML SCHEMA
V45 ---------- 19 HARDWARE ID
CUSTOMIZED CONFIGURATION
10840k...........R: RAM
2048k............E: ONBOARD FLASH
NONE FORMAT CONVERT
*** APPLICATOR P34 INTERFACE
TWINAX/COAX ID
FW VERSION IDLE DISPLAY
11/05/15 RTC DATE
11:22 RTC TIME
DISABLED ZBI
2.1 ZBI VERSION
2,641,289 IN NONRESET CNTR
2,641,289 IN RESET CNTR1
2,641,289 IN RESET CNTR2
6,708,875 CM NONRESET CNTR
6,708,875 CM RESET CNTR1
6,708,875 CM RESET CNTR2
ALL ITEMS PASSWORD LEVEL
"@

$TemplateThatFails = @"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{ZBIVersion:2.1} ZBI VERSION
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{ResetCNTR2cm:6,708,875 CM} RESET CNTR2
{PasswordLevel:ALL ITEMS}} PASSWORD LEVEL
"@

$TemplateThatPartiallyWorks= @"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{ZBIVersion:2.1}} ZBI VERSION
"@

Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig

Write-Host "Using ConvertFrom-String with the TemplateThatPartiallyWorks"
$Sample | ConvertFrom-String -TemplateContent $TemplateThatPartiallyWorks| select -ExpandProperty ZebraConfig

我得到以下结果:

Using ConvertFrom-String with the TemplateThatFails
ConvertFrom-String : ConvertFrom-String appears to be having trouble parsing your data using the template you've provided. We'd love to take a look at what went wrong, if you'd like to share the data and template used to parse it. We've saved these files to
C:\Users\alozano\AppData\Local\Temp\usiqowuu.p2u.input.txt and C:\Users\alozano\AppData\Local\Temp\usiqowuu.p2u-0.template.txt - feel free to attach them in a mail to psdmfb@microsoft.com. We will review all submissions, although we can't guarantee a response.
At line:231 char:16
+ ... codedHTML | ConvertFrom-String -TemplateContent $TemplateThatFails | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [ConvertFrom-String], ResultNotFoundException
+ FullyQualifiedErrorId : ResultNotFound,Microsoft.PowerShell.Commands.StringManipulation.ConvertFromStringCommand

Using ConvertFrom-String with the TemplateThatPartiallyWorks


Serial : JJK072821.12Z1220126.23630-01.S.JABI
Darkness : +20.0
PrintSpeed : 6 IPS
TearOff : +000
Applicator : APPLICATOR
MediaType : NON-CONTINUOUS
SensorType : WEB
PrintMethod : DIRECT-THERMAL
PrintWidth : 812
LabelLength : 1874
MaximumLength : 9.0IN 228MM
SuppliesWarning : DISABLED
EarlyWarning : MAINT. OFF
USBComm : CONNECTED
External5v : READY
ParallelComm : BIDIRECTIONAL
SerialComm : RS232
Baud : 9600
DataBits : 8 BITS
Parity : NONE
HostHandshake : XON/XOFF
Protocol : NONE
NetworkID : 000
Communications : NORMAL MODE
ControlPrefix : <~> 7EH
FormatPrefix : <^> 5EH
Delimiter : <,> 2CH
ZPLMode : ZPL II
CommandOverride : ACTIVE
MediaPowerUp : NO MOTION
HeadClose : NO MOTION
Backfeed : OFF
LabelTop : +080
LeftPosition : +0000
VerifierPort : OFF
ApplicatorPort : MODE 1
ErrorOnPause : ENABLED
StartPrintSig : PULSE MODE
ResynchMode : FEED MODE
ReprintMode : DISABLED
WebSensor : 048
MediaSensor : 079
RibbonSensor : 065
TakeLabel : 100
MarkSensor : 050
MarkMedSensor : 000
TrainsGain : 002
TransBase : 040
TransBright : 086
RibbonGain : 082
MarkGain : 000
ModesEnable : DPCSWFX.
ModesDisabled : .......M
Resolution : 832 8/MM FULL
Firmware : V53.17.21Z <-
XMLSchema : 1.3
HardwareID : V45 ---------- 19
Configuration : CUSTOMIZED
RAM : 10840k...........R:
OnboardFlash : 2048k............E:
FormatConvert : NONE
P34Interface : *** APPLICATOR
IdleDisplay : FW VERSION
RTCDate : 11/05/15
RTCTime : 11:22
ZBI : DISABLED
ZBIVersion : 2.1

这些是位于 $TemplateThatFails 末尾的 7 行,我在 $TemplateThatPartiallyWorks 中省略了它们:

{NonResetCNTRin:2,641,289 IN}        NONRESET CNTR     
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{ResetCNTR2cm:6,708,875 CM} RESET CNTR2
{PasswordLevel:ALL ITEMS}} PASSWORD LEVEL

系统信息:

Operating System: Windows 8.1 Enterprise 64-bit (6.3, Build 9600) (9600.winblue_r9.150322-1500)
Language: English (Regional Setting: English)
System Manufacturer: Dell Inc.
System Model: Latitude E7450
BIOS: BIOS Date: 12/29/14 05:36:41 Ver: A02.00
Processor: Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz (4 CPUs), ~2.3GHz
Memory: 8192MB RAM
Available OS Memory: 8082MB RAM

最佳答案

我的设置完全相同(i5/16Gb/Win8.1 64bit/PS 5.0.10514.6)。

这有点疯狂;只有最后一行有问题。

1 - 如果您将其完全隔离并使其成为模板和示例中的唯一行,则它可以工作。

代码:

$Sample = @"  
ALL ITEMS PASSWORD LEVEL
"@

$TemplateThatFails = @"
{Zebraconfig*:{PasswordLevel:ALL ITEMS}} PASSWORD LEVEL
"@

Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$startTime = Get-Date
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
$endTime = Get-Date
$elapsed = "{0:N2}" -f (New-TimeSpan $startTime $endTime).TotalSeconds
"$elapsed seconds elapsed"

输出:

PasswordLevel
-------------
ALL ITEMS
0,13 seconds elapsed

2 - 如果将其移到前一个的上方(在示例和模板中),您不会收到任何错误,但数据会混淆。

代码:

$Sample = @"
JJK072821.12Z1220126.23630-01.S.JABI
+20.0 DARKNESS
6 IPS PRINT SPEED
+000 TEAR OFF
APPLICATOR PRINT MODE
NON-CONTINUOUS MEDIA TYPE
WEB SENSOR TYPE
DIRECT-THERMAL PRINT METHOD
812 PRINT WIDTH
1874 LABEL LENGTH
9.0IN 228MM MAXIMUM LENGTH
DISABLED SUPPLIES WARNING
MAINT. OFF EARLY WARNING
CONNECTED USB COMM.
READY EXTERNAL 5V
BIDIRECTIONAL PARALLEL COMM.
RS232 SERIAL COMM.
9600 BAUD
8 BITS DATA BITS
NONE PARITY
XON/XOFF HOST HANDSHAKE
NONE PROTOCOL
000 NETWORK ID
NORMAL MODE COMMUNICATIONS
<~> 7EH CONTROL PREFIX
<^> 5EH FORMAT PREFIX
<,> 2CH DELIMITER CHAR
ZPL II ZPL MODE
ACTIVE COMMAND OVERRIDE
NO MOTION MEDIA POWER UP
NO MOTION HEAD CLOSE
OFF BACKFEED
+080 LABEL TOP
+0000 LEFT POSITION
OFF VERIFIER PORT
MODE 1 APPLICATOR PORT
ENABLED ERROR ON PAUSE
PULSE MODE START PRINT SIG
FEED MODE RESYNCH MODE
DISABLED REPRINT MODE
048 WEB S.
079 MEDIA S.
065 RIBBON S.
100 TAKE LABEL
050 MARK S.
000 MARK MED S.
002 TRANS GAIN
040 TRANS BASE
086 TRANS BRIGHT
082 RIBBON GAIN
000 MARK GAIN
DPCSWFX. MODES ENABLED
.......M MODES DISABLED
832 8/MM FULL RESOLUTION
V53.17.21Z <- FIRMWARE
1.3 XML SCHEMA
V45 ---------- 19 HARDWARE ID
CUSTOMIZED CONFIGURATION
10840k...........R: RAM
2048k............E: ONBOARD FLASH
NONE FORMAT CONVERT
*** APPLICATOR P34 INTERFACE
TWINAX/COAX ID
FW VERSION IDLE DISPLAY
11/05/15 RTC DATE
11:22 RTC TIME
DISABLED ZBI
2.1 ZBI VERSION
2,641,289 IN NONRESET CNTR
2,641,289 IN RESET CNTR1
2,641,289 IN RESET CNTR2
6,708,875 CM NONRESET CNTR
6,708,875 CM RESET CNTR1
ALL ITEMS PASSWORD LEVEL
6,708,875 CM RESET CNTR2
"@

$TemplateThatFails = @"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{ZBIVersion:2.1} ZBI VERSION
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{PasswordLevel:ALL ITEMS} PASSWORD LEVEL
{ResetCNTR2cm:6,708,875 CM}} RESET CNTR2
"@

Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$startTime = Get-Date
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
$endTime = Get-Date
$elapsed = "{0:N2}" -f (New-TimeSpan $startTime $endTime).TotalSeconds
"$elapsed seconds elapsed"

输出:

Serial          : JJK072821.12Z1220126.23630-01.S.JABI
Darkness : +20.0
PrintSpeed : 6 IPS
TearOff : +000
Applicator : APPLICATOR
MediaType : NON-CONTINUOUS
SensorType : WEB
PrintMethod : DIRECT-THERMAL
PrintWidth : 812
LabelLength : 1874
MaximumLength : 9.0IN 228MM
SuppliesWarning : DISABLED
EarlyWarning : MAINT. OFF
USBComm : CONNECTED
External5v : READY
ParallelComm : BIDIRECTIONAL
SerialComm : RS232
Baud : 9600
DataBits : 8 BITS
Parity : NONE
HostHandshake : XON/XOFF
Protocol : NONE
NetworkID : 000
Communications : NORMAL MODE
ControlPrefix : <~> 7EH
FormatPrefix : <^> 5EH
Delimiter : <,> 2CH
ZPLMode : ZPL II
CommandOverride : ACTIVE
MediaPowerUp : NO MOTION
HeadClose : NO MOTION
Backfeed : OFF
LabelTop : +080
LeftPosition : +0000
VerifierPort : OFF
ApplicatorPort : MODE 1
ErrorOnPause : ENABLED
StartPrintSig : PULSE MODE
ResynchMode : FEED MODE
ReprintMode : DISABLED
WebSensor : 048
MediaSensor : 079
RibbonSensor : 065
TakeLabel : 100
MarkSensor : 050
MarkMedSensor : 000
TrainsGain : 002
TransBase : 040
TransBright : 086
RibbonGain : 082
MarkGain : 000
ModesEnable : DPCSWFX.
ModesDisabled : .......M
Resolution : 832 8/MM FULL
Firmware : V53.17.21Z <-
XMLSchema : 1.3
HardwareID : V45 ---------- 19
Configuration : CUSTOMIZED
RAM : 10840k...........R:
OnboardFlash : 2048k............E:
FormatConvert : NONE
P34Interface : *** APPLICATOR
IdleDisplay : FW VERSION
RTCDate : 11/05/15
RTCTime : 11:22
ZBI : DISABLED
ZBIVersion : 2.1
NonResetCNTRin : 2,641,289 IN
ResetCNTR1in : 2,641,289 IN
ResetCNTR2in : 2,641,289 IN
NonResetCNTRcm : 6,708,875 CM
ResetCNTR1cm : 6,708,875 CM
PasswordLevel : CM RESET
ResetCNTR2cm : 6,708,875 CM

36,58 seconds elapsed

3 - 如果将其移至 ZBI VERSION(示例 + 模板)(部分工作模板中的最后一行)上方,则一切正常。

代码:

$Sample = @"
JJK072821.12Z1220126.23630-01.S.JABI
+20.0 DARKNESS
6 IPS PRINT SPEED
+000 TEAR OFF
APPLICATOR PRINT MODE
NON-CONTINUOUS MEDIA TYPE
WEB SENSOR TYPE
DIRECT-THERMAL PRINT METHOD
812 PRINT WIDTH
1874 LABEL LENGTH
9.0IN 228MM MAXIMUM LENGTH
DISABLED SUPPLIES WARNING
MAINT. OFF EARLY WARNING
CONNECTED USB COMM.
READY EXTERNAL 5V
BIDIRECTIONAL PARALLEL COMM.
RS232 SERIAL COMM.
9600 BAUD
8 BITS DATA BITS
NONE PARITY
XON/XOFF HOST HANDSHAKE
NONE PROTOCOL
000 NETWORK ID
NORMAL MODE COMMUNICATIONS
<~> 7EH CONTROL PREFIX
<^> 5EH FORMAT PREFIX
<,> 2CH DELIMITER CHAR
ZPL II ZPL MODE
ACTIVE COMMAND OVERRIDE
NO MOTION MEDIA POWER UP
NO MOTION HEAD CLOSE
OFF BACKFEED
+080 LABEL TOP
+0000 LEFT POSITION
OFF VERIFIER PORT
MODE 1 APPLICATOR PORT
ENABLED ERROR ON PAUSE
PULSE MODE START PRINT SIG
FEED MODE RESYNCH MODE
DISABLED REPRINT MODE
048 WEB S.
079 MEDIA S.
065 RIBBON S.
100 TAKE LABEL
050 MARK S.
000 MARK MED S.
002 TRANS GAIN
040 TRANS BASE
086 TRANS BRIGHT
082 RIBBON GAIN
000 MARK GAIN
DPCSWFX. MODES ENABLED
.......M MODES DISABLED
832 8/MM FULL RESOLUTION
V53.17.21Z <- FIRMWARE
1.3 XML SCHEMA
V45 ---------- 19 HARDWARE ID
CUSTOMIZED CONFIGURATION
10840k...........R: RAM
2048k............E: ONBOARD FLASH
NONE FORMAT CONVERT
*** APPLICATOR P34 INTERFACE
TWINAX/COAX ID
FW VERSION IDLE DISPLAY
11/05/15 RTC DATE
11:22 RTC TIME
DISABLED ZBI
ALL ITEMS PASSWORD LEVEL
2.1 ZBI VERSION
2,641,289 IN NONRESET CNTR
2,641,289 IN RESET CNTR1
2,641,289 IN RESET CNTR2
6,708,875 CM NONRESET CNTR
6,708,875 CM RESET CNTR1
6,708,875 CM RESET CNTR2
"@

$TemplateThatFails = @"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{PasswordLevel:ALL ITEMS} PASSWORD LEVEL
{ZBIVersion:2.1} ZBI VERSION
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{ResetCNTR2cm:6,708,875 CM}} RESET CNTR2
"@

Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$startTime = Get-Date
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
$endTime = Get-Date
$elapsed = "{0:N2}" -f (New-TimeSpan $startTime $endTime).TotalSeconds
"$elapsed seconds elapsed"

输出:

Serial          : JJK072821.12Z1220126.23630-01.S.JABI
Darkness : +20.0
PrintSpeed : 6 IPS
TearOff : +000
Applicator : APPLICATOR
MediaType : NON-CONTINUOUS
SensorType : WEB
PrintMethod : DIRECT-THERMAL
PrintWidth : 812
LabelLength : 1874
MaximumLength : 9.0IN 228MM
SuppliesWarning : DISABLED
EarlyWarning : MAINT. OFF
USBComm : CONNECTED
External5v : READY
ParallelComm : BIDIRECTIONAL
SerialComm : RS232
Baud : 9600
DataBits : 8 BITS
Parity : NONE
HostHandshake : XON/XOFF
Protocol : NONE
NetworkID : 000
Communications : NORMAL MODE
ControlPrefix : <~> 7EH
FormatPrefix : <^> 5EH
Delimiter : <,> 2CH
ZPLMode : ZPL II
CommandOverride : ACTIVE
MediaPowerUp : NO MOTION
HeadClose : NO MOTION
Backfeed : OFF
LabelTop : +080
LeftPosition : +0000
VerifierPort : OFF
ApplicatorPort : MODE 1
ErrorOnPause : ENABLED
StartPrintSig : PULSE MODE
ResynchMode : FEED MODE
ReprintMode : DISABLED
WebSensor : 048
MediaSensor : 079
RibbonSensor : 065
TakeLabel : 100
MarkSensor : 050
MarkMedSensor : 000
TrainsGain : 002
TransBase : 040
TransBright : 086
RibbonGain : 082
MarkGain : 000
ModesEnable : DPCSWFX.
ModesDisabled : .......M
Resolution : 832 8/MM FULL
Firmware : V53.17.21Z <-
XMLSchema : 1.3
HardwareID : V45 ---------- 19
Configuration : CUSTOMIZED
RAM : 10840k...........R:
OnboardFlash : 2048k............E:
FormatConvert : NONE
P34Interface : *** APPLICATOR
IdleDisplay : FW VERSION
RTCDate : 11/05/15
RTCTime : 11:22
ZBI : DISABLED
PasswordLevel : ALL ITEMS
ZBIVersion : 2.1
NonResetCNTRin : 2,641,289 IN
ResetCNTR1in : 2,641,289 IN
ResetCNTR2in : 2,641,289 IN
NonResetCNTRcm : 6,708,875 CM
ResetCNTR1cm : 6,708,875 CM
ResetCNTR2cm : 6,708,875 CM

36,32 seconds elapsed

我真的不明白发生了什么,但我已经设法抑制了错误,所以我希望这能为您指明正确的方向。

PS:为什么运行这么长时间?!

关于parsing - 使用模板的 ConvertFrom-String 未按预期解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33577350/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com