[英]Powershell saving as csv file
美好的一天!
我正在嘗試獲取打開的應用程序,您可以在任務欄上看到該計算機的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
我認為您的問題是因為要導出的三個對象具有不同的屬性,您遇到了麻煩嗎?
如果您真的想將所有內容放在一個文件中,則可以
ConvertTo-Csv -notype | Add-Content $savepath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.