Hi ThomasGroh-5824,
Thanks for writing the scenario and attaching the script. We are happy to help you.
Please find the working code snippet below. I have added code to copy the folders based on user selection under 'Process' method. If you have to further functionality, please add under 'end' method.
===============================Code starts here================
[CmdletBinding(SupportsShouldProcess=$True)]
Param ([Parameter(
Mandatory = $False,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True)]
[Alias("A")]
[Switch] $UserAccount,
[Parameter(
Mandatory = $False,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True)]
[Alias("CU")]
[Switch] $SourcePath)
Begin{
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = "Sticky Notes Backup"
$form.Size = New-Object System.Drawing.Size(300,250)
$form.StartPosition = "CenterScreen"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(10,180)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(85,180)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = "Please select user"
$form.Controls.Add($label)
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(150,20)
$listBox.Height = 140
$listbox.Items.AddRange((get-localuser | select -expand name))
$form.Controls.Add($listBox)
$form.Topmost = $True
$result = $form.ShowDialog()
if ($ListBox.SelectedIndices.Count -lt 1 -and $result -eq [System.Windows.Forms.DialogResult]::OK)
{
Write-Warning 'Nothing was selected, please select a user.'
}
ElseIf ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$UserAccount = $listBox.SelectedItem
}
}
Process{
If ($UserAccount -eq 'ravi2_000')
{
Write-Host = "Selected user account: " $UserAccount
$str1="C:\Users\"
$str2="\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState"
$SourcePath = $str1 + $UserAccount + $str2
Write-Host = $SourcePath
Copy-Item -Path $SourcePath -Destination "C:\Users\ravi2_000\OneDrive\Desktop\Fold" -recurse -Force
}
}
End{
If ($UserAccount -eq 'ravi2_000')
{Write-Host = "Files copied from user account: " $UserAccount}
}
==========Code ends here==============
Please modify the 'If' condition based on your functionality (To validate whether correct user is selected)
--If the reply is helpful, please Upvote and Accept as answer.--
Thank you!