我有一个powershell脚本,可生成有关AWS IAM用户密码和访问密钥上次使用情况的报告。
我的问题是如何替换Import-Csv,这样就不会创建中间的CSV文件,而是使用单个管道。
我的代码:
$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的正确答案之后更新
下面是最终的代码:
$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发布于 2018-01-26 08:33:06
您是否尝试过将输出通过管道传输到ConvertFrom-CSV
Get-IAMCredentialReport -AsTextArray |ConvertFrom-CSV | Select $desiredColumns | ConvertTo-Html > credential_report.htmlhttps://stackoverflow.com/questions/48454050
复制相似问题