我一直在寻找关于这个问题的帮助几个小时,没有运气。我的脚本监视一个文件夹,查找大于12分钟以'.tmp'结尾的文件。然后它删除'.tmp'。这部分工作正常。输出文本文件以识别PowerShell中的操作文件
我希望脚本输出一个文本文件,其中包含重命名文件的文件名。使用下面的脚本,文本文档是空的。
#Computer name from Description
$ComputerName = Get-WmiObject -Class Win32_OperatingSystem | Select Description
$ComputerName = "$ComputerName".split("}")
$ComputerName = "$ComputerName".split("=") | Select-Object -Last 1
$ComputerName = "$ComputerName".split(" ") | Select-Object -First 1
#$ComputerName = $env:computername
Write-Host "This is the computer name: $ComputerName"
$c1Output = 'E:\' + $ComputerName + '\Capture One Session\Output\Market\'
get-childitem -Path "$c1Output" -Filter *.tmp |
where-object {$_.LastWriteTime -lt (get-date).AddMinutes(-12)} |
rename-item -newname { $_.name.substring(0,$_.name.length-4) }
out-file \\server\Report.txt
这应该很容易理解,但是我对PowerShell仍然很陌生。
谢谢!
很多faff的获取计算机名称。可以用$ env得到:Computername –
嘿詹姆斯,它实际上是拉'描述'而不是'名字'。我很想知道一个更快的方法来实现这一点! – Garrett