Forum Discussion

techhondo's avatar
techhondo
Copper Contributor
Apr 21, 2025

Gui to deploy folder contents to multiple VMs

I am trying to improve imaging computers where I work. I need to create a gui for new hires since the imaging process is so complicated. I need the GUI to request necessary computer names that are being imaged and then copy files from a local workstation to the machines that are being imaged on the network that our technicians do not have physical access to. I have turned to Powershell for the solution in an attempt to improve on my knowledge which is basic really. Below is the code I have come up with so far.

In this code I am getting the location of the file. I would rather copy the entire folder instead of the file but I couldnt find the code to do that. So, if that is possible please show me how. If not I figure I would have to save these imaging files to a ZIP file. Then I could maybe use this GUI I am working on to move the zip file to the remote computers. 

Add-Type -AssemblyName System.Windows.Forms

# Create the form
$form = New-Object System.Windows.Forms.Form
$form.Text = "File and Network Location Collector"
$form.Size = New-Object System.Drawing.Size(400, 200)

# Create the label for file name
$fileLabel = New-Object System.Windows.Forms.Label
$fileLabel.Text = "File Name:"
$fileLabel.Location = New-Object System.Drawing.Point(10, 20)
$form.Controls.Add($fileLabel)

# Create the text box for file name
$fileTextBox = New-Object System.Windows.Forms.TextBox
$fileTextBox.Location = New-Object System.Drawing.Point(100, 20)
$fileTextBox.Size = New-Object System.Drawing.Size(250, 20)
$form.Controls.Add($fileTextBox)

# Create the label for network location
$networkLabel = New-Object System.Windows.Forms.Label
$networkLabel.Text = "Network Location:"
$networkLabel.Location = New-Object System.Drawing.Point(10, 60)
$form.Controls.Add($networkLabel)

# Create the text box for network location
$networkTextBox = New-Object System.Windows.Forms.TextBox
$networkTextBox.Location = New-Object System.Drawing.Point(100, 60)
$networkTextBox.Size = New-Object System.Drawing.Size(250, 20)
$form.Controls.Add($networkTextBox)

# Create the button to submit
$submitButton = New-Object System.Windows.Forms.Button
$submitButton.Text = "Submit"
$submitButton.Location = New-Object System.Drawing.Point(150, 100)
$form.Controls.Add($submitButton)

# Add event handler for the button click
$submitButton.Add_Click({
    $fileName = $fileTextBox.Text
    $networkLocation = $networkTextBox.Text
    [System.Windows.Forms.MessageBox]::Show("File Name: $fileName`nNetwork Location: $networkLocation")
})

# Show the form
$form.ShowDialog()

 
In this portion of the code it is copying from one source to many locations. Thank you for any assistance as this would help my organization a lot. We are getting several new hires who are very new to the industry. This would be a huge blessing. Pardon the change in font size. It did that for no reason, its my first time using the blog, and there appears to be no way to change the sizes lol. Forgive me.
#Define the source folder and the list of target computers
$sourceFolder = "C:\Path\To\SourceFolder"
$destinationFolder = "C:\Path\To\DestinationFolder"
$computers = @("Computer1", "Computer2", "Computer3")  # Replace with actual computer names

# Function to copy the folder
function Copy-Folder {
    param (
        [string]$source,
        [string]$destination
    )
    Copy-Item -Path $source -Destination $destination -Recurse -Force
}

# Execute the copy operation on each computer
foreach ($computer in $computers) {
    Invoke-Command -ComputerName $computer -ScriptBlock {
        param ($source, $destination)
        Copy-Folder -source $source -destination $destination
    } -ArgumentList $sourceFolder, $destinationFolder
}

Write-Host "Folder copied to all specified computers."

No RepliesBe the first to reply

Resources