Windows Powershell正在锁定第一个和最后一个文件,如果不关闭Powershell ISE,我将无法删除它们

Windows Powershell正在锁定第一个和最后一个文件,如果不关闭Powershell ISE,我将无法删除它们,windows,powershell,powershell-ise,Windows,Powershell,Powershell Ise,所以我有一个Powershell ISE(试着以管理员和w/o的身份运行),它被创建为dummy.mdf文件,其中有50个 问题是它保留了第一个和最后一个,所以复制或删除它们是不起作用的 这是我的剧本 param( $amount = 50 # $(throw "Please give an amount of files to be created") , $size = 5 # $(throw "Please give a the size of the files") , $folder

所以我有一个Powershell ISE(试着以管理员和w/o的身份运行),它被创建为dummy.mdf文件,其中有50个

问题是它保留了第一个和最后一个,所以复制或删除它们是不起作用的

这是我的剧本

param(
$amount = 50 # $(throw "Please give an amount of files to be created")
, $size = 5 # $(throw "Please give a the size of the files")
, $folder = "C:\dev\powershell\oldlocation" # $(throw "Please give an output folder wehere the files need to be created")
, $name = 'db' # $null
, $extension = '.mdf' # $null    .mdf  / .ldf
)
CLS
# Check for input
if(Test-Path $folder)
{
if($name -eq $null)
{
Write-Host "No filename given. Using default setting 'dummy'" -ForegroundColor Yellow
$name = 'dummy'
}

if($extension -eq $null)
{
Write-Host "No filename extension given. Using default setting '.txt'" -ForegroundColor Yellow
$extension = 'txt'
}
elseif($extension -contains '.')
{
$extension = $extension.Substring(($extension.LastIndexOf(".") + 1), ($extension.Length - 1))
}

for($i = 1; $i -le $amount; $i++)
{
$path = $folder + '\' + $name + '_' + $i + '.' + $extension
$file = [io.file]::Create($path)
$file.SetLength($size)
$file.Close
sleep 0.5
}

}
else{
Write-Host "The folder $folder doesn't exist" -ForegroundColor Red
Exit(0)
}
当方法上省略
()
时,它返回重载定义。因此,尝试关闭文件的行只需要
()


如果您看到有
OverloadDefinitions
返回,那就是要查找的内容。

$file.Close
->
$file.Close()
很酷,您能快速给出一个有效的答案吗
$file.Close()