-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathRegistry.ps1
52 lines (47 loc) · 1.72 KB
/
Registry.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Registry
# wop...
param( [String]$command, [String]$fullPath, [String]$name, [String]$property, [String]$value )
$splitPath = $fullPath.split( '\' )
Switch( $splitPath[0] )
{
"HKEY_CLASSES_ROOT" { $psdrive = "HKCR" }
"HKEY_CURRENT_USER" { $psdrive = "HKCU" }
"HKEY_LOCAL_MACHINE" { $psdrive = "HKLM" }
"HKEY_USERS" { $psdrive = "HKU" }
"HKEY_CURRENT_CONFIG" { $psdrive = "HKCC" }
"HKEY_PERFORMANCE_DATA" { $psdrive = "HKPD" }
"HKEY_DYN_DATA" { $psdrive = "HKDD" }
default { Write-Host "Unknown hive: $($splitPath[0])"; exit -1 }
}
If( !(Get-PSDrive $psdrive) )
{ New-PSDrive -PSProvider registry -Root $splitPath[0] -Name $psdrive > $null }
Switch( $command )
{
"list" {
Get-ChildItem -Recurse "$($psdrive):" 2>$null | Select-Object `
Name,SubKeyCount,ValueCount,PSChildName,Property | Format-Table
}
"search" {
If( $name -and $property )
{ Get-ChildItem -Recurse "$($psdrive):" 2>$null | Where {($_.PSChildName -match $name) -and ($_.Property -match $property)} }
ElseIf( $name )
{ Get-ChildItem -Recurse "$($psdrive):" 2>$null | Where {$_.PSChildName -match $name} }
ElseIf( $property )
{ Get-ChildItem -Recurse "$($psdrive):" 2>$null | Where {$_.Property -match $property} }
Else
{ Get-ChildItem -Recurse "$($psdrive):" 2>$null }
}
"print" {
If( !$name )
{ Get-ItemProperty -Path $fullPath }
Else
{ Get-ItemProperty -Path $fullPath | Where {$_ -match $name} }
}
"edit" {
Set-ItemProperty -Path $fullPath -Name $name -Value $value
}
"create" {
New-ItemProperty -Path $fullPath -Name $name -Value $value
}
default { Write-Host "Unknown command: $command"; exit -1 }
}