Hi all,
I hope I've posted this question in the correct section but apologies if I haven't. I'm new to powershell. I've successfully written some basic scripts that automate various tasks I have to perform on a daily basis. These scripts work just fine and I thought I was getting the hang of PS but it seems I've met my match! The script in question is supposed to check through a supplied list of machines [test.txt] and query a specfic registry key namely:
SYSTEM\CurrentControlSet\Control\Class\{4D36e972-E325-11CE-BFC1-08002bE10318}\0001
I am currently testing with two machines only but ultimately I want to run this against all workstations in my domain. I am looking for a value of 6 as that denotes that the NIC is set to 100Mb/Full which is what I want to see. A 0 denotes that the nic is set to auto and in our environment this causes an issue. What I have found is that if I manually set one of the machines to auto (creating an exception) and then run the script, the output states that both machines are set to 100Mb/full which is clearly not the case. This is my first attemot at using function and I've obviously got something wrong with my script but I can't figure out what.
Any help is most appreciated.
Regards Jonny Barker
function Get-RequestedMediaType{
param([string]$computer = ".")
$regHive = [Microsoft.Win32.RegistryHive]"LocalMachine";
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$computer);
$subKey = $regKey.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\{4D36e972-E325-11CE-BFC1-08002bE10318}\0001");
$subKey.GetValue("RequestedMediaType")
}
Clear-Host
$Machines = Get-Content "test.txt"
foreach ($MachineName in $Machines){
$status = Get-RequestedMediaType -computer $MachineName
if ($status -eq 6)
{Write-Host $MachineName is forced to 100Mb/Full -ForegroundColor "Green"}
else
{Write-Host $MachineName is NOT forced to 100Mb/Full -ForegroundColor "Red"}}