135-1821-9792

PowershellExcelModule-创新互联

参考文档:

池州ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!

https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/25/introducing-the-powershell-excel-module-2/

https://github.com/dfinke/ImportExcel

把Powershell中的数据导出来并能很容易的加工好像一直是一个问题,比如说,导出成CSV格式。

普及一个知识,CVS Comma-Seperated Value 文件。呵呵,我也是刚知道的,以前还纳闷呢。

举个例子,我们以前的做法就是:

Get-Process | Export-Csv c:\Temp\ps.csv #生成CSV文件

Invoke-Item c:\temp\ps.csv  #打开看看

还有一种方法,前提就是那台电脑得安装了EXCEL程序,利用EXCEL COM组件来打开的。如下所示:

$xl = New-Object -ComObject excel.application  #生成一个EXCEL类的实例

$xl.visible = $true  #让这个实例显示出来

$xl.workbooks.add() #添加一个默认的表格

好消息就是现在有一个EXCEL模块来支持了,如果你的电脑的Powershell版本是5.0 可以用以下命令直接安装这个模块,然后就可以直接调用啦,非常强大的功能。

PS C:\> Install-Module importexcel

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy

 value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

安装成功后,非常惊喜的发现:

Get-Process | Export-Excel c:\temp\psnew.xlsx -show

当然这只是一个开始,更强大的功能还在后面呢。打开一个ISE,把下面的代码放进去,运行看一下结果:

rm $file -ErrorAction Ignore

ps |
    where company |
    select Company,PagedMemorySize,PeakPagedMemorySize |
    Export-Excel $file -Show -AutoSize `
        -IncludePivotTable `
        -IncludePivotChart `
        -ChartType ColumnClustered `
        -PivotRows Company `
        -PivotData @{PagedMemorySize='sum';PeakPagedMemorySize='sum'}

Powershell Excel Module

当然,还有一些更不可思议的执行效果:

$ps = ps

$ps |
    Export-Excel .\testExport1.xlsx  -WorkSheetname memory `
        -IncludePivotTable -PivotRows Company -PivotData PM `
        -IncludePivotChart -ChartType PieExploded3D
$ps |
    Export-Excel .\testExport1.xlsx  -WorkSheetname handles `
        -IncludePivotTable -PivotRows Company -PivotData Handles `
        -IncludePivotChart -ChartType PieExploded3D -Show

Powershell Excel Module

Powershell Excel Module

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻标题:PowershellExcelModule-创新互联
分享URL:http://kswsj.com/article/ddoscp.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号