I'm trying to automate the process of right clicking a folder or file and then clicking the "Always available offline" in windows 7+.

I've not been able to find any command or batch way to do that. So far, I found this powershell script that simulate a right click operation on a context menu item (Always available offline in my case)

   $o = New-Object -ComObject Shell.Application
$o.Namespace("Z:\").Self.verbs() |
  Where-Object { $_.Name -eq 'Always &available offline' } |
  ForEach-Object { $_.DoIt() } 

It doesn't work. If I try to pass a folder UNC path instead of a drive (let's say Z:\foldertomakeavailableoffline, all I get is "You cannot call a method on a null-valued expression." as if the folder I specify doesn't exist.

Any help is appreciated.


edit: seem like getting verbs from network drive files doesnt work...?

  • You can simulate mouse clicks and keyboard strokes easily and for FREE with AutoIT. It's very intuitive and functional so consider using it if you truly want to automate the task of selecting specific folders and then selecting the needed option from the right click context menu or whatever. – Pimp Juice IT Dec 13 '17 at 4:13
  • Debug your code by running portions at a time. You can use mapped drives or full UNC paths with NameSpace. Try $o = New-Object -ComObject Shell.Application, then $o.NameSpace("Z:\foldertomakeavailableoffline").Self.verbs(). What are the results? – root Dec 14 '17 at 21:28

Your Answer

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

Browse other questions tagged or ask your own question.