小编SQL*_*ins的帖子

Powershell时间戳

我正在尝试将日志导出到 powershell 中的 csv 文件,但我很难为文件中的每个“日志”放置时间戳。我可以将日志导出到 csv 文件中,但对于它记录的每个操作,我想要一个单独的时间戳。例如,我希望 csv 文件中的输出如下所示,并且每个输出都有一个时间戳(请注意操作之前的时间戳)

2020/02/13 93520 - Performing the operation "Remove File" on target "\\03042019-PC\C$\Users\*\AppData\Local\Apps\Test\21.txt". 

2020/02/13 93522 - Performing the operation "Remove File" on target "\\03052019-PC\C$\Users\*\AppData\Local\Apps\Test\51.txt".  
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!这是我到目前为止所得到的:(来自在线研究)

Import-Module ActiveDirectory


$timestamp = "LogFile"

$filepath = "C:\$timestamp.csv"


#$Computers = Get-ADComputer -Filter {Name -like "*-PC"} | Select-Object -ExpandProperty Name 
$Computers = Get-ADComputer -Filter {Name -like "03*2019-PC"} | Select-Object -ExpandProperty Name 

# Loop through users and delete the file

ForEach ($Computer in $Computers) {

    $path = "\\$Computer\C$\Users\*\AppData\Local\Apps\Test\*"
    $result = …
Run Code Online (Sandbox Code Playgroud)

powershell datetime

2
推荐指数
1
解决办法
8874
查看次数

标签 统计

datetime ×1

powershell ×1