我一直在尋找關於這個問題的幫助幾個小時,沒有運氣。我的腳本監視一個文件夾,查找大於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