0
美好的一天!将PowerShell保存为csv文件
我想获得您可以在任务栏上看到的打开的应用程序,计算机的IP地址及其用户名。之后,我会将其保存在文本文件中,并用逗号分隔值。现在,我希望将所有内容保存在文本文件中,但在我的代码集中,Get-process
的结果是唯一保存在文本文件中的结果。如何在同一文本文件中包含保存在一起的IP地址和用户名以及来自Get-process
的结果。
这里是我的代码:
$savepath = "C:\Users\$([Environment]::UserName)\Desktop\apps\runningapps.txt"
Get-process | where {$_.mainwindowtitle.length -ne 0} | select name, mainwindowtitle| Export-Csv $savepath -notype
Get-WMIObject -class Win32_ComputerSystem | select username| Export-Csv $savepath -append -notype
Get-WmiObject Win32_NetworkAdapterConfiguration |
Where { $_.IPAddress } | # filter the objects where an address actually exists
Select -Expand IPAddress | # retrieve only the property *value*
Where { $_ -notlike "*:*" }|Export-Csv $savepath -append -notype
感谢您的快速回复先生。我真的很陌生,所以如果我可能会问,我要把它放在哪里? –
用该片段替换您的Export-Csv。这是“出口”分两步,首先转换为CSV字符串,然后将其添加到您的文件 –
感谢它的工作! –