none
Need help to find out the issue

    질문

  • Hi,

    I have script to move file from one place to another place. The file size will vary from 1GB to 15GB as well. Whenever he script moves larger file then it hung and it's not moving forward even the file moved long back. Then when i press CTRL+C then it's moving forward. Could any one help me to fix this issue.

    The script is below

    $Path = "E$\Notes\Data"
    Net use M: "\\domain.com\app\GIS\Exchg_Mig2"
    $csv = Import-Csv Inputfile.csv -Header @("StagingServerName","StagingServerPath","UPIName")
    Foreach ($row in $csv)
    {
        $ServerName = $row.StagingServerName
        $StagingServerName = [System.Net.Dns]::GetHostByName($ServerName) | Select-Object -ExpandProperty HostName
        Write-Host "The Staging Server Name: `'$StagingServerName`'"  
        $StagingServerPath = $row.StagingServerPath
        Write-Host "The Staging Server Path: `'$StagingServerPath`'"
        $UPIName = $row.UPIName
        Write-Host "The UPI Name: `'$UPIName`'"
        $File = Get-childItem "\\$StagingServerName\$Path\$StagingServerPath"
        Write-Host "The File is: `'$File`'"
        $FileName = $File.Name
        Write-Host "The File Name: `'$FileName`'"
        $NewFileName = "$UPIName"
        Write-Host "The New File Name: `'$NewFileName`'"
        if(Test-path "\\$StagingServerName\E$\Temp")
    {
        write-host "Temp folder is Exists"
        Move-Item -Path "\\$StagingServerName\$Path\$StagingServerPath" -Destination "\\$StagingServerName\E$\Temp"
        Rename-Item "\\$StagingServerName\E$\Temp\$FileName" -NewName "$NewFileName"
    }
        Else
    {
        Write-Host "There is No Temp folder"
        md "\\$StagingServerName\E$\Temp"
        Move-Item -Path "\\$StagingServerName\$Path\$StagingServerPath" -Destination "\\$StagingServerName\E$\Temp"
        Rename-Item "\\$StagingServerName\E$\Temp\$FileName" -NewName "$NewFileName"
    }
    }
    Foreach ($row in $csv)
    {
        $ServerName = $row.StagingServerName
        $StagingServerName = [System.Net.Dns]::GetHostByName($ServerName) | Select-Object -ExpandProperty HostName
        Write-Host "The Staging Server Name: `'$StagingServerName`'"  
        #$FilePath = "\\$StagingServerName\E$\Temp"
        Write-Host "The Staging Server Path: `'$FilePath`'"
        $UPIName = $row.UPIName
        Write-Host "The UPI Name: `'$UPIName`'"
        $NewFileName = "$UPIName"
        Write-Host "The New File Name: `'$NewFileName`'"
       
        $Foldername = get-date -uformat "%m-%d-%y"
        if (test-path "M:\$FolderName")
    {
        write-host "Exists: $FolderName"
        Move-Item -Path "\\$StagingServerName\E$\Temp\$NewFileName" -Destination "M:\$FolderName"
        Write-Host "----------------------------------------------------------------------"
    }
        Else
    {
        write-host "No such folder: $FolderName"
        md "M:\$((get-date).toString('MM-dd-yy'))"
        Move-Item -Path "\\$StagingServerName\E$\Temp\$NewFileName" -Destination "M:\$FolderName"
        Write-Host "----------------------------------------------------------------------"
    }
    }
    Net use M: /d
    Remove-Item -Path E:\inputfile.csv

    The input CSV file is below

    PPTWAN112 cmt\04.23.2012\PPTCON25\roba.nsf 10220859-roba.nsf
    PPTWAN112 cmt\04.23.2012\PPTCON25\basa.nsf 10220859-basa.nsf
    PPTWAN112 cmt\04.23.2012\PPTCON25\Mosr.nsf

    10220859-Mosr.nsf

    2012년 5월 4일 금요일 오후 5:29

답변

모든 응답

  • Ctrl-C should cause your script to stop, not "move foward".  That doesn't compute.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    2012년 5월 4일 금요일 오후 5:39
  • If you are transferring files that large, I would not use a standard move.  I would use Bits:

    http://blogs.msdn.com/b/powershell/archive/2009/01/11/transferring-large-files-using-bits.aspx
    http://blogs.msdn.com/b/wmi/archive/2009/01/23/introducing-bits-powershell-cmdlets.aspx
    http://technet.microsoft.com/en-us/magazine/ff382721.aspx
    http://www.nivot.org/post/2009/02/10/AnatomyOfAPowerShellModuleTheFileTransferBITSModule.aspx

    I don't know your infrastructure but if these devices aren't on the same segment, you could get a dropped connection or a drop in packets moving the file between servers that will completely crash your process.  BITS is the answer for this and the genius PoSh team has included BITS usability through PowerShell. 

    2012년 5월 4일 금요일 오후 5:39
  • @thepip3r:  Excellent suggestion.  I didn't even know about it (I'd seen the module, but didn't think much about it).

    Now I've tried it with a simple copy across the network.  It works perfectly!


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    2012년 5월 4일 금요일 오후 6:08
  • Hi,

    Now i used this Bitstransfer command instead of my original command and it's really making difference & worth. But i need to move the data from one server to another server and  dont want the data to be there in the old server too. So is there any command in BITS to move the data instaed of transfer the data? Please let me know. Thanks

    2012년 5월 8일 화요일 오후 6:36
  • without diving into this, is there any reason you just can't delete the source once the transfer is complete?

    2012년 5월 8일 화요일 오후 6:38
  • I justing creating this script to reduce manual work. We cannot delete it manually because in a single time we use to transfer 30-40 files from 40 different server. So each server we cannot login and delete it manually. Then there is no meaning of this script and my intention. So could you please let me know is there any move command is there in the BITS? Thanks
    2012년 5월 8일 화요일 오후 7:01
  • i meant to have your script delete the original file once BITS has completely transferred the file.  in other words, the very last thing your script does is delete the source file.
    2012년 5월 8일 화요일 오후 7:08
  • Yes, i already tried deleting the source file by script but i am facing some other issue. that's what i am looking for instaed of transferring the data, i need to move the data. Thanks
    2012년 5월 8일 화요일 오후 7:12
  • Hi,

    It seems that you're not having a scripting problem. I recommend collecting the exact details about your specific problem and post your specific question in a more appropriate forum.

    Bill

    2012년 5월 8일 화요일 오후 7:15
    중재자
  • Post your new script with the BITS cmdlets in it.  I think we're not understanding each other.  The only difference between "transferring" and "moving" is that with "moving" the source file gets deleted (as a part of the process).  If you're saying that the BITS cmdlets only copy or "transfer" the data to the distant end server but leave the source files in tact, then just delete the source files after the transfer is completed to emulate an actual "move" -- that would be the easy answer. 

    I'm not sure you're describing the question well enough that I can understand it.

    2012년 5월 8일 화요일 오후 7:19
  • BITS calls from script will return to the next line before the transfer is complete.  You must poll BITS to get a completion status.  During the transfer the files are locked.

    BITs can raise an event on each file completed.  You can trap the event and delete each file as it is completed.  See the BITS SDK for examples in script and batch.


    ¯\_(ツ)_/¯


    • 편집됨 jrv 2012년 5월 8일 화요일 오후 7:45
    2012년 5월 8일 화요일 오후 7:44