Hello Fellow System Administrators
For some reasons, I had to keep track of some variables and instead of using environmental variables, I tried to write down these variables to registry. Basically I tried to write registry keys to \HKLM\Software\<Contoso> path. I think everyone passes by here knows which company Contoso.com is.
Lets start with reading registry with
After reading key and key property, now we can check the key and create it on control if it doesn't exist.
You can check set-registrykey.ps1 from below
Now we can count ourselves as we can play with registries.
Thats all for today guys.
I hope it helps
See you
For some reasons, I had to keep track of some variables and instead of using environmental variables, I tried to write down these variables to registry. Basically I tried to write registry keys to \HKLM\Software\<Contoso> path. I think everyone passes by here knows which company Contoso.com is.
Lets start with reading registry with
get-childItem hklm:\Software\Contoso
Or Key properties like
(Get-ItemProperty -Path hklm:\Software\Contoso).Test
After reading key and key property, now we can check the key and create it on control if it doesn't exist.
function Get-RegistryKey
{
param(
[Parameter(Position=0,mandatory=$true)][String]$RegProperty,
[Parameter(Position=0,mandatory=$true)][String]$RegPath,
[String]$RegKey="."
)
$ReturnThis=New-Object psobject -Property @{Error="0";Value="0"}
if (!$(Test-Path -path $RegPath\$RegKey))
{
Set-RegistryKey.ps1 -RegProperty $RegProperty -RegPath $RegPath -RegValue "0"
}
$ReturnThis.Value=(Get-ItemProperty -Path $RegPath\$RegKey\).$RegProperty
if ($Null -eq $ReturnThis.Value)
{
Set-RegistryKey.ps1 -RegProperty $RegProperty -RegPath $RegPath -RegValue "0"
$ReturnThis.Value="0"
}
$ReturnThis
}
You can check set-registrykey.ps1 from below
function Set-RegistryKey
{
param(
[Parameter(Position=0,mandatory=$true)][String]$RegPath,
[Parameter(Position=0,mandatory=$true)][String]$RegProperty,
[Parameter(Position=1,mandatory=$true)][String]$RegValue,
[String]$RegKey="."
)
if (!$(Test-Path -path $RegPath\$RegKey))
{
New-Item -Path $RegPath -Name $RegKey
}
Set-ItemProperty -Path $RegPath\$RegKey -Name $RegProperty -Value $RegValue
}
Now we can count ourselves as we can play with registries.
Thats all for today guys.
I hope it helps
See you
Comments
Post a Comment