We help IT Professionals succeed at work.
Get Started

Query for first name and add to powershell forms string

Mase2k asked
Last Modified: 2019-12-18
I am trying to figure out how to query for Active Directory Display Name and then enter it into the string below where you see (Insert first name here). This is a Powershell script which I am running to announce to users that their application is launching. Trying to personalize the popup. Everything works with the exception of the users name appearing.

Function Generate-Form {
    Add-Type -AssemblyName System.Windows.Forms    
    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = "Session is loading . . . "
    $objForm.Size = New-Object System.Drawing.Size(400,400)
    $Icon = [system.drawing.icon]::ExtractAssociatedIcon("C:\test.ico")
    $objForm.Icon = $Icon
    $objForm.MinimizeBox = $False
    $objForm.MaximizeBox = $False
    $objForm.WindowState = "Normal"
    $objForm.SizeGripStyle = "Hide"
    $objForm.ShowInTaskbar = $False
    $objForm.StartPosition = "CenterScreen"
    $objForm.BackColor = "#DF7A1C"
    $Font = New-Object System.Drawing.Font("Times New Roman",18,[System.Drawing.FontStyle]::Regular)
    $objForm.Font = $Font
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(40,40)
    $objLabel.Size = New-Object System.Drawing.Size(300,300)
    $objLabel.Text = "Hello (Insert first name here)! Please wait while your application is launching.

This box will close automatically."
    $objForm.Show()| Out-Null
    Start-Sleep -Seconds 5
    $objForm.Close() | Out-Null
Watch Question
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE