This …
$computers = Get-ADComputer -Filter *
$Computers.DNSHostName only give the DNS host name string
DC01.contoso.com
EX01.contoso.com
...
So, you can’t do this at all, as you are trying, as noted by you already.
# Past the DnsHostName down the pipeline and match then name against Hostname and profiles
$Computers.DNSHostName | select-string -pattern $imported.Hostname -and $imported.Profiles -not $null -simplematch -notmatch
So,
($computers = Get-ADComputer -Filter * -Properties *)[0]
($adusers = Get-ADUser -Filter * -Properties *)[0]
There is no Hostname or profiles property on Get-ADComputer or Get-ADUser
So, you need to provide all the properties you need, then compare
Simplify Your PowerShell Code by Using a Compound Where Clause
https://blogs.technet.microsoft.com/heyscriptingguy/2012/04/14/simplify-your-powershell-code-by-using-a-compound-where-clause
Snippet from the article —
Where clause, the writer had the following:
where {($_.status -eq "Running") -and ($_.CanStop -eq $true)}
As I mentioned, it works. But it can be shortened by saying –and $_.CanStop. Here we are saying, “Does the CanStop property exist on the object?” If it does, this is all we want. Therefore, I can reduce this by saying, “Does it exist?” This is shown here.
where { $_.status -eq 'running' -and $_.canstop }
The nice thing is that I can negate the Boolean value. For example, if I want the running services that do NOT accept a Stop command, I have several choices. I would probably use the Not operator (!). This is shown here.
where { $_.status -eq 'running' -AND !$_.canstop }
Most of the time, I will use grouping around the Boolean value to make the code a bit clearer. This is shown here.
where { $_.status -eq 'running' -AND !($_.canstop)
If you do not like the exclamation point (!) for the Not operator, you also can use the –not operator. This is shown here.
where { $_.status -eq 'running' -AND -not $_.canstop }
Once again, I generally put grouping around the Boolean value to make the command easier to read (at least for me). This is shown here.
where { $_.status -eq 'running' -AND -not ($_.canstop) }