This PowerShell is designed to remotely create a custom registry key and value on multiple servers. Here's a breakdown of what the script does:
1.
**Comments and Header**:
- The script begins with comments providing a synopsis, description, and other information about the script.
2.
**Variables**:
- `$Computers`: Reads a list of server names
from a file located at "C:\temp\Servers.txt" and sorts them.
- `$ErrorActionPreference`: Sets the error
action preference to 'SilentlyContinue' to suppress error messages.
3.
**Transcript**:
- The `Start-Transcript` cmdlet records the
output to a log file located at "C:\temp\serverlog.txt" and appends
new entries to the existing log.
4.
**Main Loop**:
- The script enters a loop that iterates
through each server in the list.
- Inside the loop, it sets variables for the
registry path, key name, value name, and value data. You can customize these
values as needed for your specific use case.
5.
**ScriptBlock**:
- A script block (`$ScriptBlock`) is defined
to create the specified registry key and value on the remote server.
- The script block takes parameters for the
registry path, key name, value name, and value data.
6.
**Invoke-Command**:
- The `Invoke-Command` cmdlet is used to run
the script block on the remote server specified by `$Computer`.
- It passes the necessary parameters to the
script block.
7.
**Sleep**:
- After each remote command execution, the
script waits for 3 seconds before proceeding to the next server. This helps
avoid overloading the remote servers with concurrent requests.
8.
**Transcript End**:
- Finally, the `Stop-Transcript` cmdlet is
used to stop recording the transcript.
To
use this script:
1.
Ensure that you have a list of server names in a text file at
"C:\temp\Servers.txt".
2.
Customize the registry path, key name, value name, and value data as needed for
your specific use case.
3.
Run the script, and it will create the specified registry key and value on each
server in the list while recording the output in the log file.
Remember
to run this script with appropriate permissions and ensure that you have the
necessary privileges to make changes to the registry on the remote servers.
<#
.SYNOPSIS
PowerShell
script to remotely create a custom registry key and value on multiple servers.
.DESCRIPTION
This PowerShell
script is designed to create a custom registry key and value on multiple remote
servers.
The script
reads a list of server names from a file, connects to each server, and creates
the specified
registry key
and value. It can be customized to create different registry entries on remote
servers.
.NOTES
Author: Navinya Ambre
Creation
Date: 12/10/2023
Version: 1.0
#>
$Computers = Get-Content "C:\temp\Servers.txt" | Sort
$ErrorActionPreference = 'SilentlyContinue'
Start-Transcript -Path "C:\temp\serverlog.txt" -Append
foreach ($Computer in $Computers) {
Write-Output "Working on $Computer"
$RegPath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Cryptography" # Change this to your desired registry path
$KeyName = "Wintrust" # Change this to your desired key name
$ValueName = "EnableCertPaddingCheck" # Change this to your desired value name
$ValueData = "1" # Change this to your desired value data
$ScriptBlock = {
param (
$RegPath,
$KeyName,
$ValueName,
$ValueData
)
# Create the registry key
New-Item -Path $RegPath -Name $KeyName -Force -ErrorAction SilentlyContinue
# Create the registry value
Set-ItemProperty -Path "$RegPath\$KeyName" -Name $ValueName -Value $ValueData
}
Invoke-Command -ComputerName $Computer -ScriptBlock $ScriptBlock -ArgumentList $RegPath, $KeyName, $ValueName, $ValueData
Sleep -Seconds 3
}
Stop-Transcript
Please consider this an open forum for sharing your thoughts, modifications, and suggestions regarding the script. Your input and feedback are highly encouraged and valued.
No comments:
Post a Comment