Skip to content

Instantly share code, notes, and snippets.

@bharkr
Last active January 8, 2024 22:56
Show Gist options
  • Save bharkr/5d98d6f33f5f5b99b508a98eade810f2 to your computer and use it in GitHub Desktop.
Save bharkr/5d98d6f33f5f5b99b508a98eade810f2 to your computer and use it in GitHub Desktop.
Remove TortoiseHg from startup on a list of computers
<#
.SYNOPSIS
Disables the TortoiseHg startup entry on a list of computers.
.DESCRIPTION
The Disable-TortoiseHgStartup function uses Invoke-Command to remotely access the registry of each computer in the $ComputerName parameter. It attempts to get the 'TortoiseHgOverlayIconServer' startup entry. If the computer isn't responding or doesn't have TortoiseHg installed, it outputs a message.
.PARAMETER ComputerName
An array of computer names or a single computer name. This can be either a string or an object with a 'Name' property.
.EXAMPLE
Disable-TortoiseHgStartup -ComputerName "Computer1", "Computer2", "Computer3"
This example disables the TortoiseHg startup entry on the computers named Computer1, Computer2, and Computer3.
.EXAMPLE
$computers = @(
[PSCustomObject]@{Name = "Computer1"},
[PSCustomObject]@{Name = "Computer2"},
[PSCustomObject]@{Name = "Computer3"}
)
Disable-TortoiseHgStartup -ComputerName $computers
This example disables the TortoiseHg startup entry on the computers named Computer1, Computer2, and Computer3, using an array of objects with a 'Name' property.
.EXAMPLE
Get-ADComputer -Filter * | Disable-TortoiseHgStartup
This example disables the TortoiseHg startup entry on all computers in Active Directory.
.NOTES
The function requires that the user running it has the necessary permissions to access the remote registry of the computers in the $ComputerName parameter.
#>
function Disable-TortoiseHgStartup {
param (
[Parameter(ValueFromPipeline = $true)]
[PSObject[]]$ComputerName
)
if ($ComputerName -is [string]) {
$ComputerName = @([PSCustomObject]@{Name = $ComputerName })
}
foreach ($c in $ComputerName) {
try {
$result = Invoke-Command -ComputerName $c.Name -ScriptBlock { get-itemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run -Name 'TortoiseHgOverlayIconServer' }
if ($result) {
Invoke-Command -ComputerName $c.Name -ScriptBlock { Remove-itemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Run -Name 'TortoiseHgOverlayIconServer' -Confirm }
}
}
catch {
Write-Output "$($c.Name) isn't responding or does not have TortoiseHg installed"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment