This project is read-only.

NAME

New-RegKey

SYNOPSIS

Creates a new registry key on local or remote machines.

SYNTAX

New-RegKey [[-ComputerName] <>] [[-Hive] <>] [-Key] <> [-Name] <> [-Ping] [-View] [-PassThru] [<CommonParameters>]

DESCRIPTION

 

PARAMETERS

-ComputerName <String[]>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? false
Position? 1
Default value $env:COMPUTERNAME
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

 

-Hive <String>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? false
Position? 2
Default value LocalMachine
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

 

-Key <String>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? true
Position? 3
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

 

-Name <String>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? true
Position? 4
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

 

-Ping <SwitchParameter>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false

 

-View <RegistryView>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? false
Position? named
Default value Default
Accept pipeline input? false
Accept wildcard characters? false

 

-PassThru <SwitchParameter>

Adds a new member even the object has a custom member with the same name. You cannot use the Force parameter to replace a standard member of a type.

Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false

 

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS

 

OUTPUTS

PSFanatic.Registry.RegistryKey (PSCustomObject)

NOTES

Author: Shay Levy
Blog : http://PowerShay.com

EXAMPLES

-------------------------- EXAMPLE 1 --------------------------

C:\PS>$Key = "SOFTWARE\MyCompany"

New-RegKey -ComputerName SERVER1,SERVER2 -Key $Key -Name NewSubKey -PassThru

ComputerName Hive Key SubKeyCount ValueCount
------------ ---- --- ----------- ----------
SERVER1 LocalMachine SOFTWARE\MyCompany\New... 0 0
SERVER2 LocalMachine SOFTWARE\MyCompany\New... 0 0


Description
-----------
The command creates new regitry key on two remote computers.
When PassThru is present the command returns the registry key custom object.

-------------------------- EXAMPLE 2 --------------------------

C:\PS>[Environment]::Is64BitProcess

False

PS> New-RegKey -Hive LocalMachine -Key SOFTWARE -ComputerName Server1 -Name MyKey -View Registry64 -PassThru

ComputerName Hive Key SubKeyCount ValueCount
------------ ---- --- ----------- ----------
Server1 LocalMachine SOFTWARE\MyKey 0 0


Description
-----------
This command is using an elevated 32-bit instance of Windows PowerShell to create a new key
in a 64-bit registry section of a remote 64-bit server. First we verify that the current console
is a 32-bit instance by using the Is64BitProcess system environment variable.

Connecting to the 64-bit section of the remote server registry is done using the View
parameter.

-------------------------- EXAMPLE 3 --------------------------

C:\PS>Get-Content servers.txt | New-RegKey -Key $Key -Name NewSubKey -PassThru | Set-RegString -Value TestValue -Data TestData -Force -PassThru

ComputerName Hive Key Value Data Type
------------ ---- --- ----- ---- ----
SERVER1 LocalMachine SOFTWARE\MyCompan... TestValue TestData String
SERVER2 LocalMachine SOFTWARE\MyCompan... TestValue TestData String
SERVER3 LocalMachine SOFTWARE\MyCompan... TestValue TestData String


Description
-----------
The command uses the Get-Content cmdlet to get the server names from a text file. The names are piped into
New-RegKey which creates the key in the remote computers.
The result of New-RegKey is piped into Set-RegString which creates a new String value under the new key and sets its data.

RELATED LINKS

http://psrr.codeplex.com
Get-RegKey
Remove-RegKey
Test-RegKey

Last edited Jun 11, 2012 at 1:44 PM by Shay, version 3

Comments

No comments yet.