Get file info,user info,path,file size

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?

Sure we are more than happy to help.

What have you done so far?

Is there anything in particular giving you trouble?

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 + “<br />”
$Ondate=$Ondate + $FileItem.curretDate + “<br />”
$SourceIPinfo=$SourceIPinfo + $FileItem.SourceIP + “<br />”
}
else
{# Unknown Error
$sendEmail = $true
$unknownErrorSolution = $unknownErrorSolution + “<br />”
}
}

What is the error message you’re getting?