22 lines
1020 B
PowerShell
Executable File
22 lines
1020 B
PowerShell
Executable File
$clients = @("192.168.1.249")
|
|
|
|
foreach ($client in $clients) {
|
|
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
|
|
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo useradd -m -s /bin/bash username"
|
|
}
|
|
$groupName = "neue_gruppe"
|
|
|
|
foreach ($client in $clients) {
|
|
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
|
|
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo groupadd $groupName"
|
|
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo usermod -aG $groupName username"
|
|
}
|
|
$password = "Passwort123!"
|
|
|
|
foreach ($client in $clients) {
|
|
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
|
|
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
|
|
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "username", $securePassword
|
|
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "echo 'username:$password' | sudo chpasswd"
|
|
}
|