Universal Dashboard is a web framework for PowerShell. You can download it from the PowerShell Gallery.

Universal Dashboard provides the ability to create user input forms using the New-UDInput cmdlet. In this post we will look at how to create a form that allows the user to upload a CSV file and process it within PowerShell.

UDInput Basics

New-UDInput has two different ways of functioning. The first is to use a param block to define an input form directly from the PowerShell script you specify.
In the below example, I can create a basic for that accepts a couple different fields.

New-UDInput -Title 'New User Form' -Endpoint {
    param(
        $FirstName,
        $LastName,
        $UserName
    )

    New-ADUser -GivenName $FirstName -Surname $LastName -Name $UserName
}

This script would produce the following form.

Form generated from param block

Although this type of form is easy to produce, it doesn’t provide the same level of customization as the -Content parameter of UDInput.

UDInput Content

The -Content parameter can be used in conjunction with the -Endpoint parameter to define the fields that show up in the form. You have more options when it comes to the type of form when using this method.

Instead of creating a form that accepts a single user, we may want a form that accepts a CSV and then creates many users. Just as with the basic form, you’ll still need to provide an -Endpoint script block for processing the input data. Unlike the basic form, the actual field definitions come from the -Content block rather than the param block in the Endpoint script block.

New-UDInput -Title 'Bulk Import User Form' -Content {
    New-UDInputField -Type file -Name users 
} -Endpoint {
    param($users)

    $UserObjects = $users | ConvertFrom-Csv

    $UserObjects | ForEach-Object {
        New-ADUser -GivenName $_.FirstName -Surname $_.LastName -Name $_.UserName
    }

    Show-UDToast -Message "Created $($UserObjects.Length) users"
}

This will produce a form like this.

Form created with Content and New-UDInputField

After uploading a file, the users will be created in Active Directory and a toast will be shown to the end user.

Uploading a CSV to New-UDInput

Conclusion

In this post we went through how to upload and process a CSV using New-UDInput. Using the -Content parameter you have more control over the types of input controls that you can use in your dashboards.