PowerTip: Use the Force Switch in PowerShell

PowerTip: Use the Force Switch in PowerShell

  • Comments 4
  • Likes

Summary: Many times Windows PowerShell cmdlets display additional information when using the Force switch.

Hey, Scripting Guy! Question How can I display hidden and system files when using Windows PowerShell?

         Hey, Scripting Guy! Answer Use the Get-Item or Get-ChildItem cmdlet and use the Force switch—this works with other cmdlets as well.

                           Get-ChildItem -force

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi Ed,

    and I still wonder why ... why not add a switch -hidden ?

    Or add an "-attribute hidden" parameter ?

    There is a readonly, system, archive etc. attribute but still we have to use "-force" if we want to reveal hidden files or directories ???

    And that's ... why I still wonder why ... :-)


  • Thought you were channeling Obi-Wan there for a moment...

  • @Klaus

    I think we can use the property "Mode" to get the specifiy files or directories you want, right?

    Like hiden files

    ls -force | ?{$_.mode -match "h"}

  • @Klaus Schulte one reason is because -Force is a common switch that is honored by hundreds of cmdlets. To stay consistent we use standard parameters.

    @Martin9700 it is how I remember ... "Use the Force ....." Then I don't forget it :-0

    @Larry Song CN good point.