Remove-LocalGroupRemote
Windows: Removes a local security group from a computer
#Requires -Version 5.1
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$ComputerName = $env:COMPUTERNAME,
[pscredential]$Credential
)
Process {
try {
$scriptBlock = {
Param($GroupName)
Remove-LocalGroup -Name $GroupName -Confirm:$false -ErrorAction Stop
}
if ($ComputerName -ne $env:COMPUTERNAME) {
$invokeParams = @{
'ComputerName' = $ComputerName
'ScriptBlock' = $scriptBlock
'ArgumentList' = $Name
'ErrorAction' = 'Stop'
}
if ($null -ne $Credential) {
$invokeParams.Add('Credential', $Credential)
}
Invoke-Command @invokeParams
}
else {
&$scriptBlock -GroupName $Name
}
$output = [PSCustomObject]@{
Name = $Name
ComputerName = $ComputerName
Action = "GroupRemoved"
Status = "Success"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $output
}
catch {
throw
}
}Specifies the name of the local group to remove.
Specifies the name of the target computer. Defaults to the local computer.
Specifies a PSCredential object for remote connection.