Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created a WorkFlow to create a document populating it with data from a list. I now need a powershell script that can copy the file in the document library to a file share on our server.

I am new to using powershell in SharePoint, is this possible with a script?

share|improve this question
    
yes it is possible –  Sebastien Stettler Mar 1 '12 at 12:18
    
@SebastienStettler I did find a post on this site sharepoint.stackexchange.com/questions/6511/… It included a script which I have altered which copies files however how would I change it to only fetch a single file? –  Jonathan F Mar 1 '12 at 13:33

1 Answer 1

You can use this method.

$fileUrl = url for file on sharepoint

$destinationfolder = destinationFolder

function ProcessURL {
    param($fileUrl,$destinationfolder)
    $file = $web.GetFile($fileUrl)
        $destinationfolder = $destination + "/" + $folder.Url 
        if (!(Test-Path -path $destinationfolder))
        {
            $dest = New-Item $destinationfolder -type directory 
        }
        #Download file
        $binary = $file.OpenBinary()
        $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
        $writer = New-Object System.IO.BinaryWriter($stream)
        $writer.write($binary)
        $writer.Close()
        #Delete file by deleting parent SPListItem
        $list.Items.DeleteItemById($file.Item.Id)
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.