Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

How to run powershell concatenated commands?

$
0
0
Hello all, I am struggling to get a command working to get the ownership of a registry key and change it if its different than what I am expecting... This is my current code using the powershell provider: exec {'change reg key ownership': command => 'C:\Windows\Temp\myscript.ps1' unless => 'get-acl -path "hklm:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" | select owner | select-string Administrators', provider => powershell, } Puppet does not recognize the unless command successfully, since the concatenation to select and validate the key owner fails. To be able to run the command successfully, additional quotes should be added to treat the whole command as one and not as many, but puppet does not seem to like it. I am able to run the command successfully from cmd by running this command: C:\Windows\System32\WindowsPowerShell\v1.0>powershell.exe -executionpolicy remotesigned "get-acl -path 'hklm:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost' | select owner | select-string Administrators" This works from a command line, but how can I translate that to puppet syntax? I tried using the exec resource without the powershell provider and although it seems to be doing something else, it does not seem to do the right thing yet... exec {'change reg key ownership': command => 'C:\Windows\Temp\myscript.ps1' unless => "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -executionpolicy remotesigned get-acl -path 'hklm:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost' | select owner | select-string Administrator", } I can see that the unless command runs successfully when the registry key owner is Administrator (puppet agent -t -d shows the command run and result), however when someone else owns the key, it does run but it does not fail (return something != 0). Any ideas to make it work?

Viewing all articles
Browse latest Browse all 6104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>