I have a powershell script to search a string, and the script worked when I run it from powershell command prompt directly, but failed to run when I put it in userdata of heat template: The script is:
$regex = [regex]"(?<=\>)(\d+)(.*)SNAPSHOT(?=\/\<)"
$allsnapshot=$regex.Matches($testcode1) | % { $_.matches } | % { $_.value } |get-unique |sort -descending
The error is:
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
I think it's a parse issue. but don't know how to fix it. So how can I avoid Python to parse it?
I struggled on it for several days. I appreciate any advice.