Posted On November 22, 2021

PowerShell: Quickly Add Users into Groups on a List of Computers

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Quickly Add Users into Groups on a List of Computers
$newVmNames=@(
    'SERVER0001', 
    'SERVER0002'
)
$newUsers=@(
    'domain\user1'
)
$groupNames='Administrators','Remote Desktop Users'

$newVmNames|%{
    invoke-command -computername $_ {
        param($newUsers,$groupNames)
        try{            
            $groupNames|%{
                Add-LocalGroupMember -Group $_ -Member $newUsers
                write-host "$env:computername`: Group name '$groupName' now has these users`r`n$(get-localgroupmember $groupName)"
            }
        }catch{
            write-warning $_
        }        
    } -ArgumentList $newUsers,$groupNames
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Add Quorum to Clusters

# SetClusterQuorum.ps1$clustersAndQuorums=@();$clustersAndQuorums+=[PSCustomObject]@{ClusterName='CLUSTER1';Quorum='\\FILESHERVER007\CLUSTER1$'};$clustersAndQuorums+=[PSCustomObject]@{ClusterName='CLUSTER2';Quorum='\\FILESHERVER007\CLUSTER2$'};function getViableNode{ param($nodes) foreach ($node in $nodes){ $bingo=Test-NetConnection $node -InformationLevel Quiet; if($bingo){return $node} }}…

PowerShell: Practical Usage of Robocopy

Quick Commands: $source='C:\vssSnapshot_F'$destination='\\DESTINATIONSERVER\F$'robocopy $source $destination /E /R:0 /NP /XD '$RECYCLE.BIN' 'System Volume Information' /xf 'pagefile.sys'…

PowerShell: How To Stop and Start Palo Alto Cortex XDR Traps

$trapsAdminPassword='PASSWORDHERE', $trapsBin='C:\Program Files\Palo Alto Networks\Traps' function stopXdr{ param( $trapsAdminPassword, $trapsBin='C:\Program Files\Palo Alto Networks\Traps' ) echo…