【问题标题】:PowerShell script to remove file from hidden foldersPowerShell脚本从隐藏文件夹中删除文件
【发布时间】:2015-09-23 20:04:28
【问题描述】:

我目前正在尝试运行我编写的脚本。它工作得很好,但我也需要它来搜索并从隐藏文件夹中删除。它似乎对隐藏文件夹没有任何影响...这是我的脚本。

Get-ChildItem C:\ -Include saplogon.ini -Recurse | foreach ($_) {Remove-Item $_.fullname}

$src_dir = "\\xxxxxxxxxx\xxxxxxxxxxxx\saplogon\saplogon.ini"
$dst_dir = "C:\Windows"
$file = Get-ChildItem $src_dir
Copy-Item $file -Destination $dst_dir

[System.Environment]::SetEnvironmentVariable('SAP_LOGON_INI', 'C:\Windows\saplogon.ini', 'Machine')

【问题讨论】:

  • get-childitem -force 假设你有权限

标签: windows powershell appdata


【解决方案1】:

您缺少-Force 参数。 下面的代码使用别名,因此不需要水平滚动。知道gci 是Get-ChildItem。

请注意,只有获得许可才能访问。

gci c:\ -Include saplogon.ini -Recurse -Force | foreach ($_) {remove-item $_.fullname}

此时,您可能已经处理了非隐藏文件。如果您想再次运行脚本,但只针对隐藏文件(而不是非隐藏文件),您可以使用 -Hidden 标志来执行此操作。

同样,只有获得许可,您才能获得访问权限。

gci c:\ -Include saplogon.ini -Recurse -Hidden | foreach ($_) {remove-item $_.fullname}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多