Is it possible to pass variables to snapins?
-
I have a snapin (pwoershell template) that I would like to run with an argument pulled from the host’s inventory (PrimaryUser field). Is this possible? Am I just too crazy?
Man it would be cool if it can do this. I don’t know much about snapins though :S
-
@szeraax said in Is it possible to pass variables to snapins?:
Is this possible?
Yes but not the way you’re thinking. FOG has an API, so from your powershell script just call the API and get the info you need for the host the script is running on.
-
Can you link me to that API? or maybe an example line of calling it? Is it just rest?
-
First result from Google: https://forums.fogproject.org/topic/11184/api-powershell-create-host-and-deploy-task-script probably should do more reading before I ask you follow up questions.
-
@szeraax This is the link: https://news.fogproject.org/simplified-api-documentation/
Right now, news.fogproject.org is broke. I’ve messaged our senior devs and they should get it fixed relatively quick.You may also look at this entire thread, as it deals heavily with the API: https://forums.fogproject.org/topic/9779/can-i-use-some-kind-of-script-to-create-image-and-ghost-my-lab-machines
-
Am able to see the cached version, looks pretty easy. I’ll play and mark solved or follow up if I get stuck. Thanks a ton!
-
@szeraax Also so you’re aware, I vaguely remember a way to pass arguments directly into the snapin itself. This may be cleaner for you, maybe not. Search around in the forums and you’ll probably find it. I think the post is made by the user @joe-schmitt He’s the guy that made the new fog client.
-
So it looks like the API works great for what I need. But how do I mark as solved? I can’t find anything that lets me change this status
My code from the api is something similar to:
$fogApiToken = 'mf...A=' $fogUserToken = '5Mz...NDY=' $fogServer = "IP ADDRESS GOES HERE" $headers = @{}; $headers.Add('fog-api-token', $fogApiToken); $headers.Add('fog-user-token', $fogUserToken); $BaseUri = "http://$fogServer/fog" $HostURL = $baseUri +"/host/" $HostResult = Invoke-RestMethod -Uri $HostURL -Method GET -Headers $headers -ContentType "application/json" $ThisHost = $HostResult.hosts | ? name -eq $ENV:COMPUTERNAME $PrimaryUser = $ThisHost.Inventory.PrimaryUser.Trim()