خرید بک لینک

I am new to powershell. I need to gather lastbootup time of a list of computers and then write the output into a csv file.

pclist.txt contains below contents

computer1
computer2

output.txt with below expected results

computer1, 2016/02/22 09:01:00 am
computer2, 2016/01/01 09:10:00 am

From http://www.howtogeek.com/141495/geek-school-writing-your-first-full-powershell-script/, I got a lastboot.ps1 script that could display the results for each computer:

param(
[Parameter(Mandatory=$true)][string]$ComputerName
)
Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName | 
Select-Object -Property CSName,@{n="Last Booted";
e={[Management.ManagementDateTimeConverter]::ToDateTime($_.LastBootUpTime)}}

e.g.

powershell -executionpolicy bypass .lastboot.ps1 Computer1

CSName                                  Last Booted
------                                  -----------
Computer1                               11/18/2015 3:04:13 PM

So how to read line from pclist.txt and then format the output into a csv file?

For the output file name, could it be specified according to date/time and filename, e.g. 20160222-pclist.txt.log.

In Batch file, this is rather easy

for /F "tokens=1,8" %%i in (%%1) do (
some-command >> %date:~10,4%%date:~7,2%%date:~4,2%-%%1.log
)

20160222-pclist.txt.log

- - , .

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 3 اسفند 1394 ساعت: 11:47

صفحه بندی