简体   繁体   English

Powershell导出到文本文件

[英]powershell exporting to text file

I'm working on a script that checks folders in specific directory. 我正在研究一种检查特定目录中的文件夹的脚本。 For example, I run the script for first time, it generates me a txt file containing folders in the directory. 例如,我第一次运行该脚本,它将为我生成一个txt文件,其中包含目录中的文件夹。

I need the script to add any new directories that are found to the previously created txt file when the script is run again. 我需要脚本来在再次运行脚本时将找到的所有新目录添加到以前创建的txt文件中。

Does anyone have any suggestions how to make that happen? 有没有人建议如何实现这一目标?

Here is my code so far: 到目前为止,这是我的代码:

$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

something like this? 这样的东西?

You can specify what directory to check adding path to get-childitem cmdlet in first line 您可以指定要检查的目录,并在第一行中将路径添加到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    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM