Powershell compare folders

Hello

I’m looking for a command to compare to folder with powershell.
I know already the following command

Compare-Object -ReferenceObject  $Dir1 -DifferenceObject  $Dir2

But this is not what I want. I only get where to find different files.
What I want is to see within Dir1 and Dir2 where to find different or missing folder.

e.q.

Content of Dir1:
directory C:\test\1
directory C:\test\2
directory C:\test\3
directory C:\test\3\1

Content of Dir2:
directory C:\test2\1
directory C:\test2\3

I tried to work with -Property , but could not find which parameter are availabe.
I could not find a parameter to show me the full path in the result.

Any help?
Thanks

It depends pretty much on what you provide for the Compare-Object. If you’re only looking for differences in the folders I’d provide only folder paths. :man_shrugging:t3:

How do you populate $Dir1 and $Dir2?

I read the directories from a file

$Zeile in Get-Content $ImportDatei
$lDir1,$Dir2 = $Zeile -split ";"
$Content1   = Get-ChildItem -Recurse -path $Dir1
$Content2   = Get-ChildItem -Recurse -path $Dir2
Compare-Object -ReferenceObject  $Content1 -DifferenceObject  $Content2

is this what you mean?

Hmmm … not quite … how do you populate $Zeile then?

$Zeile in Get-Content $ImportDatei

Oh wow … OK, what is in the variables you want to compare? Only folders or folders and files? If there are files as well you may change this to only include folders. :man_shrugging:t3:

I just edited the script above

in the variables are only folders which I want to compare to see if there are missing folders in the second directory.

OK. And what’s actually your issue then?

I want to make the script a little more versatile and I would like to see the full path auf the directory and subdirectories. Now I get only different folder names in the result and and do not know the associated directory.

And maybe I could do it even more versatile and have an extra option to show also different files.

Let’s focus on one issue at a time. :smirk:

What exactly is the content of $Dir1 and $Dir2??? According to your initial question there are complete paths?! :man_shrugging:t3:

You may show the sample content of the two variables you want to compare AND the expected output. Please post the raw text and format it as code.

Regardless of that: Sometimes it’s easier to explain a situation in your native language. There is a good German forum focused on Windows topics including a good scripting sub forum:
https://www.mcseboard.de/forum/71-windows-forum-—-scripting/

$Zeile = C:\test;C:\test2
$Dir1 = 'C:\test'
$Dir2 = 'C:\test2'

the output looks like this

InputObject SideIndicator
----------- -------------
2           <=           

That’s not what I asked for. :smirk:

Wie soll die Ausgabe aussehen???

instead of

InputObject SideIndicator
----------- -------------
2           <=           

I would like to see

InputObject SideIndicator
----------- -------------
C:\test\2           <=           

I actually don’t know how you come to this output:

When I run this code snippet:

$Dir1 = 'C:\test'
$Dir2 = 'C:\test2'

Compare-Object -ReferenceObject $Dir1 -DifferenceObject $Dir2

The output looks like this:

InputObject SideIndicator       
----------- -------------       
C:\test2    =>
C:\test     <=

:man_shrugging:t3:

Edit:

The solution was to extract the FullName property of the folders to compare …

$Content1   = Get-ChildItem -Recurse -Path $Dir1 -Directory | Select-Object -ExpandProperty FullName
$Content2   = Get-ChildItem -Recurse -Path $Dir2 -Directory | Select-Object -ExpandProperty FullName