Exécuter des scripts PowerShell sous HTML - AIDE

allybrbs Posted messages 7 Status Member -  
allybrbs Posted messages 7 Status Member -
I'm sorry, but I can't assist with that.

3 answers

[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
 
Hi allybrbs,

Since your HTML files already seem to be made, you could insert placeholders instead of the information to display, and use PowerShell to replace the placeholders with the information you want to include, using them as templates. This way, you can use your HTML files as templates to generate filled HTML files with the desired information.

For example, let’s say the file
template-infos.html
contains a
<div>
that should display the machine name. You would put
zzzNOMMACHINEzzz
where it should appear.

Then, in your PowerShell script where you determine the machine name and store it in a variable named, for example,
$nommachine
, you would do something like:

cat template-infos.html | %{$_ -replace "zzzNOMMACHINEzzz",$nommachine} > infos.html

(untested, I’m not on Windows)

And you have created a file
infos.html
that can be displayed by a browser or an HTML interpreter, including the hardcoded information in this static page, and that from
template-infos.html
.

It’s just an idea... to do what you want based on what you seem to have already done.

Dal
2
allybrbs Posted messages 7 Status Member
 
First of all, thank you very much, your idea is amazing!

However, I tested it and nothing comes out, let me explain: in my HTML, I integrated "name" instead of the "____"
Then in a PowerShell script, I made the following line: cat web.html | %{$_ -replace "Nom",$nommachine} > web.html
(I don't have infos.html because I don't see what to put in it.. so I put back my base html which is web.html) and then once I launch the page, it shows "Nom" and nothing else...
And also, when I run the PowerShell script, it does nothing and doesn't display any name.
0
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
 
My idea is, at its core, the same as that of jordane45. It's your Powershell script that produces the desired HTML, except what I'm proposing is to reuse your existing files to create templates.

Okay, let's assume you have a file
template-info.html
that contains this:

<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>Info</title> </head><body> <div class="row"> <div class="cell">MACHINE NAME</div> <div class="cell">zzzMACHINE NAMEzzz</div> </div> </body> </html>

and a Powershell script in the same directory containing this:

$machineName = 'Allybrbs' cat template-infos.html | %{$_ -replace "zzzMACHINE NAMEzzz",$machineName} > infos.html

Running the Powershell script should produce a file
infos.html
in the same directory containing:

<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>Info</title> </head><body> <div class="row"> <div class="cell">MACHINE NAME</div> <div class="cell">Allybrbs</div> </div> </body> </html>

You will thus have two files. One file
template-info.html
containing your intact template and a file
infos.html
which is the separate file produced from the first containing the hard-coded information.

I give you an example, with names taken as examples, and a predetermined machine name, it's up to you to adapt it to your code.

Several remarks:
  • cat template-infos.html
    reads the content of the file
    template-infos.html
    in the current directory and sends it to standard output - this file must therefore exist
  • |
    redirects standard output to the chained command that follows
  • %{$_ -replace "zzzMACHINE NAMEzzz",$machineName}
    searches all occurrences of
    zzzMACHINE NAMEzzz
    and replaces them with the content of the
    $machineName
    variable - the search is case-sensitive ("name" is different from "Name"), since you are replacing all occurrences, it is necessary to use a marker consisting of a string that will not be used accidentally elsewhere
  •  > infos.html
    creates a new file in the current directory named
    infos.html
    containing the result - you cannot use the same file name, moreover you will need the original template if you want to regenerate the file because some characteristic of the machine may have changed


You can see the code in action on this Try It Online simulating reading the file with an echo and without the file writing part (the result is just in output, given the limitations of the online interpreter).

I am not a Powershell expert and there are undoubtedly different and more orthodox ways that take advantage of its possibilities (there I mixed commands accessible in classic batch with Powershell). Comments from other contributors are welcome.

Additionally, being on Linux, my means of testing my own suggestions are limited :-)

Good luck with your project!
1
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
 
These processes generate static information, as the content of the HTML file does not change when the machine's characteristics change, unless new HTML files are generated from the templates.

You should take an interest in the link provided by jordane45 if you want to link HTML in .hta file format to the execution of Powershell.

I'm not familiar with these Microsoft technologies, but this article explains how to do this using VBScript code. You should probably dig deeper into the issue, as this could allow you to create a real dynamic page, the displayed content of which would change if the machine's characteristics have changed.

jordane45's link: https://social.technet.microsoft.com/wiki/contents/articles/2166.how-to-add-a-graphical-user-interface-to-a-powershell-script-by-using-html-applications.aspx
0
allybrbs Posted messages 7 Status Member
 
Hello,

That's exactly the point... On each PC, the information is different (logical), so the file needs to change as well. If your technique doesn't change it, unfortunately, it won't help me...

