Export-CSV导出长度,但不包括名称 [英] Export-CSV exports length but not name

查看:70
本文介绍了Export-CSV导出长度,但不包括名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从Powershell运行的这段代码.当我在没有export-csv的情况下运行它时,我会在屏幕上看到所有文件夹的名称.

I have this code that I am running from powershell. When I run it without the export-csv i get all the folder names on the screen.

dir | select -expand fullname | % { ($_ -split '\')[7] 

但是,如果我添加| export-csv c:\test.txt,那么我在文件中看到的不是文件夹名,而是在屏幕上看到的.

But if I add | export-csv c:\test.txt then I see following in the file not the folder name I expected just like I see it on the screen.

#TYPE System.String
"Length"
"13"
"18"
"20"
"22"
"29"
"21"
"24"
"11"
"17"
"20"
"20"

推荐答案

Export-Csv导出对象属性及其值的表.由于您的脚本正在生成字符串对象,并且它们具有的唯一属性是长度,所以这就是您所得到的.

Export-Csv exports a table of object properties and their values. Since your script is producing string objects, and the only property they have is length, that's what you got.

如果只想保存列表,请使用Out-FileSet-Content代替Export-Csv.

If you just want to save the list, use Out-File or Set-Content instead of Export-Csv.

这篇关于Export-CSV导出长度,但不包括名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