• @jj-fullmer or someone also that’s working on API

    Hello, all,parameter not recognized.PNG

    Thanks for the fog api notes, appreciate you helping us out. I’m not sure if you remembered me, but have a few questions.

    I’m trying to do 2 things. One to assign a group to a machine one created in fog via powershell. I tried get-foggroupbyname, but says the parameter is not recognized.parameter not recognized.

    It then told me to go to c:\program files… until I got to fogapi.psm1

    I copied and pasted the command for cmdletBinding.

    It didn’t error out, but didn’t return anything. Ex; , I know I created a Sales group in the Fog Gui with snapins assigned to it, so I wanted the machine to be assigned to that group to make it more dynamic. Please see attached pics. I’ll keep trying as well on my side. I’m so so on Powershell, but came a long way.parameter

  • Testers

    @Jamaal
    @jj-fullmer said in fog API powershell help:

    Glad I had the code for get-foggroups somewhere to be found. It looks like something weird happened to the get-foggroups function and all the code disappeared from it. I’ll need to get that fixed as soon as I can as that function is used all over the place. I have made an issue for it https://github.com/darksidemilk/FogApi/issues/3

    I just published a new version of the module fixing the issue with get-foggroups and subsequently get-foggroupsbyname if you update to the new version 2103.2.12 those functions should work now.


  • @jj-fullmer said in fog API powershell help:

    $snapinsToRemove = @(‘snapin’,‘names’,‘here’);

    That’s what I needed, an array to choose from a list. Thank you so much! Really appreciate you on helping me on this.

  • Testers

    @jamaal I created my own infrastructure to handle this. It was not a simple process, but it works pretty well.
    I have what I call profile packages for each department, we use chocolatey for that and each one has a snapin.
    I have a powershell module for provisioning. I use sysprep/unattend firstlogoncommands to trigger its start and then it goes through a series of commands and restarts amongst that I have it use the api to get the fog group a host is in and then it adds the associated snapin that I associate through code and file structure.
    Once you get that far you can add a list of snapins to a host, deploy them, and then remove them (so the host remains ready to be deployed in a different department without having to remove old snapins) all with the api.

    Check out

    #create a list/array of the snapins you want to remove
    $snapinsToRemove = @('snapin','names','here'); 
    
    #get all the snapin associaion objects
    $AllAssocs = (Get-FogObject -type object -coreObject snapinassociation).snapinassociations
    
    # Get the snapins associated with your host
    $AllHostSnapins = Get-FogAssociatedSnapins -hostId $hostID;
    
    #get the ids of the snapins you want to remove, from the list of snapins attached to your host.
    $snapinIds = ($AllHostSnapins | Where-Object name -in $snapinsToRemove).id
    
    #Get a list of the snapinassociation ids that match your host id and are in the list of snapin ids attached to your host
    $assocsToRemove = $allAssocs | Where-Object { $_.hostID -eq $hostID -AND $_.snapinID -in $snapinIds}
    
    # loop through the found associations and remove them
    $assocsToRemove | ForEach-Object {
        Remove-FogObject -type object -coreObject snapinassociation -IDofObject $_.id;
    }
    

    I believe there is also a fog plugin for persistent groups that can do more of what you describe natively in fog.

    Granted, I will need to get the get-foggroups function fixed for some of this to work properly. Maybe I’ll have some time this weekend.


  • @jj-fullmer said in fog API powershell help:

    @jamaal I have a function for inventory here https://fogapi.readthedocs.io/en/latest/commands/Get-FogInventory/
    It gets the same inventory information via powershell and adds it to fog.
    I can also help you with queuing the native inventory task, but that might be a bit trickier. I think you can schedule more than one task for a machine when it’s a scheduled task, but I’m not sure.

    Glad I had the code for get-foggroups somewhere to be found. It looks like something weird happened to the get-foggroups function and all the code disappeared from it. I’ll need to get that fixed as soon as I can as that function is used all over the place. I have made an issue for it https://github.com/darksidemilk/FogApi/issues/3

    Thanks jj, appreciate it. And another question. So I read in the fog forums and also the general fog page that snapins for groups don’t function, correct? I created a group called sales and when I added snapins to it, they never stayed. I then started reading up on it and said the groups only serve mostly as a category for naming& imaging purposes.

    It would be create if there was a way to add snapins to groups so when the other technicians use Microsoft Forms for example, they select which group the pc will go to and then the pc will automatically have all the snapins.

    If somehow that gets done in future, please let me know. Or do you know of a powershell command to add multiple snapins at once? Ex; the tech would click on the checkbox on Microsoft Form for more than one snapin, so I need to create a powershell statement to group more than one snapin.

  • Testers

    @jamaal I have a function for inventory here https://fogapi.readthedocs.io/en/latest/commands/Get-FogInventory/
    It gets the same inventory information via powershell and adds it to fog.
    I can also help you with queuing the native inventory task, but that might be a bit trickier. I think you can schedule more than one task for a machine when it’s a scheduled task, but I’m not sure.

    Glad I had the code for get-foggroups somewhere to be found. It looks like something weird happened to the get-foggroups function and all the code disappeared from it. I’ll need to get that fixed as soon as I can as that function is used all over the place. I have made an issue for it https://github.com/darksidemilk/FogApi/issues/3


  • Ok, I think I got this figured out just now.
    Thanks to you jj, I followed your example from your original link:

    https://forums.fogproject.org/topic/12026/powershell-api-module/11

    So far I got this to work on one host: Here’s what I did by using your script:

    $newAssocs = New-Object System.Collections.Generic.List[object];
    $computer = (get-foghost -hostname “itloaner”).id
    $groups = (get-fogobject -type object -coreobject group).groups | where-object name -eq “sales”
    $groupAssocs = Get-FogObject -Type Object -CoreObject groupassociation

    $json = @{
    “hostID”=$computer;
    “groupID”="$($groups.id)";
    } | ConvertTo-Json;
    # Note, when creating the json splat and then piping it to convertto-json you must encapsulate properties and values in quotes and match the case of the original property (i.e. ID instead of Id) as in this example or it won’t parse right and will return a 417 error from the api

    $result = New-FogObject -type object -coreObject groupassociation -jsonData $json;
    $NewAssocs.Add($result);

    #list the newassocs that added the laptops to your group
    $NewAssocs;

    It then showed up as it added as per the results attached in this message.test1.PNG

    For further proof, I went to my test host and verified it was added via the new-fogobject command. I’m starting to understand now how this works. I just need to keep playing around with it and should be good going forward.

    My next task is to try to create a task via powershell to get the inventory of the machine before deploying the image. If you know of any commands, please let me know and I’ll keep trying myself as well.

    Again thanks for the info.

282
Online

8.2k
Users

15.1k
Topics

141.9k
Posts