Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. Add-Type -AssemblyName System.Windows.Forms
  2. $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
  3. InitialDirectory = [Environment]::GetFolderPath('Desktop')
  4. Multiselect = $true # Multiple files can be chosen
  5.  
  6. }
  7.  
  8. [void]$FileBrowser.ShowDialog()
  9.  
  10. $path = $FileBrowser.FileNames;
  11.  
  12. If($FileBrowser.FileNames -like "**") {
  13.  
  14. # Do something before work on individual files commences
  15. $FileBrowser.FileNames #Lists selected files (optional)
  16.  
  17. foreach($file in Get-ChildItem $path){
  18. Get-ChildItem ($file) |
  19. ForEach-Object {
  20. Set-ItemProperty -Path $path -Name IsReadOnly -Value $true
  21. compact /C $_.FullName
  22. }
  23. }
  24. # Do something when work on individual files is complete
  25. }
  26.  
  27. else {
  28. Write-Host "Cancelled by user"
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement