pop-up in a powershell script

Welcome Forums General PowerShell Q&A pop-up in a powershell script

This topic contains 3 replies, has 4 voices, and was last updated by

2 years, 11 months ago.

  • Author
  • #43154

    Topics: 8
    Replies: 8
    Points: 0
    Rank: Member

    Hello fellow powershell admins/users,

    i'm learning powershell now for like 3 months and also begon with building scripts.
    now i whant to create a script, (i think it is a simple one) it is onky one line

    Get-WMIObject Win32_UserProfile | ? {$_.localpath –like “*username*"} | Remove-Wm
    iObject -whatif

    but my question now is where is, is it to let say, when you run the script that it pops uo and you'll need to fill in wich username ?

  • #43160

    Topics: 4
    Replies: 10
    Points: 0
    Rank: Member

    Hi Jeremy,

    There are a few ways you can accomplish this. One quick way is to pipe all the results to Out-GridView with the -PassThru switch. This will send the items you choose down the pipeline (to Remove-WmiObject in your case)...

    Get-WmiObject win32_userprofile | Out-GridView -PassThru | Remove-WmiObject

    Another route would be to turn this into a function and use a dynamic parameter to validate your set of usernames. Dynamic parameters are a bit advanced with not a whole lot of examples out there. Here is one that got me going: https://blogs.technet.microsoft.com/pstips/2014/06/09/dynamic-validateset-in-a-dynamic-parameter/

    Hope this help!

  • #43162

    Topics: 0
    Replies: 3
    Points: 0
    Rank: Member

    Something like this:

    function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
        Add-Type -AssemblyName Microsoft.VisualBasic
        return [Microsoft.VisualBasic.Interaction]::InputBox($Message, $WindowTitle, $DefaultText)
    $username = Read-InputBoxDialog -Message "Please enter the username" -WindowTitle "Enter a USername"
    if ($username -eq $null) { Write-Host "You clicked Cancel" }
    else { Get-WMIObject Win32_UserProfile | ? {$_.localpath –like "$username"} | Remove-WmiObject -whatif }

    Taken from: http://blog.danskingdom.com/powershell-multi-line-input-box-dialog-open-file-dialog-folder-browser-dialog-input-box-and-message-box/

  • #43501

    Topics: 6
    Replies: 652
    Points: 11
    Rank: Member

    If you just need to get user input and don't necessarily need a "Pop-up" window. You can prompt for input at the prompt using read-host

    $username = Read-Host "Enter target profile username"
    Get-WmiObject Win32_UserProfile | Where-Object {$_.localpath -like "*$username*"} | Remove-WmiObject -WhatIf

The topic ‘pop-up in a powershell script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort