2012-11-09 19 views
2

我需要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. 

需要一些幫助得到這個打算。

回答

1

嘗試:

$file = "$env:computername$Filename.txt" 
.... 
out-file -filepath "\\PROD-AUTOMATION\PowerShellLogs\IIS_Cleanup\$filepath" -noclobber 
+0

將在早上嘗試。謝謝。 =] –

+0

令人驚歎。這次真是萬分感謝。學到了一課! –

+0

很高興幫助! –

0

嘗試改用這一行:

out-file -filepath $("\\PROD-AUTOMATION\PowerShellLogs\IIS_Cleanup\" + $filepath) -noclobber 
+0

出文件:文件名,目錄名或卷標語法不正確。差不多了。我應該說,路徑已經過驗證,我可以訪問它。 –

+0

對於未來的讀者,我在答案中有一個額外的'\',這就是上述錯誤的來源。 – Nick