0
Get-ADDomainController -Filter * | Select-Object Name, @{n="Hash";e={Get-FileHash \\$_.Name\netlogon\site\logon.bat}}

Output

Name      Hash
----      ----
DC001
DC002

Any ideas why this isn't working. It's been a while since I used a hash table to pull information like this, so I must be missing something minor. I have also tried to just return the name, Get-Childitem, which doesn't work. I have also tried just $_.Name, which does work and returns a string.

I am trying to verify the file exists and is the same on all DCs.

Ocaso Protal
  • 19,362
  • 8
  • 76
  • 83
CoryC
  • 1
  • 1
  • 4
    `Get-FileHash "\\$($_.Name)\netlogon\site\logon.bat"`. The quotes aren't technically necessary in this case but I do think they clarify that we're using string interpolation. – Jeroen Mostert Mar 14 '23 at 12:36
  • In short: Only variables _by themselves_ can be embedded as-is in expandable strings (`"..."`) (which command arguments situationally _implicitly_ are), e.g. `"foo/$var"` or `"foo/$env:USERNAME"`. To embed _expressions_ or even commands, you must enclose them in `$(...)`. Notably, this includes property and indexed access (e.g., `"foo/$($var.property)"`, `"foo/$($var[0])"`). See the linked duplicate for details. – mklement0 Mar 14 '23 at 16:08

0 Answers0