Windows powershell导出到文本文件
我正在编写一个脚本,用于检查特定目录中的文件夹。例如,我第一次运行脚本时,它会生成一个txt文件,其中包含目录中的文件夹 我需要脚本添加任何新的目录,找到之前创建的txt文件时,脚本再次运行 有人对如何实现这一点有什么建议吗 以下是我目前的代码:Windows powershell导出到文本文件,windows,powershell,Windows,Powershell,我正在编写一个脚本,用于检查特定目录中的文件夹。例如,我第一次运行脚本时,它会生成一个txt文件,其中包含目录中的文件夹 我需要脚本添加任何新的目录,找到之前创建的txt文件时,脚本再次运行 有人对如何实现这一点有什么建议吗 以下是我目前的代码: $LogFolders = Get-ChildItem -Directory mydirectory ; If (-Not (Test-Path -path "txtfilelocated")) { Add-Content txtfilel
$LogFolders = Get-ChildItem -Directory mydirectory ;
If (-Not (Test-Path -path "txtfilelocated"))
{
Add-Content txtfilelocated -Value $LogFolders
break;
}else{
$File = Get-Content "txtfilelocatedt"
$File | ForEach-Object {
$_ -match $LogFolders
}
}
$File
像这样的
您可以在第一行中指定要检查的目录,以将路径添加到get childitem
cmdlet
$a = get-childitem | ? { $_.psiscontainer } | select -expand fullname #for V2.0 and above
$a = get-childitem -Directory | select -expand fullname #for V3.0 and above
if ( test-path .\list.txt )
{
compare-object (gc list.txt) ($a) -PassThru | Add-Content .\list.txt
}
else
{
$a | set-content .\list.txt
}
非常感谢你!一切正常!谢谢大家!@user22401很高兴帮助您!