I am new at powershell scripting. I am asking for help. I have to create a script to upload folders from a fileserver to sharepoint. The script must monitoring that location( folder). And when a new folder is created ( at the same location on the server) run.


I am not sure can you hook up to the folder creation event. But what you could do is to have PowerShell set up as windows scheduled tasks. Have an csv file with existing folders to compare. If the comparison shows difference then create new folders and update the csv file. You could set it up in the scheduler to run every few minutes, it won't be real time but close to.

  • Thank you for your reply. The task is not about scheduled tasks. I have got the uploading script, but I do not know how to search for new folder.Similar to this one. .$cred = (Get-Credential admin@contoso.com) $sourceFiles = '\\fileshare\users\charles' $sourcePackage = 'C:\migration\CharlesDocumentsPackage_source' $targetPackage = 'C:\migration\CharlesDocumentsPackage_target' $targetWeb = 'contoso-my.sharepoint.com/personal/charles_contoso_com' $targetDocLib = 'Documents'
    – Junior
    Jul 18 '19 at 13:07
  • I set up a wacher SET FOLDER TO WATCH $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "filesrevre" $watcher.Filter = "*" $watcher.EnableRaisingEvents = $true ### DEFINE ACTIONS AFTER AN EVENT IS DETECTED $action = { Start-Process powershell -Argument "the script" } ### DECIDE WHICH EVENTS SHOULD BE WATCHED Register-ObjectEvent $watcher "Created" -Action $action while ($true) {sleep 20}
    – Junior
    Jul 18 '19 at 13:08
  • The point is when someone create a new folder on the fileserver to go automatically to sharepoint. The script should compare/search for new folder
    – Junior
    Jul 18 '19 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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