Edite o registro em vários computadores remotos com PowerShell

Ola Amigos

Mais uma dica valiosa sobre editar o “Regedit” em varios computadores com o PowerShell

Fonte: http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/17/edit-the-registry-on-multiple-remote-computers-with-powershell.aspx

One way to avoid this and to enable the ability to make changes on multiple machines is to turn the commands into a single line. It is then really easy to run the command by using the Invoke-Command cmdlet. To do this, I use the following steps:

  1. Use the Get-Credential cmdlet to retrieve cmdlets. Store the returned credential in a variable.
  2. Use the Invoke-Command cmdlet to run the command on remote computers.

The two commands are shown here. Keep in mind that the second command is one long command that has wrapped over several different lines. I have not included line continuation for this command.

$cred = Get-Credential iammred\administrator

Invoke-Command -cn dc3 -cred $cred {pushd;sl HKCU:\software; ni HSG; New

-ItemProperty -name forscripting -PropertyType string -path hsg -value “powershell rocks” ; popd}

The registry key is the same registry key and registry property that I created in yesterday’s blog. I test the command, and the commands and the output associated with the commands are shown in the image that follows.

Image of command output

Now, I decide to test the command against two computers. The only change required is to add an additional computer name to the –cn property (I deleted the registry key on DC3 prior to running the code the second time). This is shown here.

Image of command output

I decide to make one more test. I have a text file that contains the names of some of the servers on my network. The file is Servers.txt. Each line of the file contains a different computer name, as shown here.

Image of file

I can use the Get-Content (gc is an alias) cmdlet to read the contents of the text file. Instead of specifying a particular computer name, I can use Get-Content to retrieve the computer names for me. The revised command is shown here.

$cred = Get-Credential iammred\administrator

Invoke-Command -cn (gc c:\fso\servers.txt) -cred $cred {pushd;sl HKCU:\software; ni HSG; New-ItemProperty -name forscripting -PropertyType string –path hsg -value “powershell rocks” ; popd}

The image that follows illustrates these commands, and the output associated with the commands.

Image of command output

Well, that is about it for today. Join me tomorrow when I will talk about testing for registry keys and deleting them.

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 um comentário

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