我的组织要求从我们的计算机和服务器.PFX
中过滤和删除所有文件。.P12
根据更高的指导,我们目前每周运行的脚本不够深入或不够深入。我想要做的是获取我当前的工作脚本,并过滤两个文件扩展名。写剧本的人几乎已经离开了这个世界,所以我正在写一个不是我写的剧本,但我正在努力熟悉。
我已经尝试更改Get-ChildItem
cmdlt 内部的一些变量以在此处应用过滤而不是变量。这包括尝试:
$Files = Get-ChildItem -Path \\$client\c$\Users -Filter -filter {(Description -eq "school") -or (Description -eq "college")} -Recurse -ErrorAction SilentlyContinue
这是代码的一部分,而不是全部。除此之外,还有日志记录和注释以及其他管理任务,我只包含了导致错误的代码部分。
$computers = Get-ADComputer -Filter * -SearchBase "AD OU PATH OMITTED"
$destination = "****\Software\aPatching_Tools\Log Files\Soft Cert\Workstations\AUG 19\WEEK 2"
$ext = "*.pfx"
foreach ($computer in $computers)
{
$client = $computer.name
if (Test-Connection -ComputerName $client -Count 1 -ErrorAction SilentlyContinue)
{
$outputdir = "$destination\$client"
$filerepo = "$outputdir\Files"
$files = Get-ChildItem -Path \\$client\c$\Users -Filter $ext -Recurse -ErrorAction SilentlyContinue
if (!$files)
{
Write-Host -ForegroundColor Green "There are no .pfx files on $client."
}
else
{
Write-Host -ForegroundColor Cyan "PFX files found on $client"
脚本的预期和正常操作是它遍历每台机器,对其进行测试,如果它离线则继续,或者如果它在线,则在搜索和继续时有 4-5 分钟的暂停。
当我进行更改(例如执行$ext = "*.p12"
, )时出现的错误".pfx"
是-Filter
不支持此操作。或者,如果我尝试对过滤进行上述更改,脚本每台机器需要 1-2 秒,有时C:\Users文件夹中有 15-20 个用户,几乎不可能通过网络快速搜索。