Powershell program to upload multiple files with version control at the file level

I have a network folder which contains multiple files refreshed daily.I then run a power
shell scrip which uploads all the files . I have scheduled it to run once
daily. I have version control at the directory level , is there a way to upload all the files daily and maintain the last X versions for each file , rite now it does it at a folder level . I want it at a file level
powershell script
if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
Add-PSSnapin Microsoft.SharePoint.PowerShell
#Script settings
$webUrl = "http://sharepoint.contoso.com/Corporate/Sales/"
$docLibraryName = "Shared Documents"
$docLibraryUrlName = "Shared Documents\arizona" # specify your subfolder url here
$localFolderPath = "C:\Test"
#Open web and library
$web = Get-SPWeb $webUrl
write-host $webUrl
$docLibrary = $web.Lists[$docLibraryName]
write-host $docLibrary
$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
write-host $files
ForEach($file in $files)
if($file.Name.Contains(".pdf"))
write-host $file
#Open file
try
$fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()
#Add file
$folder = $web.getfolder($docLibraryUrlName)
write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
$spFile = $folder.Files.Add($folder.Url + "/" + $file.Name,[System.IO.Stream]$fileStream, $true)
write-host "Success"
#Close file stream
$fileStream.Close();
catch
Write "Error: $file.name: $_" >>c:\logfile.txt
continue;
#Dispose web
$web.Dispose()

Check if this helps you
http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/28/weekend-scripter-use-powershell-to-upload-a-sharepoint-file-version.aspx
# Add the Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell
# Retrieve specific Site
$spWeb = Get-SPWeb http://SP01
# Create instance of Folder
$spFolder = $spWeb.GetFolder("Shared Documents")
# Get the file on Disk that we want to upload
$file = Get-Item C:\Documents\MyDoc.docx
# upload the file.
$spFolder.Files.Add("Shared Documents/MyDoc.docx",$file.OpenRead(),$false)
$newVersion = $spFolder.Files.Add($spFile.Name, $file.OpenRead(), $spFile.Author, $spFile.ModifiedBy, $spFile.TimeCreated, (Get-Date))
If this helped you resolve your issue, please mark it Answered

