我需要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.
需要一些帮助才能完成这项工作。