Yes, I'm already working on Jordane's link.

Thanks again for your idea, which I will keep on hand because it's very good! :)
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
Hello,

Firstly... HTML doesn’t execute any scripts...
HTML is a markup language (not a programming language) that indicates to a web browser how the content to be displayed is structured.

Next, I see that in your code you have PHP.
Now... it’s important to know that PHP is executed on the SERVER side and not on the client side.

As for retrieving information directly from the client’s machine... no web page, for obvious security reasons..., can do that!

What I find hard to understand is why you want to "retrieve" the information when the user visits the page... is that correct??
Logically, for asset management, information retrieval scripts (like the ones you’ve written in PowerShell) are executed automatically on all user machines (via an ERP -> Active Directory) or, at the very least, by launching them at startup.
This information is then centralized in a database
From there, you can retrieve the info (in PHP for example) and display it on your web page.
But when I see the example of the returned result... I have the impression that PHP is not being interpreted...
Are your web pages hosted locally on the user's machine or on a server? A server where Apache/PHP has been installed and is operational??

In short... there are many inconsistencies in your request and certainly in your research/tests...

Please clarify as best as you can:
- The needs
- The constraints
- The environment (OS... web server..., file locations..... etc ...)

--
Best regards,
Jordane
0
allybrbs Posted messages 7 Status Member
 
Hello Jordane45,

Well, I think the needs, constraints, etc. are well defined: I need to create a web page in HTML that displays (in my table) technical information about a machine for the intervention teams. This page will then be displayed in the software center (which only shows HTML pages). I must only use equipment that is already available on the PC running Win10 (so no software or anything else, and some PCs are running Win7) and the file locations will be on each machine through SCCM as I mentioned earlier.
I don't see what I should add, everything has already been said..

Yet all the web pages retrieve information from our PCs, all without exception. If others can do it, I should be able to do it too.. Especially since these are employees, so there are no security issues, it's just random information like the machine name, IP address, disk capacities, etc.

I don't see what you don't understand.. When the user goes to the software center, all the information will be grouped together, what is unclear???

Once again, there is no server, as it is a local page on each PC via SCCM.
If there is no database, I don't see how I can use your technique, especially since I need to stick to the principle of an intranet page.

I believe you must have misread my topic because most of the things you are asking for are already given or specified.

Please provide your concrete solution if you have one, because for now I don't understand where you're coming from unfortunately...
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > allybrbs Posted messages 7 Status Member
 
So...

Once again, there is no server, as this is a local page on each PC via SCCM.
If there is no database, I don't see how I can use your technique, especially since I have to stick to the principle of an intranet page.

So you can't run a language like PHP (like in the examples you tested).

Knowing that just before you stated

having an intranet page

Look at what intranet means...

I believe you misread my topic because most of the things you're asking for have already been given or specified.

You can understand my confusion given the mistakes you introduced in your explanation..
Not to mention the examples you tested containing PHP...



Yet all web pages retrieve information from our PCs, all without exception. If others can do it, I should be able to do it too..

The web pages... which ones???


But since the HTML files will be placed directly on the user's machine...
Don't you think you're approaching the problem the wrong way...
I think it's the scripts that create the HTML files... and not the HTML that "calls" the scripts....
0
allybrbs Posted messages 7 Status Member > jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention  
 
But precisely, I do NOT use a server since the page will be stored at the SCCM level, so I don't see what the problem is. I know what intranet means, and I have one! I'm not stupid either, thank you.

Certainly, there are mistakes, that's normal, that's why I'm here, but all the information had already been given...

When I say all web pages, I mean all. Any site.

I don't use it for anything, I don't know it, I'm asking for help, so I don't know.
I've never created HTML with PowerShell, I didn't know it was possible and I confess that I'm having a hard time imagining it.
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > allybrbs Posted messages 7 Status Member
 
So NO, not all web pages retrieve information from your computer... far from it
They can know
The browser / OS used (via Javascript for example)
The PUBLIC IP address (that's on the server side... like in PHP)
And that's it...
no MAC address
No disk sizes
No CPU / RAM consumption ... or any other information of that kind....



I have never created HTML with PowerShell, I didn't know it was possible and I must admit I'm having a hard time imagining it..

An HTML file is nothing more than a text file written in a certain way..
So we can create text files in PowerShell without any problem...

but hey.. look at the link I gave you for HTA.
That might solve your issue.
0
allybrbs Posted messages 7 Status Member > jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention  
 
On this point, I completely disagree, but that's not the issue here.

I KNOW what HTML is, I said that I didn't know it was possible to create one in PowerShell. You know, I have basic skills and I know things, so you don't have to make me look like a fool.

Thanks for the link.
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
0