Using CSS with Powershell Output: A Step Up in Styling

Recently, I've been experimenting with the powershell functions "Convertto-HTML" and ConvertTo-EnhancedHTML (a downloadable module). While searching online, I stumbled upon a visually appealing table template that utilizes CSS and Angular. Unfortunately, my expertise in CSS and Angular is limited, so I am seeking assistance to properly format the output.
By using

Get-IAMUserList | Select Username, PasswordLastUsed, UserID |ConvertTo-Html -PreContent "<h2>User List</h2>"|Out-File report.htm

The produced result is a simplistic HTML table (excluding the header).

<body>
<h2>User List</h2>
<table>
<colgroup><col/><col/><col/></colgroup>
<tr><th>UserName</th><th>PasswordLastUsed</th><th>UserId</th></tr>
<tr><td>Joe</td><td>1/3/2020 4:36:24 PM</td><td>IPNB63</td></tr>
<tr><td>Sally</td><td>1/1/0001 12:00:00 AM</td><td>GRUIF</td></tr>
<tr><td>Joe</td><td>1/1/0001 12:00:00 AM</td><td>JI4H</td></tr>
<tr><td>user</td><td>1/1/0001 12:00:00 AM</td><td>Z4PM2</td></tr>
</table>
</body>

I'm interested in incorporating the code from this website for styling the data. It serves as a great example and template. Any guidance or support would be highly appreciated. Here is the link --Link to Code

To clarify - I have researched numerous CSS examples for displaying powershell output and tried several of them. Many are straightforward and allow me to format my data adequately. However, I am drawn to the more advanced designs showcased in the provided link but lack the understanding of CSS/JS required to implement them effectively. Thank you for any assistance!

Answer №1

If you're looking to think outside the box with ConvertTo-Html and want some custom formatting, then manual CSS creation is required for that extra touch. Alternatively, if you prefer using your own CSS styles (especially for a static table where JavaScript isn't necessary), one simple approach would be to construct the table yourself.

Here's how I do it:

$UserList = Get-IAMUserList | Select Username, PasswordLastUsed, UserID

$HTMLHead = @'
<!DOCTYPE html>
<html>
<head>
    <title>Table</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.2.0/sandstone/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <h2>User List</h2>

  <table class="table table-bordered table-striped">  
    <thead>
      <tr>
        <td>
          <a href="#">UserName</a>
        </td>
        <td>
          <a href="#">PasswordLastUsed</a>
        </td>
        <td>
          <a href="#">UserId</a>
        </td>
      </tr>
    </thead>
    <tbody>
'@

$HTMLRow = @'
      <tr>
        <td>{{UserName}}</td>
        <td>{{PasswordLastUsed}}</td>
        <td>{{UserId}}</td>
      </tr>
'@

$HTMLFoot = @'
    </tbody>
  </table>
</div>
</body>
</html>
'@

$HTMLTable = ''

$UserList | ForEach-Object {
    $Row = $HTMLRow.Replace('{{UserName}}', $_.UserName)
    $Row = $Row.Replace('{{PasswordLastUsed}}', $_.PasswordLastUsed)
    $Row = $Row.Replace('{{UserId}}', $_.UserId)

    $HTMLTable += $Row
}

#Compile everything together
$HTMLOut = $HTMLHead + $HTMLTable + $HTMLFoot

$HTMLOut | Out-File report.htm

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an interactive website with the functionalities of a blog by combining AngularJS with Middleman

I am looking to develop a single-page application that showcases similar entries, each containing pictures and descriptions. (I want to keep the process as simple as possible without relying on a graphical user interface.) Based on my understanding, I bel ...

Updating the image source using JQuery dynamically

