\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n","upvoteCount":1,"datePublished":"2021-11-05T16:21:51.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/5","author":{"@type":"Person","name":"ethanlekki","url":"https://community.spiceworks.com/u/ethanlekki"}},"suggestedAnswer":[{"@type":"Answer","text":"I want to save the selected files in the selected folder. If no file was selected, the message “No Software was selected” should appear.<\/p>\n
Thank you for your answers<\/p>\n
$handler_submitlocalinstallation_Click= \n\t{\n\twrite-host \"Initialization... Form closed. \" -ForegroundColor Yellow\n\t$window3.Close()\n\t\n\tCopy-Item $openFileDialog1 -recurse $SelectFolder\n\tif ([string]::IsNullOrEmpty($openFileDialog1)) {\n\t Write-Host \"No Software was selected\" -ForegroundColor Red\n\t\t}\n\t\telse{\n\t Write-Output \"preparing installation $openFileDialog2 \"\n\t Start-Process -Wait -FilePath $OpenFileDialog1 -ArgumentList \"/S\" -PassThru\n\t }\n\t\n\t copy-Item $openFileDialog2 -recurse $SelectFolder\n\t if ([string]::IsNullOrEmpty($openFileDialog2)) {\n\t Write-Host \"No Driver was selected\" -ForegroundColor Red\n\t }\n\t\telse{\n\t Write-Output \"preparing installation $openFileDialog1\"\n\t Start-Process -Wait -FilePath \"$OpenFileDialog2\" -ArgumentList \"/S\" -PassThru\n\t }\n\t}\n<\/code><\/pre>\n <\/p>","upvoteCount":5,"datePublished":"2021-11-05T11:45:12.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/1","author":{"@type":"Person","name":"noahscherrer","url":"https://community.spiceworks.com/u/noahscherrer"}},{"@type":"Answer","text":"
Can you be more specific about “it does not work”? What exactly happens when you run it?<\/p>","upvoteCount":1,"datePublished":"2021-11-05T12:46:02.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/2","author":{"@type":"Person","name":"kencarter","url":"https://community.spiceworks.com/u/kencarter"}},{"@type":"Answer","text":"
the following error message appears “Copy-Item : The drive was not found. A drive with the name “System.Windows.Forms.OpenFileDialog” does not exist.”<\/p>","upvoteCount":0,"datePublished":"2021-11-05T13:00:13.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/3","author":{"@type":"Person","name":"noahscherrer","url":"https://community.spiceworks.com/u/noahscherrer"}},{"@type":"Answer","text":"
My initial action would be to print the values of the variables you are using. One of your variables is not set to a value appropriate for the command you are issuing.<\/p>","upvoteCount":0,"datePublished":"2021-11-05T15:57:41.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/4","author":{"@type":"Person","name":"kencarter","url":"https://community.spiceworks.com/u/kencarter"}},{"@type":"Answer","text":"
Thank you very much for the nice answer that really helped me. I wish you still a nice day !<\/p>","upvoteCount":0,"datePublished":"2021-11-05T17:09:25.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/6","author":{"@type":"Person","name":"noahscherrer","url":"https://community.spiceworks.com/u/noahscherrer"}},{"@type":"Answer","text":"
still a small question and true everything works also with the installation but still occurs the following error message:<\/p>\n
Start-Process : This command cannot be executed completely because the system cannot find all the required information. \nIn C:\\Users\\noah\\OneDrive\\Desktop\\TBZ\\M122\\Powershell project 2\\Code\\GUI Complete\\Installer_Noah-Scherrer.ps1:688 characters:5<\/p>\n
\nStart-Process -Wait -FilePath $OpenFileDialog1 -ArgumentList …<\/li>\n \n<\/code><\/pre>\n<\/li>\nCategoryInfo : InvalidOperation: ( [Start-Process], InvalidOperationException<\/li>\n FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand<\/li>\n<\/ul>\nThanks a lot for your efforts.<\/p>","upvoteCount":0,"datePublished":"2021-11-05T17:19:12.000Z","url":"https://community.spiceworks.com/t/can-someone-please-check-the-code-it-does-not-work/816096/7","author":{"@type":"Person","name":"noahscherrer","url":"https://community.spiceworks.com/u/noahscherrer"}}]}}
Hello Noah!
Your problem is that you are trying to copy the OpenFileDialog that you presumably created earlier in your code. If you want to copy the file you selected in your file dialog, you will want to select that property of the System.Windows.Forms.OpenFileDialog class, which should be done like so:
Copy-Item $openFileDialog1.FileName -recurse $SelectFolder
In the future when you’re working with the .NET Framework, I recommend reading the MS docs about how to use their framework. It is quite well documented, with examples (mostly in C#, but the important part isn’t the syntax, it’s how they’re using the framework objects). I have linked the page for the particular class you seem to be having trouble with.
Hopefully you found this helpful! If you feel I answered your question, don’t forget to mark it as so!
Also, in the future I’d recommend reading through this to get the best help you can when you ask a question on here! I was only able to figure out your problem after reading your previous comment to something someone else asked you. We don’t know how to fix code unless we know what’s going wrong!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…
1 Spice up