Copy-Item greys out Form on large files
Posted: 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!
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 } }