2

out-fileスクリプトの結果をネットワーク共有に保存する必要があり\\prod-automation\exampledir、30 日以上経過した IIS ログを再帰的に削除したいのですが、フォルダーは削除したくありません。

ここに私が持っているものがあります:

$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.

これを行うには、いくつかの支援が必要です。

4

2 に答える 2

1

試す:

$file = "$env:computername$Filename.txt"
....
out-file -filepath "\\PROD-AUTOMATION\PowerShellLogs\IIS_Cleanup\$filepath" -noclobber
于 2012-11-09T05:46:47.610 に答える
0

次の行に変更してみてください。

out-file -filepath $("\\PROD-AUTOMATION\PowerShellLogs\IIS_Cleanup\" + $filepath) -noclobber
于 2012-11-09T00:29:42.660 に答える