I am new to Powershell scripting and i have gone through the powershell tutorial to complete my current script requirement.
I am trying to add exclamatory mark to the line by matching the pattern. I am having similar test.default file as below
"/AgentSetup/__type__"
"/AgentSetup/__name__"
"/AgentSetup/preloadedKs"
"/AgentSetup/preloadedKMsArch"
"/AgentSetup/loadOnlyPreloadedKMs"
More lines like this in the file
So here i am trying add exclamatory mark to the starting of the line by matching for example if i search for "/AgentSetup/preloadedKs" = { REPLACE="" }, then in the file it should look like
"/AgentSetup/__type__"
"/AgentSetup/__name__"
"/AgentSetup/preloadedKs"
!"/AgentSetup/defaultAccount"
"/AgentSetup/preloadedKMsArch"
"/AgentSetup/loadOnlyPreloadedKMs"
I tried below commands to achieve this but not succeefull
$TEST = "C:\Asset\config.default"
$Pattern = "/AgentSetup/defaultAccount"
$var = "!" + (Select-String -Path $TEST -pattern $Pattern | Out-String)
$var
$var + (Get-Content $TEST -Raw) | Set-Content $TEST
The above commands is not just adding exclamatory mark but adding dublicate entry in the file like this:
!
test.default:103:"/AgentSetup/defaultAccount"
I have gone through powershell Add-Content
and Select-String
tutorial even I searched Get-Content
. Please guide me to the right direction so i can achieve this it would be helpful.