I am writing a script to replicate folder and multiple subfolders inside it on two servers. Each folder having multiple files. I wrote below code to compare current folder names and number of files in each from Server1 (source) to Server2 (target where replication is required),
I am able to write PRODFLDFILECount variable output to .csv, what I want is to add another variable COBFLDFILECount output in same CSV file after used column range.
Desired output in CSV as below:
################# Folder count on PROD and file count in each folder #####################
`$PRODFLDFileCount = Get-ChildItem -LiteralPath $SRCLPRODCAS -Directory | ForEach-Object {
[pscustomobject] @{
'Prod Folder' = $_.Name
'File Count' = @(Get-ChildItem -LiteralPath $_.FullName -File -Recurse).Count }
}
$PRODFLDFileCount |Export-Csv -Path C:Tempdata.csv -NoTypeInformation
################# Folder count on COB and file count in each folder #####################
$COBFLDFileCount = Get-ChildItem -LiteralPath $TRGTLCOBCAS -Directory | ForEach-Object {
[pscustomobject] @{
'COB Folder' = $_.Name
'File Count' = @(Get-ChildItem -LiteralPath $_.FullName -File -Recurse).Count }
}
$COBFLDFileCount |Export-Csv -Append -Path C:Tempdata.csv -NoTypeInformation`
Variable PRODFLDFileCount output:
Prod Folder File Count
------------ -----------
test 122
dm001 13
dm002 284
dm33 322
dms0011 6
Variable COBFLDFileCount output:
COB Folder File Count
------------ -----------
test 11
dm001 13
dm002 2
dm33 32
dms0011 0