bibi92
asked on
problem executing sc command in powershell script
Hello,
I try to execute this following command in ps script :
$ComputerName = (get-WmiObject win32_computersystem).Name
$server = "\\" + $computername
$U = $env:USERNAME
sc $server config sshd type= own
sc $server config sshd obj= $U password= $env:password
This error is returned
Set-Content : A positional parameter cannot be found that accepts argument 'sshd'.
At line:1 char:3
+ sc <<<< $server config sshd obj= $U password= $env:password
+ CategoryInfo : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFoun d,Microsof t.PowerShe ll.Command s.SetConte ntCommand
How can I resolve this problem?
Thanks
bibi
I try to execute this following command in ps script :
$ComputerName = (get-WmiObject win32_computersystem).Name
$server = "\\" + $computername
$U = $env:USERNAME
sc $server config sshd type= own
sc $server config sshd obj= $U password= $env:password
This error is returned
Set-Content : A positional parameter cannot be found that accepts argument 'sshd'.
At line:1 char:3
+ sc <<<< $server config sshd obj= $U password= $env:password
+ CategoryInfo : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFoun
How can I resolve this problem?
Thanks
bibi
ASKER
Thanks but same error.
Hi,
Use the following:
$ComputerName= (get-WmiObject win32_computersystem).Name
$server= "\\" + $ComputerName
$U= $env:USERNAME
sc.exe $server config sshd type= own obj= '$U' password= '$env:password'
Use the following:
$ComputerName= (get-WmiObject win32_computersystem).Name
$server= "\\" + $ComputerName
$U= $env:USERNAME
sc.exe $server config sshd type= own obj= '$U' password= '$env:password'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To add to the response from Xaelian, your problem is that "sc" is an alias for the Set-Content cmdlet. By using sc.exe, you will be executing the correct command.
ASKER
Hello,
Thanks, I try this :
sc.exe $server config sshd type= own obj= DOMAIN\USERNAME password= '$env:password'
But the sc doesn't start due to a logon failure.
There is a problem with $env:password.
How can I catch the $env:password from this following bash command before sc command :
bash --login -c "/bin/ssh-host-config -y -c ntsec -u $U -w $env:password"
Thanks
bibi
Thanks, I try this :
sc.exe $server config sshd type= own obj= DOMAIN\USERNAME password= '$env:password'
But the sc doesn't start due to a logon failure.
There is a problem with $env:password.
How can I catch the $env:password from this following bash command before sc command :
bash --login -c "/bin/ssh-host-config -y -c ntsec -u $U -w $env:password"
Thanks
bibi
Well can you echo the $env:password? In your bash file?
Because password are handled really secure in every OS. If you can echo it, you can put it into a variable. If you can't echo it, you can't use it.
It would be very insecure if everyone can get the password so easy :)
Because password are handled really secure in every OS. If you can echo it, you can put it into a variable. If you can't echo it, you can't use it.
It would be very insecure if everyone can get the password so easy :)
$ComputerName= (get-WmiObject win32_computersystem).Name
$server= "\\" + $ComputerName
$U= $env:USERNAME
sc $server config sshd type= ownsc $server config sshd obj= $U password= $env:password