我正在尝试在PowerShell中编写一个脚本,该脚本在"foreach"循环中读取特定文件夹中包含"example"的所有文件.问题是我试图在变量中保存每个文件的内容而没有任何成功.尝试使用Get-Content $文件,它会抛出以下错误" Get-Content:找不到路径 ",即使路径设置在文件夹 var 的开头,文件实际上包含我需要的文件.我无法将其分配给$ FileContent
$Folder = Get-ChildItem U:\...\Source
foreach($file in $Folder)
{
if($file.Name -Match "example")
{
$FileContent = Get-Content $file
}
}
Run Code Online (Sandbox Code Playgroud)