运行 PowerShell 脚本时出现错误。它在说明
Microsoft.Powershell.Core\FileSystem::\[path to directory] 中的项目有子项,并且未指定 Recurse 参数。
在我的 PowerShell 脚本中,我确实指定了它。是不是在错误的位置?
# Add CmdletBinding to support -Verbose and -WhatIf
[CmdletBinding(SupportsShouldProcess=$True)]
param
(
# Mandatory parameter including a test that the folder exists
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_ -PathType 'Container'})]
[string]
$Path,
# Optional parameter with a default of 60
[int]
$Age = 60
)
# Identify the items, and loop around each one
Get-ChildItem -Path $Path -Recurse -Force | where {$_.lastWriteTime -lt (Get-Date).addDays(-$Age)} | ForEach-Object {
# display what is happening …Run Code Online (Sandbox Code Playgroud) powershell ×1