• Hello,

    I was viewing a powershell script I saw online about 2 days ago and I got it to add the new machine in the fog server with the MAC address fine. I also saw how to add 1 or more snapins if needed, so thank you for that.

    Here’s my question. So is there a powershell command to select adding the Active Directory option to the new host instead of going to the console to check off for each new host?

    screen shot.PNG

    I know how to do it in the console, but want to know how to do it in this script I saw on the forum by ScottyBullet: https://forums.fogproject.org/topic/11183/api-create-host-deploy-task-error-invalid-tasking-type-passed/7?_=1590872437608

    So I’m basically putting the Powershell script together when the other techs put in the valid info in Microsoft Orchestrator, it will kick off the powershell script, add the machine to the fog database and kick off imaging while plugged into the network.

    Appreciate all the hard work on this forum. I’ve learned a lot on here and imaged a lot of computers from last year.


  • @JJ-Fullmer said in Need Powershell help:

    @Jamaal I believe that the wake on lan is enabled by default, so you don’t need to do anything to include it when creating the deploy task via the api.

    Ok, gotcha.

    Thank you very much for letting me know of this.

  • Testers

    @Jamaal I believe that the wake on lan is enabled by default, so you don’t need to do anything to include it when creating the deploy task via the api.


  • @JJ-Fullmer said in Need Powershell help:

    TL;DR
    The quick answer is the ‘useAD’ property of a host in the api checks that box, but will not pull your default settings when done through the api. So you need to provide all domain join info.

    @Jamaal Good day sir! Sorry for a delayed reply, haven’t been on here in a bit, had been trying to stay active during my quarantine but eventually my infant son won all my attention while I was home. But I am now back at work and am excited to see someone with a powershell api question =).

    I took a look at that old post and @scottybullet and I should clearly be friends. Looks like he posted some powershell api stuff before I published my module publicly.

    So as @Sebastian-Roth mentioned, check out the powershell module (check the links in my signature). If you use that as a dependency of your script you’ll have a good time. If this leads to some more functions needing to be added to the module to make it easier we can make the functions and get them added.

    So let me see if I got this straight.

    You have microsoft orchestrator (I’m not actually familiar with that product, but I think I get what it does from context)

    1. You want other employees to put info about a new computer into that product in some way
    2. That product sends that info to a powershell script
    3. The script adds the computer to fog and queues it to start imaging with wake on lan as soon as you plug it in to the network.

    Currently it isn’t auto joining the domain but you want it to.

    Well sir I believe the answer may be pretty easy. I usually add fog hosts using the pxe boot menu
    Firstly, something built in fog is setting default AD settings at http://fog-server/fog/management/index.php?node=about&sub=settings (select Active directory defaults). I pull that info when I register a host in the pxe boot menu and then edit it during a provisioning script to put things in the right OU. But I just realized that doesn’t matter because it doesn’t pull that information when you create from the API, but it’s still a feature that exists and there may be a way to leverage it in your situation but we’ll come back to that if we need to.

    Ok so first let’s create a host

    # you can also just do name, description, and macs and add the rest after with a set-fogobject command
    $HostJson = @{
        "name"=  "testHost-1"
        "description"=  "a test"
        "macs" =  @("11:22:33:44:55:66")
        "imageID" = "29"
        "useAD" = 1 
        "ADDomain" = "yourDomain.com"
        "ADOU" =  "OU=OUname,OU=ParentOU,OU=GrandParrentOU,DC=yourDomain,DC=com"
        "ADUser" = "domainUsername"
        "ADPass" = "plainTextPassword"
        "enforce" = 1
    }
    #note that "useAD" = 1 checks the join domain after deploy box
    #note that "enforce" = 1 checks the force rename and join even if user is logged in box
    #note that the password is in plaintext via the api because you are already authenticated to get to this point, this is why I prefer to pull from the existing default so I don't pass the password in plaintext anywhere. 
    
    #convert to ps object to a json string
    $json = $hostJson | ConvertTo-Json
    $newHost = New-FogObject -type object -coreObject host -jsonData $json
    

    Sidenote: @Tom-Elliott or @Sebastian-Roth is it possible to pull the default domain settings include username/password from the fog settings via the api? So that to add domain join info through an api call doesn’t require a plaintext password, or maybe some other solution, like making it so the defaults are pulled if a host created with the api has that join after deploy/useAD box checked?

    So that above code would add a new host with the domain information and stores the host info in a variable. You could then queue the image of the host with (I should really make a function for this)

    $jsonObj = @{
        "taskTypeID" = 1
    }
    $jsonData = $jsonObj | ConvertTo-Json;
    # create the image task on the newhost 
    New-FogObject -type objecttasktype -coreTaskObject host -jsonData $jsonData -IDofObject $newHost.ID;
    

    Thank you so much! Much appreciated. I’m starting to play around with both your script and Scotty’s as well. I started looking over the get-fogobject and just trying to get the option to use wake on LAN. If you have any idea on how to do so, I appreciate it.

  • Testers

    TL;DR
    The quick answer is the ‘useAD’ property of a host in the api checks that box, but will not pull your default settings when done through the api. So you need to provide all domain join info.

    @Jamaal Good day sir! Sorry for a delayed reply, haven’t been on here in a bit, had been trying to stay active during my quarantine but eventually my infant son won all my attention while I was home. But I am now back at work and am excited to see someone with a powershell api question =).

    I took a look at that old post and @scottybullet and I should clearly be friends. Looks like he posted some powershell api stuff before I published my module publicly.

    So as @Sebastian-Roth mentioned, check out the powershell module (check the links in my signature). If you use that as a dependency of your script you’ll have a good time. If this leads to some more functions needing to be added to the module to make it easier we can make the functions and get them added.

    So let me see if I got this straight.

    You have microsoft orchestrator (I’m not actually familiar with that product, but I think I get what it does from context)

    1. You want other employees to put info about a new computer into that product in some way
    2. That product sends that info to a powershell script
    3. The script adds the computer to fog and queues it to start imaging with wake on lan as soon as you plug it in to the network.

    Currently it isn’t auto joining the domain but you want it to.

    Well sir I believe the answer may be pretty easy. I usually add fog hosts using the pxe boot menu
    Firstly, something built in fog is setting default AD settings at http://fog-server/fog/management/index.php?node=about&sub=settings (select Active directory defaults). I pull that info when I register a host in the pxe boot menu and then edit it during a provisioning script to put things in the right OU. But I just realized that doesn’t matter because it doesn’t pull that information when you create from the API, but it’s still a feature that exists and there may be a way to leverage it in your situation but we’ll come back to that if we need to.

    Ok so first let’s create a host

    # you can also just do name, description, and macs and add the rest after with a set-fogobject command
    $HostJson = @{
        "name"=  "testHost-1"
        "description"=  "a test"
        "macs" =  @("11:22:33:44:55:66")
        "imageID" = "29"
        "useAD" = 1 
        "ADDomain" = "yourDomain.com"
        "ADOU" =  "OU=OUname,OU=ParentOU,OU=GrandParrentOU,DC=yourDomain,DC=com"
        "ADUser" = "domainUsername"
        "ADPass" = "plainTextPassword"
        "enforce" = 1
    }
    #note that "useAD" = 1 checks the join domain after deploy box
    #note that "enforce" = 1 checks the force rename and join even if user is logged in box
    #note that the password is in plaintext via the api because you are already authenticated to get to this point, this is why I prefer to pull from the existing default so I don't pass the password in plaintext anywhere. 
    
    #convert to ps object to a json string
    $json = $hostJson | ConvertTo-Json
    $newHost = New-FogObject -type object -coreObject host -jsonData $json
    

    Sidenote: @Tom-Elliott or @Sebastian-Roth is it possible to pull the default domain settings include username/password from the fog settings via the api? So that to add domain join info through an api call doesn’t require a plaintext password, or maybe some other solution, like making it so the defaults are pulled if a host created with the api has that join after deploy/useAD box checked?

    So that above code would add a new host with the domain information and stores the host info in a variable. You could then queue the image of the host with (I should really make a function for this)

    $jsonObj = @{
        "taskTypeID" = 1
    }
    $jsonData = $jsonObj | ConvertTo-Json;
    # create the image task on the newhost 
    New-FogObject -type objecttasktype -coreTaskObject host -jsonData $jsonData -IDofObject $newHost.ID;
    

  • @Sebastian-Roth said in Need Powershell help:

    @Jamaal I have not used the PowerShell stuff myself yet and so I can only refer you to the great information @JJ-Fullmer provided here: https://forums.fogproject.org/topic/12026/powershell-api-module (he might also be able to answer the question more thoroughly)

    If there is really something missing in the API itself you guys just need to call out for us to fix this.

    Thank you, Sebastian.

  • Senior Developer

    @Jamaal I have not used the PowerShell stuff myself yet and so I can only refer you to the great information @JJ-Fullmer provided here: https://forums.fogproject.org/topic/12026/powershell-api-module (he might also be able to answer the question more thoroughly)

    If there is really something missing in the API itself you guys just need to call out for us to fix this.

334
Online

7.7k
Users

14.7k
Topics

138.5k
Posts