I have a PowerShell script file: C:\Workdir\createLog.ps1
I want to comment out this line Remove-Item -Force ($Path + '*' + $Suffix); in the script
I use ansible to do it automatically, using win_lineinfile module. The code is like this:
- name: Comment out content
win_lineinfile:
path: "C:\\Workdir\\createLog.ps1"
regexp: '^(\s+)Remove-Item -Force \(\$Path \+ \'\*\' \+ \$Suffix\);'
line: '$1# Remove-Item -Force ($Path + '*' + $Suffix);'
backrefs: yes
But it returns an error, because '*' cannot pass as string at regexp