移动活动目录输出的文件列表

时间:2018-09-17 19:47:19

标签: powershell active-directory move

我是PowerShell的新手,我试图在工作中重建许多过时的“轮子”,但可悲的是仍然需要。

内容:我们将所有BitLocker恢复密钥备份到一个文本文件。当计算机脱机并从AD中删除时,我们将运行报告,其中包括撤消该文本文件以进行备份。我们运行的脚本在AD上查看PasswordLastSet变量,如果密码已设置超过90天,则将其输出到CSV文件,因此我在excel工作表中列出了需要删除的计算机。

我要做的是获取该CSV文件,并使用PowerShell脚本搜索这些计算机名称,并在末尾附加“ .txt”,然后将其移至备份文件夹。我可以使脚本一次只能工作一次,但不能连续工作。接下来是我的脚本副本,其中省略了服务器名称:

$ComputerNames = Get-Content "\\SERVER\Software\Bitlocker\OLD BITLOCKER KEYS\Over_90.txt"
$New_path = "\\SERVER\Software\Bitlocker\OLD BITLOCKER KEYS\FY 18\13 - SEP 18"
$ComputerName = $ComputerNames
$ComputerNames = $ComputerNames +".txt"

foreach ($ComputerName in $ComputerNames)
{   cd "\\SERVER\Software\Bitlocker\BITLOCKER KEYS\Windows10"
        move-item $ComputerNames $new_path -Force
}

1 个答案:

答案 0 :(得分:0)

我可能会从以下内容开始:

$ComputerNames = Get-Content "\\SERVER\Software\Bitlocker\OLD BITLOCKER KEYS\Over_90.txt"
$DestinationPath = "\\SERVER\Software\Bitlocker\OLD BITLOCKER KEYS\FY 18\13 - SEP 18"

foreach ($ComputerName in $ComputerNames) {
    $SourceFile = "\\SERVER\Software\Bitlocker\BITLOCKER KEYS\Windows10\$ComputerName.txt"
    if ((Test-Path $SourceFile)) {
        Move-Item -LiteralPath $SourceFile -Destination $DestinationPath -Force
    }
    else {
        Write-Warning "File '$SourceFile' not found."
    }
}

如果不断出现终止错误,则可能需要在-ErrorAction Continue行上指定Move-Item