如何在导出为CSV之前为每行添加日期/时间(How to Add Date/Time to Each Line before exporting to CSV)
我有一个很棒的工作PowerShell函数,叫做PSO。 PSO功能基于给定的输入/参数搜索一个或多个特定的窗口过程。 当一个进程名与searchparameter匹配时,它会将进程所有者和更多信息导出/附加到csv文件。 到目前为止都很好。
现在我真的想在PowerShell写入csv的每一行中添加日期和时间信息。 我一直在苦苦挣扎一段时间。 我在VBScript中有类似的工作,但我真的开始喜欢powershell,喜欢看到和了解更多。
在PSO函数下面,我假设这是应该生成和添加日期和时间的区域......对吗?
Function Get-PSO($searchString) # http://powershell.com/cs/blogs/tips/archive/2009/12/17/get-process-owners.aspx # Usage: Get-PSO * OR Get-PSO exp*,*paint*,calc*,notepad* # Sample Export2csv: Get-PSO notepad* | Export-CSV $env:userprofile\desktop\export.csv -Append # A few date/time formats for later use... i hope $date=(Get-Date -format "yyyy-MM-d") $time=(Get-Date -format "HH:mm:ss") $datetime=(Get-Date -format "yyyy-MM-d HH:mm") $foundProcess = ps $searchString -ea silentlycontinue if($foundProcess -eq $null) { return; } $foundprocess | % { gwmi Win32_Process -Filter ("Handle={0}" -f $_.id ) | % { Add-Member -TypeName Type -InputObject $_ -MemberType NoteProperty -Name Owner -Value ($_.GetOwner().User) -PassThru } | # See below my last attempt to get this tot work # % { Add-Member -TypeName Type -InputObject $_ -MemberType NoteProperty -Name Owner -Value ($_.GetOwner().User) -MemberType NoteProperty -Name Date -Value $date -PassThru } | select Name, Handle, Owner, Type }
当我运行该功能; Get-PSO记事本* | Export-CSV $ env:userprofile \ desktop \ export.csv -Append)我得到以下结果:
名称;处理;所有者;类型
。记事本++ exe文件; 7736;戴夫;
我喜欢添加日期/时间,结果应该类似于:
名称;处理;所有者,日期,时间,日期时间,类型
notepad ++。exe; 7736; Dave; 5-4-2015; 20:07; 5-4-2015 20:07;
任何人? 一些帮助或想法将非常感激。
I've got a nice working powershell function called PSO. The PSO function searches for one or more specific windows processes based on the given input/parameter. When a procesname matches the searchparameter it exports/appends the process owner and more info to a csv file. All good so far.
Now I really like to add date and time info to each line PowerShell writes to the csv. I've been struggling with it for a while now. I've got somehting simular working in VBScript, but i'm really starting to like powershell and like to see and learn more.
Below The PSO Function, I assume this is the area where Date and Time should be generated and added... right?
Function Get-PSO($searchString) # http://powershell.com/cs/blogs/tips/archive/2009/12/17/get-process-owners.aspx # Usage: Get-PSO * OR Get-PSO exp*,*paint*,calc*,notepad* # Sample Export2csv: Get-PSO notepad* | Export-CSV $env:userprofile\desktop\export.csv -Append # A few date/time formats for later use... i hope $date=(Get-Date -format "yyyy-MM-d") $time=(Get-Date -format "HH:mm:ss") $datetime=(Get-Date -format "yyyy-MM-d HH:mm") $foundProcess = ps $searchString -ea silentlycontinue if($foundProcess -eq $null) { return; } $foundprocess | % { gwmi Win32_Process -Filter ("Handle={0}" -f $_.id ) | % { Add-Member -TypeName Type -InputObject $_ -MemberType NoteProperty -Name Owner -Value ($_.GetOwner().User) -PassThru } | # See below my last attempt to get this tot work # % { Add-Member -TypeName Type -InputObject $_ -MemberType NoteProperty -Name Owner -Value ($_.GetOwner().User) -MemberType NoteProperty -Name Date -Value $date -PassThru } | select Name, Handle, Owner, Type }
When I run the function ; Get-PSO notepad* | Export-CSV $env:userprofile\desktop\export.csv -Append) I get the following result:
Name;Handle;Owner;Type
notepad++.exe;7736;Dave;
I like to Add Date/Time and the result should look something like:
Name;Handle;Owner;Date;Time;DateTime;Type
notepad++.exe;7736;Dave;5-4-2015;20:07;5-4-2015 20:07;
Anyone? some help or ideas would be very much appreciated.
原文:https://stackoverflow.com/questions/29460853
最满意答案
相关问答
更多-
主标记是否也具有分组相关元素的含义 仅与组相关元素的程度相同。
的主要目的是指示页面的主要内容的开始位置。 (此外,根据WHATWG规范,但不是W3C规范,页面的主要内容恢复 )。 或者在这种情况下是否应该在部分标签内? 分段标记是对内容进行分组的一种方式,用于指示其内容在特定主题上,其方式与不在该部分中的内容不同。 通常情况下,您可以并且应该使用 元素为该部分提供标题,该元素说明了该主题是什么。 将单个元素(如图像)包装到节标记中是否有意义? 很少。 有一件事意味着该部 ... 我设法解决了我的问题。 仍然不确定这是否是最好的解决方案,但我想让别人知道,以防其他人需要相同的解决方案。 所以这是怎么回事,我有以下流程:controller - > {Velocity engine} - >本地化jtable配置 - > jsp 控制器获取模型并将其提供给速度模板。 在那里我也提供(除了我的速度模板模型):messageSource和localeResolver。 无论我在速度上有本地化标签,我都按如下方式编写它们:$ {messageSource.getMessage($ {fiel ...如果要使用内置表单处理功能,将字段分成两个输入可能会变得复杂。 一种更简单的方法可能是在数据库表中包含两个附加字段,并将组合的“邮政编码”字段作为计算字段: db.define_table('user_address', Field('street_address', 'string', requires=IS_NOT_EMPTY()), Field('city', 'string', requires=IS_NOT_EMPTY()), Field('country', 'stri ...import re # use table text find comment text table_text = soup.find(text=re.compile('table class="adv sortable stats_table"')) # use bs4 to parse the text table_soup = BeautifulSoup(table_text, 'lxml') # find_all .... table_soup.find_all('tr') import r ...居中两个
标记彼此相邻(Center two [2023-08-23]tags next to each other) 这样做的现代和简单的方法是使用flexbox。 你可以通过给容器div(或者div - main,article等的任何语义版本)提供以下属性来实现: #container { display: flex; justify-content: center; }Content Content 你的选择器$('.nav navbar-nav')是错误的。 它应该是: $('.nav.navbar-nav').append(nav) Your selector $('.nav navbar-nav') is wrong. It should be: $('.nav.navbar-nav').append(nav)这个表单如何与[2020-01-19]
有一些javascript(你可以在html-source的底部找到它,就在body关闭之前): function updateArea() { var allVals = []; $('.areas :checked').each(function (i) { allVals.push((i != 0 ? "\r\n" : "") + $(this).val()); }); $('#wantedArea').val(allVals).attr('rows', ...获取simplexml以了解没有自闭标签的输入?(Getting simplexml to understand input that have no self closing tags?)[2023-08-07]
有一个技巧: DOM扩展可以解析HTML ,包括你在这里的非闭合标签; 和SimpleXML可以“导入”一个DOM对象 (实际上没有重新解析任何东西,因为它们在下面使用相同的内存结构)。 它应该像下面这样简单: $dom = new DOMDocument; $dom->loadHTML($html); $sx = simplexml_import_dom($dom); There is a trick for this: the DOM extension can parse HTML, includi ...这是你的h1在父母之外坍塌的边缘。 有很多方法可以修复它,所以我只删除了h1上的上边距。 这是一个资源 - https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing 如果没有边框,填充,内联内容,block_formatting_context创建或间隙将块的边缘顶部与其第一个子块的边缘顶部分开,或者没有边框,填充,内联内容,高度,最小高度,或者max-height将块的边距底部与其最 ...选择其中包含和
标记的所有