Invoke hostinfo.php from powershell
-
Hi togehter,
i got a lot of informations here in the forum about the post installation scripts and so on.
I need to run a powershell script after deployment. In this script i try to get the host informations from fog:
Invoke-WebRequest http://${web}service/hostinfo.php?mac=$mac
But all i get is:
StatusCode : 200
StatusDescription : OK
Content : “Cannot view from browser”or without a user agent
Invoke-WebRequest -UserAgent “”StatusCode : 200
StatusDescription : OK
Content : Invalid tasking!I researched the hostinfo.php and there is something with the User Agent but i don’t know exactly what?
Is anybody able to help me out with this.
Thanks so much for this good work,
R,
Andreas -
The first message you saw is 100% correct. You did the -UserAgent “” already and found the other part.
This “hostinfo” is designed to only be used for hosts in a task, otherwise anybody could request information otherwise (especially considering it can contain information that could compromise your network).
If you need to get data, the host needs to be in a “tasking”.
-
You could also just query the fog database directly using the fogstorage credentials.
-
@andreas.paul said in Invoke hostinfo.php from powershell:
Invoke-WebRequest http://${web}service/hostinfo.php?mac=$mac
Just be aware that in your url you have embedded php variables which may really confuse powershell.
Invoke-WebRequest http://${web}service/hostinfo.php?mac=$mac
The ${web} variable represents the FOG server url of “
<fog_server_ip>/fog
”and
$mac
is the mac address of the target computer. You need to replace these with real literal strings.Such as
Invoke-WebRequest http://192.168.1.22/fog/service/hostinfo.php?mac=00:08:12:34:56:78
to make the url correct. -
Hi,
thanks for the quick response.
@Wayne-Workman
Im intrested in the option to query the database direct, do you have any snipped for this?@Tom-Elliott
It means if i “wrap” my script in a snapin i have access to the hostinfo because the host ist running a snapin task?R,
Andreas
-
@andreas.paul I’d have to look at the code, but theoretically yes.
-
Looked it over, and that seems correct.
-
Hi,
yes it works,
but not all fields ar filled with values:
[[ -z $primaryuser ]] && export primaryuser=‘’
[[ -z $othertag ]] && export othertag=‘’
[[ -z $othertag1 ]] && export othertag1=‘’I have set a primaryuser but it is not shown.
By the way,
Do you plan to create a REST api ore something else?R,
Andreas
-
@andreas.paul I can say for fog 1.x.x there are no plans for an REST api. With FOG 2.x (still a while off) there will be a lot more options since its reported that FOG 2.x may be using node.js for ist structure.
The intent of the hostinfo.php is to build a bash script that can be executed on the target computer for scripting, and not really how you are intending to use it. I’m not saying that you can’t work with it. You will just need to discard everything to the left of the space after the export tag.
-
@andreas.paul Confirmed that primary user is not passed to hostinfo.php
[[ -z $imagepath ]] && export imagepath='WIN10_ENT_X64' [[ -z $primaryuser ]] && export primaryuser='' [[ -z $othertag ]] && export othertag='tag1' [[ -z $othertag1 ]] && export othertag1='tag2' [[ -z $sysman ]] && export sysman='VMware, Inc.'
Primary user should list “JimBob” and not blank.
FOG version used 1.3.4 -
Fixed for 1.3.5 working branch.
I’m working on issues with logical/extended partitions right now.
I can tell you all, I hate partitioning scheme maths.
-
@Tom-Elliott said in Invoke hostinfo.php from powershell:
Fixed for 1.3.5 working branch.
I can tell you all, I hate partitioning scheme maths.Simple
p1 + p2 = (square root of infinity). That way it always fits.
-
Hi,
thanks for fixing.
if i do a git pull witch version i will have, current is: “1.3.5-RC-10” is this the working branch?
Because if it is it will not work :-(.
And good look with your math study I think i know what you try to to its the same shit as you try to mount the 5 extended partition in a dd file via loop, it’s crap.
R,
Andreas
-
@andreas.paul There is a development branch (i.e. pre RC11) where the fix lives. Let me check to see if the fix can be back ported to RC10.
-
@andreas.paul I sent you a DM (little talk bubble on the fog tool bar).
-
@andreas.paul said in Invoke hostinfo.php from powershell:
Im intrested in the option to query the database direct, do you have any snipped for this?
I’ve only done it with BASH, it’s easy in bash. Here’s an article about doing it in powershell. All I did was google-search “powershell query mysql” and there’s tons of results.
http://www.thomasmaurer.ch/2011/04/powershell-run-mysql-querys-with-powershell/