VMware Cloud Community
dshivamu
Contributor
Contributor
Jump to solution

Need help creating user ID using power CLI

Hi

I am trying to create the ID using pslink.exe in power CLI, i am getting followig error message

Server sent command exit status 2
usage: useradd  [-u uid [-o]] [-g group] [-G group,...]
                [-d home] [-s shell] [-c comment] [-m [-k template]]
                [-f inactive] [-e expire ] [-p passwd] [-M] [-n] [-r] [-l] nam
       useradd  -D [-g group] [-b base] [-s shell]
                [-f inactive] [-e expire ]

This is the script

Get-VMHost | %{
$User = "root"
$Pswd = "xxxxxx"


$plink = "C:\Progra~1\PuTTY\plink.exe"
$plinkoptions = " -v -batch -pw $Pswd"
$cmd1 = ' useradd -u 10001 -G wheel -s /bin/bash -d /home/xxxxx -m -p xxxxxx -c "xxxxxx" xxxxxxx'

$remoteCommand =  '"'+ $cmd1 +'"'
$command =  $plink + " " + $plinkoptions + " " + $User + "@" + $_.NAME + " " + $remoteCommand


$msg = Invoke-Expression -command $command

}

Kindly help on this

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Why don't you use the New-VMHostAccount cmdlet? Something like:

New-VMHostAccount -Id 1001 -Password TopSecret -Description 'User 1001' -UserAccount -AssignGroups wheel -GrantShellAccess

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
3 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Why don't you use the New-VMHostAccount cmdlet? Something like:

New-VMHostAccount -Id 1001 -Password TopSecret -Description 'User 1001' -UserAccount -AssignGroups wheel -GrantShellAccess

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
dshivamu
Contributor
Contributor
Jump to solution

excellent it got works.... by the way can u tell me anything wrong in plink command, looks like space or special character issue but i couldn't able to identify

sorry actually the answer is helpful answer, i am looking for doing it on bulk of servers so i guess it won't be possible by using your command, can u tell me how i can achive?

Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

Hi,

can you try your command in the way i did ?

http://psvmware.wordpress.com/2012/04/13/esxi-filesystem-disk-usage-script/

$str1=’c:\plink.exe -v -pw ”v53HYfsd#$%$%^^&*” -l root ‘
$str2='useradd -u 10001 -G wheel -s /bin/bash -d /home/xxxxx -m -p xxxxxx -c "xxxxxx" xxxxxxx'

$esxhost=”‘”+'esx_host_name'+”‘”
$command=$str1+$esxhost+$str2
Invoke-Expression -Command $command

And let me know if this works for you ?

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos