我需要out-file
腳本的結果到網絡共享\\prod-automation\exampledir
,我想遞歸刪除30天以前的IIS日誌,但不是文件夾。Out-File to Network共享,寫成hostname.txt
以下是我有:
$WhatIfPreference = $true
$file = ("$($env:computername)$($Filename).txt")
$Directory = "C:\inetpub\logs\LogFiles*"
Get-ChildItem -path $Directory -recurse | Sort-Object Name, LastWriteTime | Format-Table Name, Fullname, LastWriteTime | out-file $file -filepath "\\\PROD-AUTOMATION\PowerShellLogs\IIS_Cleanup" -noclobber
$logpath = "C:\inetpub\logs\LogFiles\"
Get-ChildItem $logpath -recurse *.log -force | where {$_.lastwritetime -lt (get- date).adddays(-0)} | Remove-Item -force
目前的問題是,我得到如下:
Out-File : Cannot validate argument on parameter 'Encoding'. The argument "PROD-CONTOSCO.txt" does not belong to the set "unicode,utf7,utf8,utf32,ascii,bigendianunicode,default,oem" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.
需要一些幫助得到這個打算。
將在早上嘗試。謝謝。 =] –
令人驚歎。這次真是萬分感謝。學到了一課! –
很高興幫助! –