cwstad2
asked on
powershell ampersand issue
Hi all, i have found the following powershell script online, but when i run it i get many issues like Ampersand not allowed. The & operator is reserved for future use; use "&" to pass ampersand as a string.
At line:5 char:53. Any ideas?
thanks
$AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"}
ForEach ($Server in $AllServers){
$Result=Get-WmiObject -Class Win32_NetworkAdapterConfig uration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $Server.Name
$output = new-object PSObject
$output | add-member NoteProperty "ComputerName" $Server.Name
$output | add-member NoteProperty "DNSServerSearchOrder " $Result.DNSServerSearchOrd er
$output
}
At line:5 char:53. Any ideas?
thanks
$AllServers=Get-ADComputer
ForEach ($Server in $AllServers){
$Result=Get-WmiObject -Class Win32_NetworkAdapterConfig
$output = new-object PSObject
$output | add-member NoteProperty "ComputerName" $Server.Name
$output | add-member NoteProperty "DNSServerSearchOrder
$output
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yep, I missed the semicolons, I was in the process of correcting it but we just had a fire drill so I had to leave my desk. Thanks
Thank you
ASKER
excellent thanks guys, is it possible to do the same for desktops such as windows XP, 7 and 8.
best regards
best regards
All you have to do is change the
OperatingSystem -Like "Windows Server*"
to
OperatingSystem -Like "Windows XP*"
OperatingSystem -Like "Windows 7*"
OperatingSystem -Like "Windows 8*"
or you can take it out completely (using Qlemo's version of script)
This will return the result for every computer on your domain.
or you can do everything but servers by changing -like to -NotLike
OperatingSystem -Like "Windows Server*"
to
OperatingSystem -Like "Windows XP*"
OperatingSystem -Like "Windows 7*"
OperatingSystem -Like "Windows 8*"
or you can take it out completely (using Qlemo's version of script)
This will return the result for every computer on your domain.
Get-ADComputer -Filter * | % {
$comp = $_.Name
$Result = (Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $comp).DNSServerSearchOrder
new-object PSObject -Property @{
ComputerName = $comp
DNSServerSearchOrder = $Result
}
}
or you can do everything but servers by changing -like to -NotLike
Get-ADComputer -Filter {OperatingSystem -NotLike "Windows Server*"} | % {
$comp = $_.Name
$Result = (Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $comp).DNSServerSearchOrder
new-object PSObject -Property @{
ComputerName = $comp
DNSServerSearchOrder = $Result
}
}
ASKER
Thanks guys