相关疑难解决方法(0)

Powershell 5 Get-ChildItem LiteralPath不再适用于Include

现在我使用PowerShell 5.0.10586.0更新到Windows 10 TH2 Build 10586

现在我遇到了Get-ChildItem的问题

$files = Get-ChildItem -LiteralPath $path -Force -Recurse -Include *.txt
Run Code Online (Sandbox Code Playgroud)

这将返回$ path中的所有文件,即使它们不是.txt.这在更新之前有效.当我改为

$files = Get-ChildItem -Path $path -Force -Recurse -Include *.txt
Run Code Online (Sandbox Code Playgroud)

它又有效了.但这不是我想要的.这是一个错误还是我做错了什么?

powershell powershell-5.0

8
推荐指数
1
解决办法
1666
查看次数

PowerShell脚本 - Get-ChildItem

我编写了一个脚本,用于从服务器归档日志文件.除了Get-ChildItem的递归与否之外,我的状态还不错......

我似乎遇到的问题是,当Get-ChildItem不是递归的并且-Include只有一个过滤器时,它会被忽略!或者,我做错了(可能).

我把输出清理了一下......

PS C:\foo> Get-childitem -path "c:\foo"

Name
----
bar1.doc
bar2.doc
bar3.doc
foo1.txt
foo2.txt
foo3.txt

PS C:\foo> Get-childitem -path "c:\foo" -Include *.txt
PS C:\foo> Get-childitem -path "c:\foo" -Include *.txt -recurse

Name
----
foo1.txt
foo2.txt
foo3.txt
Run Code Online (Sandbox Code Playgroud)

SOOO ??? 我有一个幻想,我所要做的就是分支到没有递归开关的脚本路径.(顺便说一句,是否可以可变地应用参数,以避免重复的代码路径,其中唯一的可变性是cmdlet的参数?)

无论如何,除了我的Get-ChildItem问题之外,这里还有我的完整性脚本.

function MoveFiles()
{
    Get-ChildItem -Path $source -Recurse -Include $ext | where { $_.LastWriteTime -lt (Get-Date).AddDays(-$days) } | foreach {
        $SourceDirectory = $_.DirectoryName;
        $SourceFile = $_.FullName;
        $DestinationDirectory = $SourceDirectory -replace [regex]::Escape($source), $dest;
        $DestionationFile = $SourceFile -replace [regex]::Escape($source), …
Run Code Online (Sandbox Code Playgroud)

powershell get-childitem

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×2

get-childitem ×1

powershell-5.0 ×1