【发布时间】:2016-04-08 03:55:17
【问题描述】:
我的 PowerShell 可执行文件中有一个从 PHP 脚本返回的数组值列表。这些值对应于我的 Windows Server 上的活动项目。我的C:/ 驱动器中有一个项目文件夹,其中包含该服务器已处理的每个项目的子文件夹。结构看起来像这样:
/project-files
/1
/2
/3
/4
以上信号表明服务器到目前为止已经处理了四个项目。
我每天运行一个计划任务 Powershell 脚本来清理 project-files 文件夹。当我运行我的脚本时,我只想删除与当前未在服务器上运行的项目相对应的子文件夹。
我有以下 Powershell:
$active_projects = php c:/path/to/php/script/active_projects.php
if($active_projects -ne "No active projects"){
# Convert the returned value from JSON to an Powershell array
$active_projects = $active_projects | ConvertFrom-Json
# Delete sub folders from projects folder
Get-ChildItem -Path "c:\project-files\ -Recurse -Force |
Select -ExpandProperty FullName |
Where {$_ -notlike 'C:\project-files\every value in $active_projects*'}
Remove-Item -Force
}
如果子文件夹编号对应于 $active_projects 数组中的项目编号,我想排除删除 project-files 文件夹中的子文件夹。
我将如何在此处编写Where 声明?
【问题讨论】: