Trying to compress files and move older than 30 days.. Error in script
trying compress files older 60 days...
error:
missing closing '}' in <g class="gr_ gr_62 gr-alert gr_gramm gr_run_anim grammar only-ins doublereplace replacewithoutsep" data-gr-id="62" id="62">statement</g> block.
+ categoryinfo : parsererror: (:) [], parentcontainserrorrecordexception
+ fullyqualifiederrorid : missingendcurlybrace
script
$logfolder=“c:\temp”$arcfolder="\\nafile126.sc.intel.com\software$\temp\archive”
$lastwrite=(get-date).adddays(-30).tostring("mm/dd/yyyy")
if ($logs = get-childitem $logfolder | where-object {$_.lastwritetime -le $lastwrite -and !($_.psiscontainer)} | sort-object lastwritetime)
{
foreach ($l in $logs)
{
$fullname=$l.fullname
$wmifilename= $fullname.replace("\", "\\")
$wmiquery = get-wmiobject -query “select * cim_datafile name='$wmifilename'“
if ($wmiquery.compress()) {write-host "$fullname compressed successfully."-foregroundcolor green}
else {write-host "$fullname not compressed." -foregroundcolor red}
i know bit beyond knowledge of powershell , try understand why.
get-childitem $logfolder -file| where-object { $_.lastwritetime -le [datetime]::today.adddays(-30) } | foreach-object{ $wmifilename = $_.fullname.replace('\', '\\') #' $q = "select * cim_datafile name='$wmifilename'" if($file = get-wmiobject -query $q){ if ($file.compress() -eq 0) { write-host "$fullname compressed successfully." -fore green } else { write-host "$fullname not compressed." -fore red } }else{ write-host 'file not found' } }bit of effort figure out.
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment