I might be overthinking this, but have been unable to get this simple code edit to work with Powershell
This works fine
Get-ADComputer -Filter "operatingsystem -like "Windows server 2012"
However, i'd like to use a variable such as $ServerOS = "Windows server 2022"
And then using that variable inside the same code, such as this
Get-ADComputer -Filter "operatingsystem -like "$EOLOS"
However, as the -filter uses 'single' quotes, it doesn't work. How would I edit the code to make the variable work?
Get-ADComputer -Filter "operatingsystem -like "Windows server 2012"
What I did is to split the filter parameter, insert it into a variable and call the entire variable as the filter.
With your example you will get the following result:
However, in your case specificlly, it sounds like it is best to use equal (-eq) as it is an exact value (but it is yours to decide):