# Check by powershell

**URL:** <https://community.icinga.com/t/check-by-powershell/6601>\
**Category:** Icinga Director\
**Tags:** powershell\
**Created:** [February 1, 2021, 2:49pm UTC](https://community.icinga.com/t/check-by-powershell/6601 "2021-02-01T14:49:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 1, 2021, 2:49pm UTC](https://community.icinga.com/t/check-by-powershell/6601/1 "2021-02-01T14:49:57Z")

</div>

Hi

Icinga agent installation causing memory leak in our windows server and only very few checks are running on the server

So I am trying [check\_by powershell](https://github.com/Icinga/check_by_powershell) in director method  
Unfortunately i am not getting correct details how to configure it in director way.commands are genereted in external commands sections also I am getting the output from linux cmd line.  
anyone tried the same ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [February 1, 2021, 3:06pm UTC](https://community.icinga.com/t/check-by-powershell/6601/2 "2021-02-01T15:06:26Z")

</div>

Hi @krishna

Are you using the powershell framework? You can [import the commands](https://github.com/Icinga/icinga-powershell-framework/blob/master/doc/icingaintegration/01-Director-Baskets.md) into the director.

Kind regards

---

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 1, 2021, 4:37pm UTC](https://community.icinga.com/t/check-by-powershell/6601/3 "2021-02-01T16:37:05Z")

</div>

Hi @ritzgu,

Powershell framework i am using

Commands are also imported through Director basket configuration

Still confused how i can declare the variable as mentioned in the example [Powershell](https://github.com/Icinga/check_by_powershell)

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [February 1, 2021, 5:18pm UTC](https://community.icinga.com/t/check-by-powershell/6601/4 "2021-02-01T17:18:33Z")

</div>

I may have misread your question. Are you trying to check via WinRM or the icinga2 agent?

---

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 1, 2021, 5:22pm UTC](https://community.icinga.com/t/check-by-powershell/6601/5 "2021-02-01T17:22:10Z")

</div>

Hi @ritzgu yes I am trying check via winrm

Regards

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [February 2, 2021, 10:55am UTC](https://community.icinga.com/t/check-by-powershell/6601/6 "2021-02-02T10:55:00Z")

</div>

I think the commands imported via the director basket require a local agent to execute the checks. What i think you want to do is check the windows host remotely via `check_by_powershell` and WinRM. I guess you have to create your own command definition for this.

---

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 2, 2021, 1:58pm UTC](https://community.icinga.com/t/check-by-powershell/6601/7 "2021-02-02T13:58:51Z")

</div>

Yes

I have created my own command definitions  
Like checking cpu load in the external command section

But dont know how to do it in director way  
What are the variables need to declared

Would have been good if they provide some more example

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [February 3, 2021, 9:22am UTC](https://community.icinga.com/t/check-by-powershell/6601/8 "2021-02-03T09:22:04Z")

</div>

Hi,

I tried to recreate the [example command](https://github.com/Icinga/check_by_powershell/blob/master/icinga2/command.conf). Instead of using a dictionary for the `--icingacmd`, i just used a string.  
 ![grafik](https://community.icinga.com/uploads/default/original/2X/1/1104e1ea36944d95ea74c16e1db2dcf1053a21e2.png)  
Then I created another command for the specific check which imports the above command. The arguments can be directly added to the command string.  
 ![grafik](https://community.icinga.com/uploads/default/original/2X/1/110db05787eb9ab462564f3212b0a329dda85e7b.png)  
[Idea from here](https://github.com/Icinga/icingaweb2-module-director/issues/1884#issuecomment-504317570)

Kind regards

---

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 3, 2021, 11:15am UTC](https://community.icinga.com/t/check-by-powershell/6601/9 "2021-02-03T11:15:54Z")

</div>

Hi

Could you please show me the preview of the command and service

what is the argument you created for powershell\_command?  
Thanks

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [February 3, 2021, 11:39am UTC](https://community.icinga.com/t/check-by-powershell/6601/10 "2021-02-03T11:39:46Z")

</div>

Sure.

```auto
# preview of powershell template
object CheckCommand "by_powershell" {
    import "plugin-check-command"
    command = [PluginDir + "/check_by_powershell"]
    arguments += {
        "--auth" = "$powershell_auth$"
        "--ca" = "$powershell_ca$"
        "--cert" = "$powershell_cert$"
        "--cmd" = "$powershell_cmd$"
        "--icingacmd" = "$powershell_command$"
        "--insecure" = {
            set_if = "$powershell_insecure$"
        }
        "--key" = "$powershell_key$"
        "--no-tls" = {
            set_if = "$powershell_no_tls$"
        }
        "--password" = "$powershell_password$"
        "--sshhost" = "$powershell_sshhost$"
        "--sshpassword" = "$powershell_sshpassword$"
        "--sshuser" = "$powershell_sshuser$"
        "--user" = "$powershell_user$"
        "-H" = "$powershell_host$"
        "-p" = "$powershell_port$"
    }
    vars.powershell_insecure = true
}

```

```auto
// preview of specific cpu command
object CheckCommand "by_powershell_cpu" {
    import "plugin-check-command"
    import "by_powershell"

    vars.powershell_command = "Invoke-IcingaCheckCPU -Warning $powershell_cpu_warning$ -Critical $powershell_cpu_critical$"
    vars.powershell_cpu_critical = "90"
    vars.powershell_cpu_warning = "80"
    vars.powershell_host = "$address$"
}

```

In the director you have to add the custom fields for the thresholds to the command.  
The resolved service command:

```auto
// preview of service
apply Service "test-cpu" {
    import "agent-service"

    check_command = "by_powershell_cpu"
    assign where host.vars.os == "windows"
    vars.powershell_cpu_critical = "90"
    vars.powershell_cpu_warning = "75"
    vars.powershell_password = "some_password"
    vars.powershell_port = "5986"
    vars.powershell_user = "some_user"

    import DirectorOverrideTemplate
}

```

---

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 3, 2021, 11:43am UTC](https://community.icinga.com/t/check-by-powershell/6601/11 "2021-02-03T11:43:21Z")

</div>

Thanks for your input

Let me check it and try to configure it  
So it means for each check we need to create respective commands?  
Regards

---

<div class="post-metadata">

**Author:** ![ritzgu](https://community.icinga.com/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@ritzgu](https://community.icinga.com/u/ritzgu)\
**Post date:** [February 3, 2021, 2:45pm UTC](https://community.icinga.com/t/check-by-powershell/6601/12 "2021-02-03T14:45:19Z")

</div>

I don’t know if there’s a better way now but i had the same problem in the past with by\_ssh and found [this discussion](https://community.icinga.com/t/example-for-a-check-by-ssh-using-the-director/2076/3) to be useful. Maybe this will change with the support for [dictionaries](https://github.com/Icinga/icingaweb2-module-director/issues/337).

---

<div class="post-metadata">

**Author:** ![krishna](https://community.icinga.com/user_avatar/community.icinga.com/krishna/32/2922_2.png) [@krishna](https://community.icinga.com/u/krishna)\
**Post date:** [February 3, 2021, 3:48pm UTC](https://community.icinga.com/t/check-by-powershell/6601/13 "2021-02-03T15:48:57Z")

</div>

Ok thanks for your valuable suggestion and your time

Thanks and Regards  
Krishna
