Thank you for the response,
I made the changes you suggested, but the issue persists. There is one more new error:
Here are the Errors
Set-Location : Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.
At C:\APPS\Scripts\CreateFolder - Test.ps1:104 char:9
+ Set-Location $LabServer
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Location], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SetLocationCommand
New-Item : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\APPS\Scripts\CreateFolder - Test.ps1:111 char:22
+ New-Item $Folder -type directory
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.NewItemCommand
Thank you for all your help
Here is the full script:
# 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 Multiple Custodian Folders"
$CreateFolder.Size = New-Object System.Drawing.Size(350,415)
$CreateFolder.FormBorderStyle = "FixedDialog"
$CreateFolder.TopMost = $true
$CreateFolder.MaximizeBox = $false
$CreateFolder.MinimizeBox = $false
$CreateFolder.ControlBox = $true
$CreateFolder.StartPosition = "CenterScreen"
$CreateFolder.Font = "Segoe UI"
#======================== CASE NAME ========================#
# adding a label to my form
$label_message = New-Object System.Windows.Forms.Label
$label_message.Location = New-Object System.Drawing.Size(20,8)
$label_message.Size = New-Object System.Drawing.Size(100,15)
$label_message.Text = "Case Name"
$CreateFolder.Controls.Add($label_message)
# CaseName
$CaseName = New-Object System.Windows.Forms.TextBox
$CaseName.Location = New-Object System.Drawing.Size(20,30)
$CaseName.Size = New-Object System.Drawing.Size(300,25)
$CaseName.ScrollBars = "Vertical"
$CreateFolder.Controls.Add($CaseName)
#======================== DROPBOX ========================#
$label_messageCombobox = New-Object System.Windows.Forms.Label
$label_messageCombobox.Location = New-Object System.Drawing.Size(20,60)
$label_messageCombobox.Size = New-Object System.Drawing.Size(100,15)
$label_messageCombobox.Text = "Pick a Server"
$CreateFolder.Controls.Add($label_messageCombobox)
$DropdownBox = New-Object System.Windows.Forms.ComboBox
$DropdownBox.Location = New-Object System.Drawing.Size(20,80)
$DropdownBox.Size = New-Object System.Drawing.Size(300,15)
$DropdownBox.Height = 200
$Dropdownbox.DropDownStyle = "DropDownList"
$CreateFolder.Controls.Add($DropdownBox)
$Servers = @("Lab Machine 40","Lab Machine 45","Lab Machine 50","Lab Machine 55")
foreach($Server in $Servers){
$DropdownBox.Items.Add($Server)
}
Function Get-Server{
$SelectedServer = $DropdownBox.SelectedItem.ToString()
if($SelectedServer -eq "Lab Machine 50") {
$script:LabServer = Set-Location "\\Server50\K$"
}
elseif($SelectedServer -eq "Lab Machine 55") {
$script:LabServer = Set-Location "\\Server55\K$"
}
elseif($SelectedServer -eq "Lab Machine 40") {
$script:LabServer = Set-Location "\\Server40\K$"
}
elseif($SelectedServer -eq "Lab Machine 45") {
$script:LabServer = Set-Location "\\Server45\K$"
}
}
#======================== INPUTBOX ========================#
$label_message2 = New-Object System.Windows.Forms.Label
$label_message2.Location = New-Object System.Drawing.Size(20,110)
$label_message2.Size = New-Object System.Drawing.Size(100,15)
$label_message2.Text = "Custodian Names"
$CreateFolder.Controls.Add($label_message2)
# Inputbox
$Inputbox = New-Object System.Windows.Forms.TextBox
$Inputbox.Multiline = $True;
$Inputbox.Location = New-Object System.Drawing.Size(20,130)
$Inputbox.Size = New-Object System.Drawing.Size(300,200)
$Inputbox.ScrollBars = "Vertical"
$CreateFolder.Controls.Add($Inputbox)
#======================== BUTTON ========================#
# add a button ti create folder
$button_ClickMe = New-Object System.Windows.Forms.Button
$button_ClickMe.Location = New-Object System.Drawing.Size(45,340)
$button_ClickMe.Size = New-Object System.Drawing.Size(240,32)
$button_ClickMe.TextAlign = "MiddleCenter"
$button_ClickMe.Text = "Create Folders"
$button_ClickMe.Add_Click({Get-Server})
$button_ClickMe.Add_Click({
If ($CaseName.TextLength -eq 0){
[System.Windows.MessageBox]::Show('Please Enter a Case Name')
}
elseif ($Inputbox.TextLength -eq 0){
[System.Windows.MessageBox]::Show('Please enter 1 custodian name')
}
else {
Set-Location $LabServer
New-Item $CaseName.Text -type directory
Start-Sleep -Seconds 5
Set-Location ($LabServer.Text + $CaseName.Text)
#$button_ClickMe.Text = "Folders were created"
ForEach ($Folder in $Inputbox.lines) {
New-Item $Folder -type directory
}
#======================== YES OR NO MESSAGE ========================#
$UserResponse= [System.Windows.Forms.MessageBox]::Show("Do you want to continue? YES for a new Case, NO to Exit" , "Create Folders", 4)
if ($UserResponse -eq "YES" )
{
$CaseName.Text = ''
$Inputbox.Text = ''
}
else
{
[System.Windows.Forms.Application]::Exit()
}
}
})
$CreateFolder.Controls.Add($button_ClickMe)
# show form
$CreateFolder.Add_Shown({$CreateFolder.Activate()})
[void] $CreateFolder.ShowDialog()