Does it work if you run the Get-ADComputer command using one of the names from the list?
Get-ADComputer -filter ‘Name -eq “ServerA”’ -Properties *|select -Property Name,OperatingSystem -verbose
What happens if you pick a name from the list by doing this: $computers[0]|ForEach-Object -Process {Get-ADComputer -filter 'Name -eq "$_"' -Properties *|select -Property Name,OperatingSystem -verbose}
Hah hah, I guess I should have refreshed after having the tab open for a bit…
Use Export-Csv -Path C:\test\Output\Result.csv -Notype rather than Out-File -FilePath C:\test\Output\Result.csv -Append.
Export-Csv will set the first row as the header row. The remaining rows will be data. Export-Csv -Delimiter 'character' allows for a different delimiter (character) than the default comma.
[quote quote=247837]Use Export-Csv -Path C:\test\Output\Result.csv -Notype rather than Out-File -FilePath C:\test\Output\Result.csv -Append.
Export-Csv will set the first row as the header row. The remaining rows will be data. Export-Csv -Delimiter ‘character’ allows for a different delimiter (character) than the default comma.
[/quote]
Thanks much. I’ll use the same as suggested.
Actually I keep on watching different lectures from Youtube(Don Jones) & LinkedLearning(Jason Helmick, Matt Hester, Adam Bertram). Due to lack of practice i end up in different or wrong commands rather than the appropriate one. But Thanks for you kind advise, I’ll continue to do that.
If you could share any PowerShell learning path to move from beginner, that would be really great…!! Thanks in advance. Have a good weekend.
[quote quote=247873]Actually I keep on watching different lectures from Youtube(Don Jones) & LinkedLearning(Jason Helmick, Matt Hester, Adam Bertram). Due to lack of practice i end up in different or wrong commands rather than the appropriate one. But Thanks for you kind advise, I’ll continue to do that.
If you could share any PowerShell learning path to move from beginner, that would be really great…!! Thanks in advance. Have a good weekend.[/quote]
I think you’re doing just fine. What I’d like to recommend though is to search for a solution first before you ask in forum like this. Most questions a beginner has have been aswered already in the past.
If you have to use a source like this and you cannot count on the quality of the source data you could try to use the .trim() method to remove spaces (or other unwnated charachters) from strings you need to use. Example:
$ComputerList =
@(
'Computer_01'
' Computer_02 '
'Computer_03 '
' Computer_04'
)
foreach ($ComputerName in $ComputerList) {
"Output without leading or trailing spaces: '$($ComputerName.trim())'"
}