New to UD and trying to figure out some stuff

Hello, I’m new to UD and trying to figure out if a few things are possible with UD.

  1. Upload a file and pass it to another script/more code
    Something like this
    New-UDColumn -Size 3 { New-UDInput -Title "User Onboarding Tool" -Id "Form" -Content { New-UDInputField -Type 'file' -Name 'Upload' } -Endpoint { param($Upload) $File = Import-Excel $Upload } }

image
The idea with this one is to upload a file that gets passed to another tool or to more code.

  1. Take input and pass it to another script/more code
    Something like this
    New-UDColumn -Size 3 { New-UDInput -Title "Get User Information" -Id "DoesThisMatter" -Content { New-UDInputField -Type 'textbox' -Name 'Username' -Placeholder 'Username' } -Endpoint { param($Username) Show-UDModal -Content { Get-ADUser -Identity $Username | Select-Object Name,Department,Title } } }
    image
    Similar idea with this one but its input instead of a file.

so it aint working for you? as I see it, this should work.

Correct, currently it doesn’t do anything, errors out or crashes the site.

Welcome @mpolselli to the universal dashboard forums. Thanks for posting your question, and for providing some code…just so I can understand your exact problem…

You would like to be able to upload a file…say a CSV file for arguement sake…then you want to automatically do something with that CSV file…as in change the formatting, or run a macro?
Just want to clarify the issue then either myself or another member will be able to provide a solution. Thank you.

Thanks @psDevUK

Not quite, what I’d like to do is have a tech upload a file then pass that file onto either another PowerShell script or to use that file in additional code in the dashboard.

For example my current onboarding tool (powershell) accepts an excel spreadsheet and pulls data from the spreadsheet to fill variables within the tool.

The second scenario is to take input like a username for example, take that input and run some code against it, like Get-ADUser for example and then take that output and display it on the screen for the tech to see.

Does that make more sense?

1 Like

Thanks for clarifying the situation @mpolselli it does indeed make 100% sense what you are trying to achieve. I have done the second part, numerous times with pulling data back from SQL with either what the user has typed or what the user has selected.
I have not however ever thought about the first issue you are describing…having a quick think about it now, I am confident it would work, however the CSV or what-ever file you are uploading would need to be consistent…as in the layout is always the same, else you will get wonky results…I also see that you may need two buttons…one to upload the file…and one to process the file…I am curious about this now, so will do my best to knock up a demo of both of these scenarios :crazy_face:

1 Like

so what you are trying to accomplish is doing a bulk on board to AD and then query these IDs to view the on boarding results.

Thanks for clarifying the situation @mpolselli it does indeed make 100% sense what you are trying to achieve. I have done the second part, numerous times with pulling data back from SQL with either what the user has typed or what the user has selected.
I have not however ever thought about the first issue you are describing…having a quick think about it now, I am confident it would work, however the CSV or what-ever file you are uploading would need to be consistent…as in the layout is always the same, else you will get wonky results…I also see that you may need two buttons…one to upload the file…and one to process the file…I am curious about this now, so will do my best to knock up a demo of both of these scenarios

@psDevUK That would be awesome. I’ll try out adding a second button to process the form, I hadn’t thought of trying that. Also yes the layout is the same each time.

Currently the excel file is generated by extracting data out of a word file that HR submits to IT. The word doc has fillable forms so the layout and headers in the excel file are always consistent. That excel file is then used in a parameter for my onboarding tool eg. New-User -EmployeeFile JohnDoe.xlsx. I’m simply trying to move the use of the tool to UD as not all of the techs are comfortable with the command line.

As for the first part, trying to return output to the tech after they give a tool some input, would you have any guidance on that?

@wsl2001

so what you are trying to accomplish is doing a bulk on board to AD and then query these IDs to view the on boarding results.

Not quite, this would be for onboarding an individual user.

The second piece is a separate tool entirely used for querying existing users and returning useful information, such as password expiration, account status, lockout, etc.

