locked
Need help with powershell to prompt SaveAs diag box. RRS feed

  • Question

  • Greetings!

    I am a amatuer in powershell. After some digging in various forums, I found a simple powershell code which monitors a particular directory for any file changes(Creation) and if found, calls a batch file which copies the files to a designated path.

    $folder = "C:\Users\$env:USERNAME\Documents\" # Enter the root path you want to monitor.
     $filter = '*.*'  # You can enter a wildcard filter here. 
    
     $fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property  @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
    
     Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { 
     $name = $Event.SourceEventArgs.Name 
     $changeType = $Event.SourceEventArgs.ChangeType 
     $timeStamp = $Event.TimeGenerated 
     Write-Host "The file '$name' was $changeType at $timeStamp" -fore green 
     cmd.exe /c 'C:\FileCopy\Test1.bat'
     }

    As you can see, this code monitors the documents folder of any user and if a new file is created/copied to this path, calls a Test1.bat file which contains a simple xcopy command to copy those files to a predefined directory path.

    Now, what i want is a powershell script which monitors the said directory and if any changes found, gives the user a "SaveAs" dialogue box so user can choose his directory instead of just copying it to a fixed path.

    Basically a file transfer box using which he can copy file/s to his/her selected directory.

    Any guidance/help please.

    Thanks

    Wednesday, July 25, 2018 10:14 AM

All replies