Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@marshyski
Created September 4, 2015 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshyski/3a3f37f15cd5cc7985a8 to your computer and use it in GitHub Desktop.
Save marshyski/3a3f37f15cd5cc7985a8 to your computer and use it in GitHub Desktop.
Windows fact to parse file by pattern and show field by space delimiter
Facter.Add(:test1) do
confine :kernel => 'Windows'
setcode do
powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe'
test1 = 'Get-Content C:\test.txt | Select-String -Pattern "test1" - SimpleMatch | foreach { $_.ToString().split(" ")[1]}'
Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{test1}"})
end
end
# Below is example of file
# Content of C:\test.txt
# test1 one
# test2 two
# test3 three
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment