ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

PowerShell Pickle with Registry Updates

(1/1)

Stoic Joker:
Greetings,
    So I'm in a bit of a pickle trying to update the registry with PowerShell. I need to go into a key, list it's sub keys, and update a value in all of the subkeys on local machine. Reason this is being done with PowerShell, is it has to be pushed out to 80 machines...so nobody wants to do it manually 80 times  :D

   The script (scrounged off the internet) I've been beating on all afternoon is below, it will open the key and list the values I'm after … But I cannot get it to update them. Note: the updated value is/will be based on the current value. So I'm looking for a get/replace/set type of operation on the HostName entry's value which is an IP address.


--- Code: PowerShell ---$registry = Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" -Recurse foreach ($a in $registry) {    ($a | Get-ItemProperty).Psobject.Properties |    #Exclude powershell-properties in the object    Where-Object { $_.Name -like 'HostName' } |    Select-Object Name, Value}
So instead of displaying the HostName entry's value, I need it to change the third octet of the IP address to a 4 so that 192.168.1.152 becomes 192.168.4.152

Anybody smarter than I am got a bit of mercy handy for a tired old fool?

TIA
-Stoic Joker

Stoic Joker:
So... Crickets it is then..

Well for the next poor sod what ends up wondering, I did manage to cobble together an answer:

--- Code: PowerShell ---$registry = Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" -Recurse foreach($a in $registry) {         $X = $a.ToString()        $X = $X.Replace("HKEY_LOCAL_MACHINE", "HKLM:")        Get-ItemProperty -Path "$X" HostName | %{Set-ItemProperty -Path $_.PSPath HostName -Value ( $_.HostName -Replace ".1.", ".4." )}} Restart-Service -Name Spooler

Object being: we're having to readdress a large network that is running out of addresses to an entirely different - non overlapping - subnet. So when all of the machines (DHCP) jump over to the new address range, nobody will be able to access their printers because they all print to direct IP. 80 computers, pointing at 60+ different printers, in what is basically a mesh pattern.

Nobody want's to do that shit through the GUI by hand.

So this (pushed to each machine via management software) will update the Printer Port IP Address targets on each machine to the new address range … Without requiring anyone to romp all over the complex touching machines.

superboyac:
LOL loving the attitude.  This is how I am normally LOLLL.

Navigation

[0] Message Index

Go to full version