powershell:add-content

add-content命令,主要是向文件中添加内容

  • 主要参数有两个,-path用来指定路径,-value用来指定要添加的内容,暂时只知道这两个参数
  • 下面是例子
    • add-content -path *.txt -exclude help* -value "END" 
      这个命令是向在当前目录的所有txt文件添加"END"这个内容,但是以help开关的txt文件除外,-exclude 用来排除不符合要求的文件
    • add-content -Path file1.log, file2.log -Value (get-date) -passthru 
      这个命令是向fiel1.log和file2.log文件中添加日期,日期对象通过get-date这个命令获取,如果-value的值是对象,则用括号括起来。加上-passthru参数,会把get-date获取的对象输入到终端上。
    • add-content -path monthly.txt -value (get-content c:
      ec1weekly.txt) 
      这个命令是把当前目录的weekly的内容加入到monthly.txt这个文件中,是从末尾开始插入,而不是覆盖. get-content是获取文件内容的命令,加括号的作用是保证在执行add-content的时候,get-content已经执行完毕
    • add-content -value (get-content test.log) -path C:	ests	est134logs	est134.log 
      这个命令的作用是先获取文件的内容,再把这个内容完全得到一个新文件中,test134.log可以不存在,add-content命令会创建这个文件
原文地址:https://www.cnblogs.com/popping57/p/3208152.html