Powershell pitfalls

后端 未结 21 1407
梦谈多话
梦谈多话 2020-12-23 01:44

What Powershell pitfalls you have fall into? :-)

Mine are:

# -----------------------------------
function foo()
{
    @(\"text\")
}

# Expected 1, a         


        
21条回答
  •  醉话见心
    2020-12-23 02:27

    Mine are both related to file copying...

    Square Brackets in File Names
    I once had to move a very large/complicated folder structure using Move-Item -Path C:\Source -Destination C:\Dest. At the end of the process there were still a number of files in source directory. I noticed that every remaining file had square brackets in the name.

    The problem was that the -Path parameter treats square brackets as wildcards.
    EG. If you wanted to copy Log001 to Log200, you could use square brackets as follows: Move-Item -Path C:\Source\Log[001-200].log.

    In my case, to avoid square brackets being interpreted as wildcards, I should have used the -LiteralPath parameter.

    ErrorActionPreference
    The $ErrorActionPreference variable is ignored when using Move-Item and Copy-Item with the -Verbose parameter.

提交回复
热议问题