Create folders from a Textbox - Windows Form

Miguel Cuba 21 Reputation points

Hello Everyone,
I am hoping you can help me with the following error. I am trying to create folders name in each Line of the TextBox.
The Windows Form opens, and the Button works, but I am not sure why it is not creating folders in the specific location.
If the textbox contains:

I would like 3 folders be created with those names.
I hope you can help me
Thank you

# Load required assemblies
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

# Drawing form and controls
$CreateFolder = New-Object System.Windows.Forms.Form
    $CreateFolder.Text = "Create Folder"
    $CreateFolder.Size = New-Object System.Drawing.Size(800,400)
    $CreateFolder.FormBorderStyle = "FixedDialog"
    $CreateFolder.TopMost = $true
    $CreateFolder.MaximizeBox = $false
    $CreateFolder.MinimizeBox = $false
    $CreateFolder.ControlBox = $true
    $CreateFolder.StartPosition = "CenterScreen"
    $CreateFolder.Font = "Segoe UI"

# Inputbox    
    $Inputbox = New-Object System.Windows.Forms.TextBox
    $Inputbox.Multiline = $True;
    $Inputbox.Location = New-Object System.Drawing.Size(20,50)
    $Inputbox.Size = New-Object System.Drawing.Size(300,200)
    $Inputbox.ScrollBars = "Vertical"
    $Inputbox = $Folders

# adding a label to my form
$label_message = New-Object System.Windows.Forms.Label
    $label_message.Location = New-Object System.Drawing.Size(8,8)
    $label_message.Size = New-Object System.Drawing.Size(240,32)
    $label_message.TextAlign = "MiddleCenter"
    $label_message.Text = "Create Folders!!"

Set-Location "c:\Users\miguel\Desktop"
New-Item eMail -type directory
Set-Location "c:\Users\miguel\Desktop\eMail"

# add a button
$button_ClickMe = New-Object System.Windows.Forms.Button
    $button_ClickMe.Location = New-Object System.Drawing.Size(350,80)
    $button_ClickMe.Size = New-Object System.Drawing.Size(240,32)
    $button_ClickMe.TextAlign = "MiddleCenter"
    $button_ClickMe.Text = "Create Folders Now!!!"
        $button_ClickMe.Text = "Folders were created"
        ForEach ($Folder in $Folders) {
            New-Item $Folder.Name -type directory

# show form
[void] $CreateFolder.ShowDialog()
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,856 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Miguel Cuba 21 Reputation points

    That help!
    Thank you

    0 comments No comments