0
votes

I have the following to folders:

V:\100 Migrering til Dalux\ES 
E:\ES

I'd like to compare the folder and sub folder names to make sure they are similar.
I've been trying to get the following code to work without success:

$ES = Get-ChildItem -Recurse -path E:\ES
$ES = Get-ChildItem -Recurse -path V:\100 Migrering til Dalux\ES

Compare-Object -ReferenceObject $ES -DifferenceObject $ES

Edit:I get the following error:

Get-ChildItem : A positional parameter cannot be found that accepts argument 'til'. At line:3 char:7

  • $ES = Get-ChildItem -Recurse -path V:\100 Migrering til Dalux\ES
  •   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
1
What does "without success" look like? Any errors thrown? If so, what do the error messages say?Mathias R. Jessen
You need to quote paths with spaces. 'V:\100 Migrering til Dalux\ES'Doug Maurer
As @DougMaurer says, but also, you are using the exact same variable for both lists so you are trying to compare a directory list to itself, AND is (as the title says) you want to compare only folder names, not files inside these, you should add switch -Directory to the Get-ChildItem callsTheo

1 Answers

0
votes

You have 2 errors.

  1. You have space into your path of directory
  2. You use the same variable to compare.

Try something like this :

$ES1 = Get-ChildItem -Recurse -path "E:\ES"
$ES2 = Get-ChildItem -Recurse -path "V:\100 Migrering til Dalux\ES"

Compare-Object -ReferenceObject $ES1 -DifferenceObject $ES2