Within my index.php file: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('.on').click(function ...

How can you extract the text associated with the chosen value in a dropdown list implemented in JavaScript?

Hello, I've been having difficulty extracting the value from a dropdown list created using the FacetWP plugin. Despite extensive research and numerous attempts using various methods to retrieve the text value from the list, I have not been successful. ...

Tips for preserving the contents of a list with HTML and Javascript

My latest project involves creating a website with a To-Do list feature. Users should be able to add and delete items from the list, which I achieved using JavaScript. Now, my next goal is to ensure that the current items on the list are saved when the pag ...

Storing passwords in a text file using PHP

Even though I understand that storing passwords in a text file is not the most secure method, please note that security is not my main concern here. This is more of a hackme website scenario. Currently, I have an array where usernames and passwords are st ...

Container slide-show fill error

I'm attempting to create a slide show with an overlapping caption that appears when hovering over the container or image. The image needs to fit exactly inside the container so no scroll bar is shown and the border radius is correct. I managed to achi ...

Transition from the previous image to the new one with a fading effect to enhance list item navigation

I've been working on implementing a sprite image for each list item (home, services, and contact) in my project. Using CSS, I've managed to move the position on hover successfully. However, I now want to add a fade effect to the transition instea ...

collaborating with complex structures within an object

This question may seem simple, but despite my efforts to search through Google and other resources, I can't seem to find the answer. My array of objects looks like this: const myArr = [ [{ id: 1, price: 200, }, { ...

Different perspectives displayed simultaneously on a single page, achieved without the need for routes

On my page, users have the ability to sort items using various filters. When the filter is set to Newest, the items are simply listed by name. But when the filter is set to By collection, the items within a specific collection are displayed under that col ...

Choosing the perfect gradient shade for a progress bar canvas illustration: Tips and tricks

I am trying to customize the appearance of the usage bar in my Google Chrome extension by utilizing the features of the HTML5 canvas. Currently, the bar consists of a basic DIV element: <div id="idUsgBar"></div> accompanied by this CSS stylin ...

Prevent any sliding animations of content when the button is triggered

I've implemented a basic slideToggle functionality in jQuery. You can check out the code on JSFiddle here: $(document).ready(function() { $(".panel_button").on('click', function() { $(".panel").slideUp(); var targetPanel = $(thi ...

Display or conceal elements using Jquery based on radio button selection

Recently delved into JQuery and encountered a frustrating issue that I can't seem to resolve. I'm certain it's a simple fix, but despite researching similar questions with solutions, I'm still stuck... The problem arises when attemptin ...

Adding a gradient to enhance an SVG chart

Hey there! I'm currently experimenting with Plotly to create some awesome charts, and I've been trying to figure out how to give my area-charts a gradient instead of the usual fill with opacity. This is how I typically build my graph: Plotly.ne ...

How to Create a Dynamic CSS Mobile Menu Animation

After checking out some online tutorials, I managed to get a hamburger menu working. However, I encountered an issue with the X icon not being symmetrical after the animation from 3 bars to an X. Here is the comparison: Before: https://gyazo.com/351864d8 ...

I am receiving a 401 error when attempting to verify the token following a successful login

I've been working on a small project utilizing VueJS, Vue Router, and Laravel for the backend. Despite several attempts, I haven't been successful in implementing navigation guards. My login component is functioning properly. Here's my log ...

Is it possible to adjust a single element within a class without affecting the rest using CSS?

Currently, I am facing an issue where my jQuery and JavaScript code is affecting all instances of messageCase when I only want to target and expand one specific instance. How can I modify my code to achieve this without impacting every occurrence of messag ...

Transform form array elements into JSON format using solely JavaScript or other client-side libraries

Currently, I'm developing a Joomla component and facing some issues with the serialization of my form data. To address this, my plan is to create a hidden textarea. This textarea will be populated with the JSON data generated as the form is filled out ...

How can I use PHP to send the user to another PHP file?

After searching for answers with no luck, I ended up coming here to ask my question. Here is the code snippet in question : <a href="manage/10000' . $user["user_id"] . ' " class="user_grop">More Info</span></a> I am wondering ...

Retrieving the special attribute value from a div element

When running the following command: console.log(document.getElementById('container')); The output is as follows: <div id="container" prjid="ABCDE">...</div> But why does the next command: console.log(document.getElementById(&a ...

Ways to determine if a date matches today's date within a component template

I am currently displaying a list of news articles on the webpage and I want to show the word "Today" if the news article's date is equal to today's date. Otherwise, I want to display the full date on the page. Is there a way to compare the news.D ...