我有一个用于搜索字符串的powershell脚本,当我直接从powershell命令提示符运行它时,该脚本可以工作,但是当我将它放入热模板的用户数据时无法运行:脚本是:
$regex = [regex]"(?<=\>)(\d+)(.*)SNAPSHOT(?=\/\<)"
$allsnapshot=$regex.Matches($testcode1) | % { $_.matches } | % { $_.value } |get-unique |sort -descending
错误是:
execute_user_data_script C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\Python27\lib\site-packages\cloudbaseinit\plugins\windows\userdatautils.py:58
2015-04-25 12:11:45.140 1796 DEBUG cloudbaseinit.plugins.windows.userdatautils [-] User_data stderr:
The term '?<=\>' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\cloudbase-init\appdata\local\temp\835603b2-b3dc-4a9b-a156-029c75322
a8f.ps1:26 char:24
+ $regex = [regex]"(?<=\> <<<< )(\d+)(.*)SNAPSHOT(?=\/\<)"
+ CategoryInfo : ObjectNotFound: (?<=\>:String) [], CommandNotFou
ndException
+ FullyQualifiedErrorId : CommandNotFoundException
我认为这是一个解析问题。但不知道如何解决。那么如何避免 Python 解析它呢?
我为此挣扎了好几天。我很感激任何建议。