Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Thu Jul 19, 2018 5:30 am
Hi Folks,
I need some help in modifying the PowerShell script to compare the date time created and file size for the multiple AD Domain Controllers servers shared folder
Example of the UNC path to compare:
Source will be first copied to this reference folders\\PRODDC01-VM\sysvol\domain.com\LogonScripts
Code: Select all
\\PRODDC02-VM\sysvol\domain.com\LogonScripts
\\PRODDC03-VM\sysvol\domain.com\LogonScripts
…
\\PRODDC29-VM\sysvol\domain.com\LogonScripts
This is the script that I have but not working:
Code: Select all
Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))" | ForEach-Object {
"Processing $($_.DNSHostName) ..." | Write-Host
$folderReference = "\\PRODDC01-VM\sysvol\domain.com\LogonScripts"
$folderDifference = "\\$_.DNSHostName\sysvol\domain.com\LogonScripts"
$FolderReferenceContents = Get-ChildItem $folderReference -Recurse | where-object { -not $_.PSIsContainer }
$FolderDifferenceContents = Get-ChildItem $folderDifference -Recurse | where-object { -not $_.PSIsContainer }
#Get only files that are NOT on the reference server
Compare-Object -ReferenceObject $FolderReferenceContents -DifferenceObject $FolderDifferenceContents -Property ('Name', 'Length') -PassThru |
where-object { $_.SideIndicator -eq '=>' } | Select FullName
} | Export-Csv -Path C:\SYSVOL-Script.CSV -NTI
Any help would be greatly appreciated.
Thanks,
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu Jul 19, 2018 6:18 am
You cannot do this:
$folderDifference = "\\$_.DNSHostName\sysvol\domain.com\LogonScripts"
It must be this:
$folderDifference = "\\$($_.DNSHostName)\sysvol\domain.com\LogonScripts"
Subexpression evaluation must be used for an object's properties.
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Thu Jul 19, 2018 11:46 pm
jvierra wrote: ↑ Thu Jul 19, 2018 6:18 am
You cannot do this:
$folderDifference = "\\$_.DNSHostName\sysvol\domain.com\LogonScripts"
It must be this:
$folderDifference = "\\$($_.DNSHostName)\sysvol\domain.com\LogonScripts"
Subexpression evaluation must be used for an object's properties.
yes, you are right.
however, there is no result at the.CSV file and there is nothing showing on the PowerShell console either?
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Fri Jul 20, 2018 12:03 am
You will have to debug the script since we cannot run it.
Do the script at a prompt one line at a time and check the results.
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Fri Jul 20, 2018 12:05 am
This is the updated script as per your suggestion:
The output on the console is correct:
Processing PRODDC01-VM...
Processing PRODDC02-VM...
Processing PRODDC03-VM...
...
Processing PRODDC29-VM...
Code: Select all
$folderReference = "\\PRODDC01-VM\sysvol\domain.com\LogonScripts"
Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))" | ForEach-Object {
"Processing $($_.DNSHostName) ..." | Write-Host
$folderDifference = "\\$($_.DNSHostName)\sysvol\domain.com\LogonScripts"
$FolderReferenceContents = Get-ChildItem $folderReference -Recurse | where-object { -not $_.PSIsContainer }
$FolderDifferenceContents = Get-ChildItem $folderDifference -Recurse | where-object { -not $_.PSIsContainer }
#Get only files that are NOT on the reference server
Compare-Object -ReferenceObject $FolderReferenceContents -DifferenceObject $FolderDifferenceContents -Property ('Name', 'Length') -PassThru |
where-object { $_.SideIndicator -eq '=>' } | Select FullName
} | Export-Csv -Path C:\TheDifferencesAre.CSV -NoTypeInformation
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Fri Jul 20, 2018 12:11 am
No. You have to debug it a line at a time.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Fri Jul 20, 2018 12:17 am
Note that the correct method of using this is:
Compare-Object $a $b |Where {$_.SideIndicator -eq '=>'} | Select InputObject
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked