Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- This script is just a wrapper of fm's ua-user command
- .DESCRIPTION
- This script creates a super account for the specified user on the specified machine.
- It can also create a homedir if needed.
- .PARAMETER machineName
- Used to specify the machine name.
- .PARAMETER login
- Used to specify the user login.
- .PARAMETER homedir
- Used to specify if a homedir should be created.
- y or n. No is set by default.
- .EXAMPLE
- .\uaUser.ps1 -machineName "mymachine" -login "conio"
- .EXAMPLE
- .\uaUser.ps1 -machineName "mymachine" -login "conio" -HomeDir "y"
- #>
- param
- (
- [string]$machineName = "NotSet",
- [string]$login = "NotSet",
- [string]$HomeDir = "n"
- )
- $command = "/usr/local/bin/ua-user -sa "
- if($machineName -eq "NotSet") {
- Write-Host "The Machine's name was not entered."
- Exit
- }
- else {
- $machineName = $machineName + ".dbs.fr"
- }
- if($login -eq "NotSet") {
- Write-Host "User's login was not entered."
- Exit
- }
- $cred = Get-StoredCredential -Target sshConn
- $ssho = New-SSHSession -ComputerName $machineName -Credential $cred
- $streamyo = New-SSHShellStream -Index $ssho.SessionId
- $streamyo.WriteLine('sudo -i')
- Start-Sleep -Milliseconds 400
- if($HomeDir -eq "n") {
- $command = $command + $login
- $streamyo.WriteLine($command)
- }
- else {
- $command = "echo y | " + $command + "-a " + $login
- $streamyo.WriteLine($command)
- }
- Start-Sleep -Milliseconds 800
- $result = $streamyo.read()
- Write-Host $result
- Remove-SSHSession $ssho 2>&1>$null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement