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.
Locked
User avatar
FDBTech
Posts: 3
Joined: Sun Mar 03, 2013 12:44 pm

Copy-Item greys out Form on large files

Post by FDBTech » Thu Mar 21, 2013 1:31 pm

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: 5801
Joined: Thu Aug 18, 2011 4:56 am

Re: Copy-Item greys out Form on large files

Post by davidc » Thu Mar 21, 2013 2:35 pm

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
Joined: Sun Mar 03, 2013 12:44 pm

Re: Copy-Item greys out Form on large files

Post by FDBTech » Fri Mar 22, 2013 3:41 pm

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: 5801
Joined: Thu Aug 18, 2011 4:56 am

Re: Copy-Item greys out Form on large files

Post by davidc » Fri Mar 22, 2013 4:45 pm

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
Joined: Sun Mar 03, 2013 12:44 pm

Re: Copy-Item greys out Form on large files

Post by FDBTech » Mon Mar 25, 2013 9:55 am

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

Thanks David!

Locked