Page 1 of 1

Copy-Item greys out Form on large files

Posted: Thu Mar 21, 2013 1:31 pm
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

	}
}

Re: Copy-Item greys out Form on large files

Posted: Thu Mar 21, 2013 2:35 pm
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

Re: Copy-Item greys out Form on large files

Posted: Fri Mar 22, 2013 3:41 pm
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.

Re: Copy-Item greys out Form on large files

Posted: Fri Mar 22, 2013 4:45 pm
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

Re: Copy-Item greys out Form on large files

Posted: Mon Mar 25, 2013 9:55 am
by FDBTech
(Face Palm)
Oh God. ProgressBar = 1 word... My fault!

Thanks David!