Hi Folks,
Hoping for some advice - another set of eyes to tackle an issue. I have a text/CSV file containing details
Server,MasterID,WebsiteName,Rootfolder ABCD,12234,mysite.com,e:\websites\mysite EFGH,12331,another.com,e:\websites\another
This file is pulled down to a Automation Server /Powershell server so it can be used to hold details on which remote servers to connect to and get some info about files/folders.
$Alldata = Import-CSV -Path $File
foreach ($item in $allData) {
$session = New-PSSession -ComputerName $item.Server -Credential $creds
$output += Invoke-Command -Session $session `
{Get-ChildItem -File -Path $ite.rootfolder -Recurse
| Select-Object FullName,@{N='LastUpdated';
Expression={Get-Date -Date $_.LastWriteTime -Uformat "%d-%m-%Y %R"}},@{N='MD5';Expression={(Get-FileHash $_.FullName).Hash}} }
So this gives me something like:
FullName LastUpdated MD5 PSComputerName RunspaceId -------- ----------- --- -------------- ---------- E:\websites\mysite\www\default.aspx 15-07-2020 14:54 EF165CB4 ABCD dced3d40 E:\websites\mysite\www\other.aspx 15-07-2020 14:55 EF165CB1 ABCD dced3d40 E:\websites\another\www\default.aspx 24-07-2020 07:16 4F361B43 EFGH 0d731a90 E:\websites\another\www\and.aspx 24-07-2020 07:16 4F361B42 EFGH 0d731a90
Which is great, BUT - I am wondering how can I get values from the original CSV file added to that?
What I mean is - I need to also have the values from the CSV (ie. Server, MasterId, Websitename added to each beginning line of the output and get rid of the PsComputerName and RunSpaceId)
So the end result I need would be:
Server MasterID FullName LastUpdated MD5 ------ -------- -------- ----------- --- ABCD 12334 E:\websites\mysite\www\default.aspx 15-07-2020 14:54 EF165CB4 ABCD 12334 E:\websites\mysite\www\other.aspx 15-07-2020 14:54 EF165CB1 EFGH 12331 E:\websites\another\www\default.aspx 24-07-2020 07:16 4F361B43 EFGH 12331 E:\websites\another\www\and.aspx 24-07-2020 07:16 4F361B42
The aim is to create a text file on the automation server that has that output.
Any ideas/thoughts on best way to approach this?