Use O PowerShell para editar o Registro em computadores remotos


Ola Amigos

 

Mais uma dica bem legal para quem quer editar o “regedit” do Windows remotamente.

Link: http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/16/use-powershell-to-edit-the-registry-on-remote-computers.aspx

Suppose I want to create a new registry key under HKEY_CURRENT_USER under the Software key, and I want to call it HSG. The registry location (for the target HSG) is shown in the following image.

Image of menu

To create the new registry key, I use the four steps:

  1. I use the Push-Location cmdlet (pushd is an alias) to store my current location.
  2. I use the Set-Location cmdlet to change my working location to the HKCU:\Software location.
  3. I use the New-Item cmdlet to create the new registry key.
  4. I use the Pop-Location cmdlet (popd is an alias) to return to my current location.

The commands are shown here.

PS C:\> pushd

PS C:\> Set-Location HKCU:\Software

PS HKCU:\Software> New-Item -Name HSG

    Hive: HKEY_CURRENT_USER\Software

SKC  VC Name                           Property

—  — —-                           ——–

  0   0 HSG                            {}

PS HKCU:\Software> popd

PS C:\>

The newly created registry key is shown in the image that follows.

Image of menu

To add a registry property value, I use the New-ItemProperty cmdlet. I perform the same basic steps I used to create the registry key, but I use the New-ITemProperty cmdlet instead of the New-Item cmdlet, as follows:

  1. I use the Push-Location cmdlet to store my current location.
  2. I use the Set-Location cmdlet to change my working location to the HKCU:\Software location.
  3. I use the New-ItemProperty cmdlet to create the new registry property. I specify the Name, Path, Value, and PropertyType.
  4. I use the Pop-Location cmdlet to return to my current location.

The use of these techniques is shown here.

PS C:\> pushd

PS C:\> Set-Location HKCU:\Software

PS HKCU:\Software> New-ItemProperty -Name forscripting -PropertyType string -path hsg -Value “PowerShell Rocks”

PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\hsg

PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software

PSChildName  : hsg

PSDrive      : HKCU

PSProvider   : Microsoft.PowerShell.Core\Registry

forscripting : PowerShell Rocks

PS HKCU:\Software> popd

PS C:\>

The newly created registry property is shown in the image that follows.

Image of menu

After I have done all this locally, it is really easy to do it against a remote computer. I can do it by using Windows PowerShell remoting by using the following steps:

  1. I use the Get-Credential cmdlet to retrieve a credential object to use to make a remote connection.
  2. I use the Enter-PSSession cmdlet to enter a remote PS Session.
  3. I use the Push-Location cmdlet to store my current location.
  4. I use the Set-Location cmdlet to change my working location to the HKCU:\Software location.
  5. I use the New-Item cmdlet to create the new registry key.
  6. I use the New-ItemProperty cmdlet to create the new registry property. I specify the Name, Path, Value, and PropertyType.
  7. I use the Pop-Location cmdlet to return to my previous location.
  8. I use the EXIT command to leave the remote PS Session.

The following image illustrates this technique.

Image of command output

I then use Remote Desktop to connect to the remote server to verify that the registry key and property are updated. This is shown in the following image.

Image of menu

Well, that is about it for creating a remote registry key. Join me tomorrow, when I will talk about doing this in a single command—a scenario that is useful when you need to make changes on multiple computers.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

 

Outra boa dica e seguir o  @ScriptingGuys pelo twitter.

Polegar para cima

Sobre Julio Vaz

I'm a results-driven IT professional on consulting for integration projects with extensive experience in the engineering, administration and support. Direct experience with customer relationships, complex problem troubleshooting, implementation, optimization, technology advisor and training deliveries. Always interested in professional growth as well as high-quality service delivery. Specialties: Office 365. Windows Intune. Windows Azure. Microsoft Windows Server and Active Directory Microsoft Exchange Server 2000/2003/2007/2010, 2013 Windows Virtualization: Hyper-V Windows server 2008, 2008 R2, 2012, 2012 R2. Microsoft Isa Server 2000, Isa Server 2004, Isa Server 2006. Microsoft Forefront TMG 2010. Microsoft Project Server 2007/2010, 2013 Microsoft SharePoint 2007/2010, 2013 Documentation of the computing environment and services. Elaboration of technical procedures. Elaboration of proposals and projects. Management and training of support staff. Implementation and maintenance of security and backup policies. Implementation, administration and migration from Microsoft . Windows NT, Windows 2000 Server, Windows Server 2003 R2, Windows Server 2008 R2, Windows Server 2012 R2 Implementation and migration from Microsoft Office Communications Server 2007 Implementation and migration from Microsoft Lync Server 2010, 2013. Implementation and migration from Microsoft Exchange Server 2000, 2003 and 2007, 2010, 2013. Implementation and migration from Microsoft Isa Server 2000, 2004 and 2006, Forefront TMG Implementation Microsoft System Center 2012 R2 - SCCM, SCOM, DPM. Migration of servers and domains
Esse post foi publicado em Dicas. Bookmark o link permanente.

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s