Set-LocalGroupConfig
Windows: Modifies a local security group configuration
#Requires -Version 5.1
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$NewName,
[string]$Description,
[string]$ComputerName = $env:COMPUTERNAME,
[pscredential]$Credential
)
Process {
try {
$scriptBlock = {
Param($GroupName, $UpdatedName, $GroupDesc, $BoundParams)
$targetName = $GroupName
if ($BoundParams.ContainsKey('Description')) {
Set-LocalGroup -Name $GroupName -Description $GroupDesc -ErrorAction Stop
}
if ($BoundParams.ContainsKey('NewName')) {
Rename-LocalGroup -Name $GroupName -NewName $UpdatedName -ErrorAction Stop
$targetName = $UpdatedName
}
Get-LocalGroup -Name $targetName | Select-Object Name, SID, Description
}
if ($ComputerName -ne $env:COMPUTERNAME) {
$invokeParams = @{
'ComputerName' = $ComputerName
'ScriptBlock' = $scriptBlock
'ArgumentList' = @($Name, $NewName, $Description, $PSBoundParameters)
'ErrorAction' = 'Stop'
}
if ($null -ne $Credential) {
$invokeParams.Add('Credential', $Credential)
}
$result = Invoke-Command @invokeParams
}
else {
$result = &$scriptBlock -GroupName $Name -UpdatedName $NewName -GroupDesc $Description -BoundParams $PSBoundParameters
}
$output = [PSCustomObject]@{
Name = $result.Name
SID = $result.SID.Value
Description = $result.Description
ComputerName = $ComputerName
Action = "GroupModified"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $output
}
catch {
throw
}
}Specifies the name of the local group to modify.
Specifies a new name for the local group.
Specifies a new description for the local group.
Specifies the name of the target computer. Defaults to the local computer.
Specifies a PSCredential object for remote connection.