To add some additional clarification, I have a Utilities module that is filled with separate tools from getting user information, adding users to VPN groups, offboarding users and so on. I am trying to move them to UD for ease of use.

@mpolselli

look at this page

the second example you can use to out to udgrid or table so the uploaded file will appear for the tech who did the upload.

also this vedio when you get to 40:53 you will see an example of uploading a file and the code needed in new-udinputfield -type file
https://www.youtube.com/watch?v=6nPGEIFqlXw

So this is the button upload…I created a file called DEMO.ps1 which was stored in my C:\UD\test location on my laptop…now when I run the script from the C:\UD\test folder, it makes that location the $Root varible…so whenever I upload any files, they are automatically copied to the $Root location and a toast is sent:-

Import-Module -Name UniversalDashboard.Community -RequiredVersion 2.8.1
Get-UDDashboard | Stop-UDDashboard
$Root = $PSScriptRoot
$Init = New-UDEndpointInitialization -Variable "Root"

Start-UDDashboard -Port 1000 -AutoReload -Dashboard (
    New-UDDashboard -Title "Powershell UniversalDashboard" -Content {
        New-UDLayout -Columns 3 -Content {
            New-UDInput -Title "Upload A File" -Content {
                New-UDInputField -Type binaryFile -Name file
            } -Endpoint {
                param($File)
                $fileStream = [IO.File]::Create($File.FileName)
                $stream = $File.OpenReadStream()
                $stream.CopyTo($fileStream)
                $fileStream.Dispose()
                $stream.Dispose()
                copy-item -Path $($File.FileName) -Destination $Root
                New-UDInputAction -Toast "Congratulations the attachment has now been uploaded" -Duration 5000
            }

        }
    } -EndpointInitialization $Init
)

So I created a simple two column CSV with the headings Name and Position

Name,Position
Adam,Manager
Rob,Tech
Jim,Cleaner
Fred,User
Susie,Admin

Then I fed that into my script like so:-

Import-Module -Name UniversalDashboard.Community -RequiredVersion 2.8.1
Get-UDDashboard | Stop-UDDashboard
$Root = $PSScriptRoot
$Init = New-UDEndpointInitialization -Variable "Root"

Start-UDDashboard -Port 1000 -AutoReload -Dashboard (
    New-UDDashboard -Title "Powershell UniversalDashboard" -Content {
        New-UDLayout -Columns 3 -Content {
            New-UDInput -Title "Upload A File" -Content {
                New-UDInputField -Type binaryFile -Name file
            } -Endpoint {
                param($File)
                $fileStream = [IO.File]::Create($File.FileName)
                $stream = $File.OpenReadStream()
                $stream.CopyTo($fileStream)
                $fileStream.Dispose()
                $stream.Dispose()
                copy-item -Path $($File.FileName) -Destination $Root
                $Session:csvFile = "$Root\$($File.FileName)"
                New-UDInputAction -Toast "Congratulations the attachment has now been uploaded" -Duration 5000
            }
            New-UdGrid -Title "Profiles" -DefaultSortColumn "Name" -Endpoint {
                if ($Session:csvFile -ne $null) {
                    Import-Csv $Session:csvFile | Select-Object Name, Position | Out-UDGridData
                }

            } -AutoRefresh
        }
    } -EndpointInitialization $Init
)

I added the file selected to be held in the session variable which is unique to UD, so read the document pages here https://docs.universaldashboard.io/endpoints/custom-variable-scopes#session-scope if you didn’t know about that handy variable.
Which then gives you this awesome dashboard which automatically processes the CSV file selected and displays it in a grid:-

To save me scripting up more stuff on my friday evening (as I got 4 kids and all) take a butchers at my page I uploaded here:-


this is a statistics page filling lots of different cards, and chart with the ID supplied in the input field…hopefully this will give you enough information to see how this is done…if not can knock another demo together…Anyways let me know if you need more info. Peace :sunglasses:

3 Likes

Awesome, thanks! I’ll definitely try and work on this some more and use your info.