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.
これを行うには、いくつかの支援が必要です。