首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何替换Import-CSV以使用单个命令管道

如何替换Import-CSV以使用单个命令管道
EN

Stack Overflow用户
提问于 2018-01-26 08:21:14
回答 1查看 428关注 0票数 0

我有一个powershell脚本,可生成有关AWS IAM用户密码和访问密钥上次使用情况的报告。

我的问题是如何替换Import-Csv,这样就不会创建中间的CSV文件,而是使用单个管道。

我的代码:

代码语言:javascript
复制
$desiredColumns = 'user', 'arn', 'password_last_used', 'access_key_1_last_used_date', 'access_key_2_last_used_date'

# Request the creation of a credential report
Request-IAMCredentialReport

# Get the credential report and save as a CSV file
Get-IAMCredentialReport -AsTextArray > credential_report.csv

# Import the CSV file, select the desired columns and output as an HTML file
Import-Csv credential_report.csv | Select $desiredColumns | ConvertTo-Html > credential_report.html

# Launch the default web browser to view the credential report
start credential_report.html

在veefu的正确答案之后更新

下面是最终的代码:

代码语言:javascript
复制
$desiredColumns = 'user', 'arn', 'password_last_used', 'access_key_1_last_used_date', 'access_key_2_last_used_date'

$reportFile = "credential_report.html"

# Request the creation of a credential report
Request-IAMCredentialReport

# Get the credential report and save as a variable
$data = Get-IAMCredentialReport -AsTextArray

# Process the variable, select the desired columns and output as an HTML file
$data | ConvertFrom-Csv | Select $desiredColumns | ConvertTo-Html > $reportFile

# Launch the default web browser to view the credential report
Invoke-Item $reportFile
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-26 08:33:06

您是否尝试过将输出通过管道传输到ConvertFrom-CSV

代码语言:javascript
复制
Get-IAMCredentialReport -AsTextArray |ConvertFrom-CSV | Select $desiredColumns | ConvertTo-Html > credential_report.html
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48454050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档