Unexpected token ‘in’ in expression or statement.

Home Forums Scripting PowerShell Unexpected token ‘in’ in expression or statement.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    sameer12
    Member
    #167112

    Hi Experts !

    I am finding the error while running the powershell script , please help to fix it.

    D:ReplicationViaFTPServer>DeleteBackupsOlderthen. bat

    D:ReplicationViaFTPServer>powershell .DeleteBackupsOlderthen.ps1
    Unexpected token ‘in’ in expression or statement.
    At D:ReplicationViaFTPServerDeleteBackupsOlderthen. ps1:19 char:12
    + if($File in < <<< $Files)
    + CategoryInfo : ParserError: (in:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

    D:ReplicationViaFTPServer>

    Script

    Code:
    # POWER SHELL TO DELETE LOGS FILES FROM SERVER OLDER THEN X DAYS
    # DEFINE PARAMETERS
    # GET CURRENT DATE
    $Now = Get-Date
    # DEFINE AMOUNT OF DAYS
    $Days=”1″
    # Define folder where files are loacted
    $Targetfolder =’D:ReplicationViaFTPServer’
    #define extention
    $Extention =”*trn”
    # define last writed time parameters based on $days
    $LastWrite = $Now.AddDays(-$Days)
    #get files based on last write filter and specific folder #
    $File = Get-Childitem $TargetFolder-Include $Extention -Recurse | Where {$_.LastWriteTime
    -le
    “$LastWrite”}
    foreach($File in $Files)
    {
    if($File in $Files)
    {
    if($File -ne $NULL)
    {
    Write-host “Deleting File $File” -Foregroundcolor “DarkRed”
    Remove-Item $File.FullName | out-null
    } else {
    Write-Host “No more files to delete!” -foregroundcolor “Green” }
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.