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

15 years’ experience as an IT infrastructure consultant and Solution Architect. Accomplished IT professional recognized for excellence in the design, management, and development of complex business applications. Passion for delivering software and technology that meets the needs of the business. Proven ability to work with business users together with a strong development background make for an ideal analyst or solutions architect. 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. Playing the role of solution architect and project leader focusing on migrations and deployments of Office 365 (Exchange Online, Sharepoint Online and Skype for Business) and Microsoft Azure (IaaS, PaaS, SaaS DRaaS). My main responsibilities were:-design and architecture scaling Exchange Server 2003 migration, 2007, 2010 and 2013 to Office 365 with ADFS in Microsoft Azure as IaaS; -Management of major project of Yammer and Sharepoint; -Development of strong relationship with partners and major customers.
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