header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Remote Registry Check
Last Post 25 Oct 2009 12:21 AM by Ayth. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jonnynohUser is Offline
New Member
New Member
Posts:1
Avatar

--
23 Oct 2009 10:07 AM  

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"}}

AythUser is Offline
Basic Member
Basic Member
Posts:173
Avatar

--
25 Oct 2009 12:21 AM  
Hey Johnnyoh,

It might have been better to put this in the General Powershell forum instead of here. I started looking at this script, and it seems to run fine for me. I took two machines and threw them into a text file like you have. I ended up using a different key than RequestedMediaType, one I created just to test to be exact and it worked fine. Couple of questions:

1. What version of Powershell are you running?
2. I would confirm again that the exception is there, might be a good idea to add a Write-Host $status after you call the function, to confirm what value $status is set to.

We should be able to get this working. Thanks.

Cheers,

Darrin aka Ayth
My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer