Copy-Item greys out Form on large files

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 3 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
FDBTech
Posts: 3
Last visit: Mon Aug 12, 2013 10:37 am

Copy-Item greys out Form on large files

Post by FDBTech »

My issue is when i try to do a Copy-Item that is over 100MB to a remote computer, my Form will grey out (Not Responding) for a long period of time. Is was wondering if there is a way i can continue to use other functions on my Form while the files are being Copied? Here is a sample of my code.
Also, if anyone can suggest a better method of transferring files off a File Server to a remote PC that would be very helpful!

PowerShell Code
Double-click the code block to select all.
$ContextMenuApps_ItemClicked=[System.Windows.Forms.ToolStripItemClickedEventHandler]{
	#Where-Object didn't like $_ClickedItem
	$ClickedItem = $_.ClickedItem
	
	IF ($ClickedItem -ne $null){
	$ImportCSV = @(Import-Csv -Path "\\NetworkShare\File.csv")
	$SCCMDir = "\\FileServer"	
	$AppName = $ComboApp.Text
	$CSVLineItem = $ImportCSV | Where-Object {$_.Name -eq $AppName -and $_.Program -eq $ClickedItem}
	$CSVItemID = $CSVLineItem.PackageID
	$CSVItemCMD = $CSVLineItem.Command	
	$Dir = "$SCCMDir\$CSVItemID"
	$CMDSplit = $CSVItemCMD.Split(" ")[0]
	$CSVDirectory = (Get-ChildItem $Dir -Filter $CMDSplit -Recurse).DirectoryName
	$CSVInstallApp = "$CSVDirectory\$CSVItemCMD"
	$ComputerName = Get-ComputerName
	$StatBar.Text = "Copying files to local PC"
	$CopyPath = "\\$ComputerName\C$\Windows\Temp"
	Copy-Item -Path $CSVDirectory -Destination $CopyPath -Container -Force:$true -Recurse
	$StatBar.Text = "Copy Complete"
	$InvokeAppDir = (Get-ChildItem $CopyPath -Filter $CMDSplit -Recurse).DirectoryName
	$InvokeApp = "$InvokeAppDir\$CSVItemCMD"	
	$PassArgs = @("\\$Computername", "-i", "-s", "-accepteula", $InvokeApp)
	Start-Process "\\NetworkShare\PSexec.exe" -Verb Runas -ArgumentList $PassArgs

	}
}
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Copy-Item greys out Form on large files

Post by davidc »

The following blog articles should provide some help:

Creating Responsive Loops:
http://www.sapien.com/blog/2011/07/15/p ... ive-loops/

Creating Responsive Forms:
http://www.sapien.com/blog/2012/05/16/p ... ive-forms/

David
David
SAPIEN Technologies, Inc.
User avatar
FDBTech
Posts: 3
Last visit: Mon Aug 12, 2013 10:37 am

Re: Copy-Item greys out Form on large files

Post by FDBTech »

Thanks davidc!

I think ill try adding a progress bar to my form. You know of any detailed post on Progress bar's like Spotlight on the "Progress Bar" Control post? I didn't see any when i did a search.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Copy-Item greys out Form on large files

Post by davidc »

Other than the responsive forms blog I have the Spotlight (as you mentioned):

http://www.sapien.com/blog/2011/07/14/p ... r-control/

And the New Progress Bar for PowerShell Studio:

http://www.sapien.com/blog/2012/08/27/p ... r-control/

David
David
SAPIEN Technologies, Inc.
User avatar
FDBTech
Posts: 3
Last visit: Mon Aug 12, 2013 10:37 am

Re: Copy-Item greys out Form on large files

Post by FDBTech »

(Face Palm)
Oh God. ProgressBar = 1 word... My fault!

Thanks David!
This topic is 11 years and 3 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked