powershell - 使用 Powershell 在 CSV 的特定单元格中输入结果

标签 powershell

我有一个 CSV 文件,最后一列(J 列)中有用户名。 我有一个脚本,它将沿着 J 列运行并通过从事件目录中提取信息来显示状态。 我希望它将信息添加到当前用户名旁边的 K 列。 下面是脚本。获取信息效果很好,但我无法将其添加到 K 列。 我放置了一个计数函数(显示 $add1 = $add1 +1 的行),希望能找到一个解决方案,让我可以将结果通过管道传输到 CSV 文件的 K 列 $add1 行中。我认为有一种方法可以做到这一点,但无法弄清楚。 谢谢

enter code here



Import-Module ActiveDirectory
$add1 = 1
Import-csv C:\Temp\newfile.csv | Select -expand MUID | ForEach {          
$add1 = $add1 +1   
Get-ADUser -Identity $_ -Properties st | select -ExpandProperty st

}

最佳答案

你可以这样做:

import-csv C:\Temp\newfile.csv | %{

    $k = Get-ADUser -Identity $_.MUID -Properties st | select -ExpandProperty st
    $_ | add-member -MemberType noteproperty -Name k -Value $k
    $_
}  | export-csv -NoTypeInformation C:\Temp\newfile2.csv

如果 csv 已经有 k 列,您只需将想要的结果分配给 $_.k

关于powershell - 使用 Powershell 在 CSV 的特定单元格中输入结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9623745/

相关文章:

Powershell 小数点后四舍五入

powershell - 在单引号内扩展变量

powershell - PowerShell-带语音输出的多线程

powershell - 如何使用 PowerShell 命令找出已安装的 .NET 框架版本?

powershell - 使用 Get-ADGroup 时隐藏错误

powershell - Powershell命令删除以_开头的所有内容

powershell - PowerShell脚本查找大于10 MB的日志文件并在该文件夹中生成新文件时发送邮件

powershell - 如何使用 Powershell 中的 Edge Selenium webdriver 检查窗口是否最小化

powershell - 是否可以检查 Powershell 中是否给出了 -Verbose 参数?

python - 在 Powershell 下运行 Python 脚本