Get file info,user info,path,file size

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of David Christian David Christian 3 years, 11 months ago.

  • Author
    Posts
  • #8582
    Profile photo of sainiaman
    sainiaman
    Participant

    Can someone help me to create a power shell.my requirement is that files are posted on sftp and under different folders like folder a, folder b and so on.files would be already there posted in the folders.file names would be same according to different folders.like if folder is a then a_test.txt file would be posted and if folder is b then b_test.txt file would be there.Now if there is a file under folders then i need to capture file size,path of the file,IP of computer who posted it and date posted.

    I would need to run this power shell using a batch file on server.

     

    Can some one help me on this?

  • #8586
    Profile photo of David Christian
    David Christian
    Participant

    Sure we are more than happy to help.

    What have you done so far?

    Is there anything in particular giving you trouble?

  • #8607
    Profile photo of sainiaman
    sainiaman
    Participant

    Hi David,

    I have created this script so far.Email function is working properly so i am not going to write it here.Here is what i have so far:

    $AlertDetails = @(
    @{

    Filepath = "D:\File\A\Folder\";
    FileName=get-childitem Filepath -recurse | where {$_.extension -eq ".dat"} | Format-Table Name
    Fileuploadpath="\A\Folder\"
    extension= "*.dat"
    sourceIP=Get-WmiObject Win32_NetworkAdapterConfiguration | Select IPAddress | Where-Object {$_.IPaddress}
    curretDate = (Get-Date).ToString("yyyy-MM-dd HH:MM:ss")
    },
    @{

    Filepath = "D:\File\B\Folder\";
    FileName=get-childitem Filepath -recurse | where {$_.extension -eq ".dat"} | Format-Table Name
    Fileuploadpath="\B\Folder\"
    extension= "*.dat"
    sourceIP=Get-WmiObject Win32_NetworkAdapterConfiguration | Select IPAddress | Where-Object {$_.IPaddress}
    curretDate = (Get-Date).ToString("yyyy-MM-dd HH:MM:ss")
    }
    )
    $Subject = "Test"

    $sendEmail = $false
    $FindFile = ""
    $unknownErrorSolution = ""
    $EmailContent = ""
    $Fileuploadinfo=""
    $Ondate=""
    $SourceIPinfo=""
    $FileSizeinfo=""
    $Userinfo=""

    foreach ($FileItem in $AlertDetails)
    {
    # Set the file filter = File Path + file name
    $fileFilter = $FileItem.Filepath + $FileItem.FileName

    # Get files
    $files = @(gci $FileItem.Filepath -Filter $fileFilter)

    if ($files.Count -gt 0)
    {# If File exists
    $sendEmail = $true
    $Fileuploadinfo = $Fileuploadinfo + $FileItem.Filepath + $FileItem.FileName + "
    "
    $Ondate=$Ondate + $FileItem.curretDate + "
    "
    $SourceIPinfo=$SourceIPinfo + $FileItem.SourceIP + "
    "
    }
    else
    {# Unknown Error
    $sendEmail = $true
    $unknownErrorSolution = $unknownErrorSolution + "
    "
    }
    }

  • #8635
    Profile photo of David Christian
    David Christian
    Participant

    What is the error message you're getting?

You must be logged in to reply to this topic.