Ask Your Question
0

Verify windows feature state

asked 2017-03-17 15:58:07 -0500

k1911 gravatar image

updated 2017-03-20 15:41:38 -0500

DarylW gravatar image

How can I verify if DHCP tools is already installed before executing the script to install dhcp tools. In my add-dhcptools.ps1 I have else statement that will exit the script, however puppet will execute the exec block.

exec{'add-dhcptools':
            path => 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0',
            command => 'powershell -executionpolicy remotesigned -file "c:/add-dhcptools.ps1"',
    }

powershell script

 Import-Module servermanager 
$installedstate = Get-WindowsFeature -Name RSAT-DHCP|select *
if(($installedstate).installed -eq $false)
    {
        Add-WindowsFeature -Name RSAT-DHCP -Restart:$false -IncludeAllSubFeature -Confirm:$false
     }
     else{

        exit 0
     }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-03-20 06:18:47 -0500

Eric_Anderson gravatar image

https://docs.puppet.com/puppet/4.9/re...execwindows.html

If you add an onlyif parameter to your resource exec you can run a command to check if DHCP tools is already installed. See the onlyif section of code. onlyif says that it will run the exec resource only if the command in the onlyif section of the exec resource is true.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-17 15:57:39 -0500

Seen: 26 times

Last updated: Mar 20