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 回答