[英]REMOVE FIRST LINE from TEXT file AFTER running a script in POWERSHELL
I've put a script together that captures all the computers in an active directory and imports that list into a .txt file. 我将一个脚本放在一起,以捕获活动目录中的所有计算机,并将该列表导入到.txt文件中。 This works fine, however, when I open the .txt file I noticed that the first line is blank.. I referred back to my code and saw that I've got my table headers set to "-HideTableHeaders" when I removed this, it displayed the table header.. my question is how do I remove th table header completely and start the generated results from the FIRST LINE.. instead of having a header there or a blank line.
这样做很好,但是,当我打开.txt文件时,我注意到第一行是空白。.回到我的代码,我发现删除该表头时将其表头设置为“ -HideTableHeaders”,它显示了表头。.我的问题是如何完全删除表头,并从第一行开始生成结果。.而不是在那里有头或空行。 See code below:
参见下面的代码:
$location = // location where I save my outputfile
Get-ADComputer -Filter [Name -like "test*" } - Property * | Format-table Name -auto -HideTableHeaders | out-file $location
Things I've tried: 我尝试过的事情:
1) Removed "-HideTableHeaders" 1)删除了“ -HideTableHeaders”
2) Tried adding "select-object -skip 1" 2)尝试添加“选择对象-跳过1”
I don't think its a major issue having the first line blank or having a header name, its just for personal knowledge, I want to know how to set the output result so it starts from the FIRST line. 我认为这不是主要问题,因为第一行是空白或标题名称,这仅仅是出于个人知识,我想知道如何设置输出结果,使其从FIRST行开始。
Help will be much appreciated. 帮助将不胜感激。
Thanks, 谢谢,
Sohail. 苏海尔。
Rule number 1 in PowerShell, never do formatting in the middle of your code. PowerShell中的规则编号1,永远不要在代码中间进行格式化。 Keep the formatting CmdLets for last.
最后保留格式CmdLets。 So in this case you don't need to use
Format-Table
as it breaks the pipeline and is only useful for visual representation in the console, not for output to files: 因此,在这种情况下,您不需要使用
Format-Table
因为它会中断管道,并且仅对控制台中的可视表示有用,而对于输出到文件不起作用:
$location = 'S:\Test\Out_Test\File.txt'
Get-ADComputer -Filter {Name -like "Test*"} -Property * |
Select-Object -ExpandProperty Name | Out-File $location
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.