Ask Your Question

Verify windows feature state

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

k1911 gravatar image

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

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.

            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

        exit 0
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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

puser gravatar image

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


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

Seen: 73 times

Last updated: Mar 20 '17