Similar Messages

  • Read Document in FileUtilities  cannot search a file with french character in the file name

    Hi,
    I am trying to search a file with french character in the file name like 'captures écran.doc' in my unix server directory, and Write the file somewhere, say in a list of documents or, write on file system to another directory.
    I am using to Read Document in FileUtilities of Foundation, but it cannot read the file due to french character in its name. Although it can find any other file name without these french characters.
    Tried renaming but that also cannot find the file with french character name.
    Please provide any idea to solve it using LC operation.
    Regards,
    Rohan Raj.

    Hi Thomas,
    Thanks for the post, but I have already found a solution to it a month ago. Sorry for not posting the solution.
    You just have to set the '-Djava.property.file.encoding=ISO8859-1' into JVM argument of your server startup, and bounce the server back to pick the new JVM arg set. And now the service Read Document in FileUtilities of Foundation will read all french characters.
    ISO8859-1refers to "Latin alphabet no. 1," consisting of 191 characters from the Latin script. This character-encoding scheme is used throughout The Americas,Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.
    regards,
    Rohan Raj.

  • Serving up files with Russian chars in the file name

    Anyone know how to get CF 8 to serve up CFM files with
    Russian characters in the file name? I can get IIS to server up
    .html files but .cfm files turn in to ?????????.cfm files.
    For example, this:
    новостииобновления.cfm
    becomes this ??????????????.cfm and throws a CF error (File Not
    Found) when clicking on the link. The strange thing is I can see
    the Russian characters in the status bar when I mouse over the link
    but CF can't handle it. And IIS will serve up the file and replace
    all the chars with their URL entity equivalent.
    Any suggestions on how to fix?

    Open the Script Editor or AppleScript Editor in one of the subfolders of Applications and run the following:
    tell application "Finder" to quit
    if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is "1" then
    do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
    else
    do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
    end if
    delay 2
    tell application "Finder" to run
    If you change your mind later, run the script again.
    (93787)

  • How to handle flat file with variable delimiters in the file sender adapter

    Hi friends,
    I have some flat files in the ftp server and hope to poll them into XI, but before processing in XI, I hope to do some content conversion in the file sender adapter, according to the general solution, I just need to specify the field names, field seperator, end seperator, etc. But the questions is:
    The fileds in the test data may have different amount of delimiters (,), for example:
    ORD01,,,Z4XS,6100001746,,,,,2,1
    OBJ01,,,,,,,,,,4,3     
    Some fileds only have 1 ',' as the delimiter, but some of them have multiple ','.
    How can I handle it in the content conversion?
    Regards,
    Bean

    Hi Bing,
    Plz do refer the following blogs u will get an idea:
    File content conversion Blogs
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2005/08/17/nab-the-tab-file-adapter
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2005/08/17/nab-the-tab-file-adapter
    /people/jeyakumar.muthu2/blog/2005/11/29/file-content-conversion-for-unequal-number-of-columns
    /people/shabarish.vijayakumar/blog/2006/02/27/content-conversion-the-key-field-problem
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
    Regards,
    Vinod.

  • Could not open the project file with write access. The file may be locked or you may not have permission to write to this location

    Keep getting this message if i try to open a file from an Network Drive. It only appears with adobe Premiere

    Not designed to do what you want on a network, so may or may not work properly... copy your files to a local hard drive for editing and back to network when done
    Some/all? versions of Premiere do not work properly, if at all, over a network
    -see messages #1 and #3 in http://forums.adobe.com/thread/771151
    -you MUST give all users administrator accounts to use Premiere
    -and especially Encore dual layer http://forums.adobe.com/thread/969395
    -#5 Server 2008 is UNsupported http://forums.adobe.com/thread/851602
    -a work around, of sorts http://forums.adobe.com/thread/957523
    -and not on a "domain" http://forums.adobe.com/thread/858977
    -http://helpx.adobe.com/premiere-pro/kb/networks-removable-media-dva.html

  • I can't open pdf files with Ibooks app. The files open for some seconds and then they disappear! Thanks

    Files open and disappear in few seconds!

    It sounds like the app is crashing for whatever reason. Start with simple, easy things.
    Quit iBooks and restart the iPad.
    Go to the home screen first by tapping the home button. Quit/close open apps by double tapping the home button and the task bar will appear with all of you recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner to close the apps. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    If those things do not help - you may want to consider deleting the iBooks app and reinstall it. Make sue that all of your books and pdf files have been backed up and synced with iTunes before you delete the app.

  • Photoshop Elements 13 (Mac) Organizer - Can't save file with version sets.

    I have spent many hours now trying to get Elements Organizer to save Version Sets when I've edited a photo. I've tried more or less every little thing you can find online without any luck. But just moments ago I found that if I move the file to my desktop everything works just fine. I then tried to edit files in a few other folders (also imported to my Organizer) and found that when ever the folder was named to something with a nordic letter in it (å, ä, ö) then I couldn't save my file with version sets (option greyed out) but if I moved that same file to another folder, well then everything worked as it's suposed to.
    I'm using the trial version of PSE 13 for Mac (Yosemite) and the full version is ordered and on it's way. But if this problem can't be fixed, I need to return that order and buy some other photo editing program.
    Can anyone help me with this problem? Is there perhaps a solution to this?
    Please, any help is much appreciated!

    I'm using the English version (as more or less always - Swedish is rarely an option). The thing is that I have never encountered this problem before in any other software I've been using, and certainly not in Aperture that I've been using up until now.
    I name my photo folders with a date and a few words, for ex. "2014-12-31 New Years in Stockholm" (but I normally write in Swedish). I use this method so that my folder that contains the original photos will be easy to find in even without any other software than Finder (or Windows Explorer if I connect my external drive to a Windows machine). I could change the name of all of my folders, or at least all of the folders with a name containing one or more of the letters Å, Ä or Ö to "force" PSE to work as it should, but why? This really shouldn't be a problem.
    I was hoping that their was a simple option or something like that that could fix this issue, but I guess not.
    If this problem lies in the software itself I will have to return it and look elsewhere (but where? Lightroom is certainly not an option if Adobe can't handle "normal" letters and Aperture is discontinued in a few months).
    Thank you for your reply!

  • S3 backup can't upload files with apostrophe​s in the name

    s3 backup doesn't seem to be able to upload any file with an apostrophe in the name.  I see a load of "Unable to upload 'foo bar's.file' to Amazon S3" warnings in the event log.  The log is littered with file names that contain an apostrope.  This seems to be the thing that stands out in common with all of the failed transfers.  Is there some way to workaround the problem besides renaming all files containing apostropes?
    It seems like an easy fix to properly escape single quotes in the name for upload though, but I suppose that I'll need a firmware fix for a change like that.

     Hello spitzcor
    Have you checked your Amazon S3 account to see if the files have actually uploaded to the bucket or if they did indeed fail to upload?
    I also recommend that you contact support to have an incident created.  There is a hotfix for 4.1.108 that updates the Amazon S3 applications API version and might help with what you are experiencing, although it is intended for a seperate Amazon S3 issue.
    LenovoEMC Contact Information is region specific. Please select the correct link then access the Contact Us at the top right:
    US and Canada: https://lenovo-na-en.custhelp.com/
    Latin America and Mexico: https://lenovo-la-es.custhelp.com/
    EU: https://lenovo-eu-en.custhelp.com/
    India/Asia Pacific: https://lenovo-ap-en.custhelp.com/
    http://support.lenovoemc.com/

  • UPLOAD A DIRECTORY WITH N NUMBER OF DATA FILE

    Hi Experts
                               In my scenario i need to upload a directory with n number of excel file from my presentation server to application server . Please do help on that (note : directory with many file not an single file )

    Hi,
    Here is the Code for List of Files from the Specific Directory to Application Server(SAP)..
    REPORT  ZDIRFILES    .
    PARAMETER: p_fdir            type pfeflnamel DEFAULT '/usr/sap/tmp'.
    data: begin of it_filedir occurs 10.
            include structure salfldir.
    data: end of it_filedir.
    *START-OF-SELECTION
    START-OF-SELECTION.
    Get Current Directory Listing for OUT Dir
      call function 'RZL_READ_DIR_LOCAL'
           exporting
                name     = p_fdir
           tables
                file_tbl = it_filedir.
    List of files are contained within table it_filedir
      loop at it_filedir.
        write: / it_filedir-NAME.
      endloop.
    Girish

  • Cannot print PDF file with version 11.0.10 Adobe Reader.

    Cannot print PDF file with version 11.0.10 Adobe Reader.  Get error messages "This document could not be printed" and "There are no pages selected to print".  I am using a Mac OS Ver 10.0.2.  I see that this question has been asked by others recently, but no answers.  Anyone have any suggestions?

    Assuming you are running 10.10.2 and not the ancient 10.0.2, can you tell us what printer and printer driver you are using? How is the printer connected to the computer (network, usb)? See if you can delete the Reader preference files? Years ago I resetting the printer subsystem would sometimes cure a problem like this.

  • When opening a Photoshop file with Bridge, how can I control which version of Photoshop the file wil

    When opening a Photoshop file fthrough Bridge, how can I control which version of Photoshop the file will open in?
    I store my PSD files adjacent to the original RAW file from which it was derived.
    If I open the file folder and double click on that PSD file, it opens in CS6. But,if I use Bridge (CS6) to navigate to and open the same file, it first opens Photoshop CS5 and then opens that PSD file in CS5.
    How can I control which Photoshop will open a file I select when opening it through Bridge?.

    Interesting, but it doesn't give a clue what I'm supposed to do. No Photoshop ducuments listed.
    Look at the PSD file on the location Curt provided and search for Photoshop Document. Next to it ideally should show Adobe Photoshop CS6 if you have Bridge CS6 open. Click on it to provide the fly out menu and choose the correct Photoshop from the list.
    But probably something went wrong with your install. By default Bridge chooses the latest version of PS to open its file in.
    Maybe a reset of the preferences might also help you. Can you provide more details about OS version etc.
    And do you have a good reason for keeping your Raw and finished files in the same location. Personally I keep them apart and use a proper file name convention (yyyymmdd and details) so I can easily search for the DNG files in my archive if I needed them but I don't make mistakes in opening the wrong one

  • How to upload a Flat file into sap database if the file is in Appl'n Server

    Hello Sap Experts , Can you tel me
    " How to upload a Flat file into sap database if the file is in Application Server.
    what is Path for that ?
    Plz Tel Me its Urgent
    Thanks for all

    Hi,
    ABAP code for uploading a TAB delimited file into an internal table. See code below for structures.
    *& Report  ZUPLOADTAB                                                  *
    *& Example of Uploading tab delimited file                             *
    REPORT  zuploadtab                    .
    PARAMETERS: p_infile  LIKE rlgrap-filename
                            OBLIGATORY DEFAULT  '/usr/sap/'..
    DATA: ld_file LIKE rlgrap-filename.
    *Internal tabe to store upload data
    TYPES: BEGIN OF t_record,
        name1 like pa0002-VORNA,
        name2 like pa0002-name2,
        age   type i,
        END OF t_record.
    DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
          wa_record TYPE t_record.
    *Text version of data table
    TYPES: begin of t_uploadtxt,
      name1(10) type c,
      name2(15) type c,
      age(5)  type c,
    end of t_uploadtxt.
    DATA: wa_uploadtxt TYPE t_uploadtxt.
    *String value to data in initially.
    DATA: wa_string(255) type c.
    constants: con_tab TYPE x VALUE '09'.
    *If you have Unicode check active in program attributes then you will
    *need to declare constants as follows:
    *class cl_abap_char_utilities definition load.
    *constants:
    *    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
    *START-OF-SELECTION
    START-OF-SELECTION.
    ld_file = p_infile.
    OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc NE 0.
    ELSE.
      DO.
        CLEAR: wa_string, wa_uploadtxt.
        READ DATASET ld_file INTO wa_string.
        IF sy-subrc NE 0.
          EXIT.
        ELSE.
          SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
                                          wa_uploadtxt-name2
                                          wa_uploadtxt-age.
          MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
          APPEND wa_upload TO it_record.
        ENDIF.
      ENDDO.
      CLOSE DATASET ld_file.
    ENDIF.
    *END-OF-SELECTION
    END-OF-SELECTION.
    *!! Text data is now contained within the internal table IT_RECORD
    * Display report data for illustration purposes
      loop at it_record into wa_record.
        write:/     sy-vline,
               (10) wa_record-name1, sy-vline,
               (10) wa_record-name2, sy-vline,
               (10) wa_record-age, sy-vline.
      endloop.

  • Using Lightroom 4 w/ Windows 7.  Recently started shooting w/ Sony camera .arw files.  Lightroom cannot read the files.  Loaded Adobe converter program onto the computer and this program cannot read the files either.  Any suggestions?

    Using Lightroom 4 w/ Windows 7.  Recently started shooting w/ Sony camera that shoots .arw files.  Lightroom cannot read the files.  Loaded Adobe converter program onto the computer and this program cannot read the files either.  Any suggestions?

    Thnx again for the reply.  The version of Lightroom I have is 4.0  (working w/Windows 7)  This computer and all media files are kept off-line After doing more research, I downloaded DNG Converter 7.1This loaded into a .zip folder, which I am planning to install into the off-line computer andrun.  Where does this folder go?
    And will this set up work with my version of Lightroom?
    What a pain.  Makes me wanna go back to shooting .nef files for all stills
    Thnx

  • Get error message "this "**" file cannot be attached until the files already attached are finished uploading" even when attaching 1 file

    I attached multiples .pdf files to an email. Tried to attach the next file before the previous 1 finished attaching. Got error message "this "**" file cannot be attached until the files already attached are finished uploading". Was never able to attach that 1 file to the email that I received the error message for; was able to attach subsequent files to that same email & send it. Now, I often get the same error message, even if I only attach 1 file & esp. when attaching .ai or .jpeg files. What can I do to fix this problem?

    It looks like nobody has an answer for this despite of the 80 something views!
    And here i thought Adobe admin would be monitoring the forum, but surprisingly, they don't even have the answer for this!!!

  • With Windows Vista Once the file is Downloded I Can't Open File, Whats wrong, What Can I Do to Solve this problem?

    Tried to download an AntiVirus program Windows Vista and Firefox, once I click download the file is taken to the Download management window, then I try to open the File by Double-Click' or Right Clicking The Mouse, but nothing happens. the word Open it's not Highlighted or the right click won't do anything. Has anybody experienced this problem before? Help

    If "Open" and "Open Containing Folder" in the right-click context menu in the Download Manager window are grayed then that means that the file is no longer in the original download location and they may have been removed by Anti-virus or cleanup software.
    It is possible that your anti-virus software is corrupting the downloaded files or otherwise interfering with downloading files by Firefox.
    See also "Disable virus scanning in Firefox preferences - Windows"
    * http://kb.mozillazine.org/Unable_to_save_or_download_files

Maybe you are looking for

  • Calendar font and color change no reason

    I am attempting to create a calendar with the new Iphoto and I have to say it is harder to use then the old one. I am trying to manually enter birthdays. Typed couple of entries with Hoefler Text size 8 and worked. All of a sudden tried typing in ano

  • Table which stores SU01 Master Data (Telephone Number)

    Hi Experts, We goto SU01 tcode to get the master data of SAP ID. I was able to track the table which is updated for all except the TELEPHONE NUMBER which is present there. Could you please advice in which table the TELEPHONE NUMBER is stored ? I trie

  • IDOC type for PO

    Hello, I am new to SRM and need to send a PO created in SRM 6.0 to a legacy system as an IDOC. I have checked the available IDOC types in SRM and cannot find any types that match a PO. Does anybody know if such an IDOC type exists? Thank you

  • How to create xml template in landscape format

    Hello Everyone, I am trying to create a template in Landscape format in xml publisher. But when i upload and run, the output is in portrait format only. Any suggestions would be helpful. Thank You Kumar

  • MacBook pro 15 inch Hard drive noise - 2.4ghz vs. 2.53ghz

    Hi, I finally re-purchased a mid-range MacBook Pro 15 inch (500hd, 2.53 ghz). I had first bought it in September from the online store but it was scratched right out of the box and the bottom panel wasn't put in properly so I sent it back. Anyways...