0

I want to run below command using domain user :

New-DfsReplicationGroup -GroupName "RG01"

I have tried 2 ways but for both it give error :

1). Start-Process powershell -Credential domain.com\Admin -password abc1234 New-DfsReplicationGroup -GroupName "RG01"
2). Invoke-Command -Credential domain.com\Admin -password abc1234 New-DfsReplicationGroup -GroupName "RG01"

Please advice.

hazel
  • 3
  • 1
  • 3
  • What error messages do you receive? Does the operation work if you login as domain.com\Admin and simply run 'New-DFSReplicationGroup -GroupName "RG01"'? – veefu Jan 20 '18 at 01:49

1 Answers1

0

You are trying to use down-level WinNT logons but specifying the domain fqdn.

Change this...

Start-Process powershell -Credential domain.com\Admin -password abc1234 New-DfsReplicationGroup -GroupName "RG01"
Invoke-Command -Credential domain.com\Admin -password abc1234 New-DfsReplicationGroup -GroupName "RG01"

To this... each of the below will autofill the password dialog with the user info, you still have to enter the password of course.

Start-Process powershell -Credential domain\Admin -password abc1234 New-DfsReplicationGroup -GroupName "RG01"
Invoke-Command -Credential domain\Admin -password abc1234 New-DfsReplicationGroup -GroupName "RG01"

Never put passwords in plain text in scripts

So, use

$DomainUserCreds = Get-Credential -Credential 'Domainname\Username'
Start-Process powershell -Credential $DomainUserCreds New-DfsReplicationGroup -GroupName "RG01"
Invoke-Command -Credential $DomainUserCreds New-DfsReplicationGroup -GroupName "RG01"

If you are logged on as a admin of the domain, you can just get this dynamically

$DomainUserCreds = Get-Credential -Credential "$env:USERDOMAIN\$env:USERNAME"
Start-Process powershell -Credential $DomainUserCreds New-DfsReplicationGroup -GroupName "RG01"
Invoke-Command -Credential $DomainUserCreds New-DfsReplicationGroup -GroupName "RG01"

If you domain is set to use UPN you can do

$DomainUserCreds = Get-Credential -Credential "$env:USERNAME@$env:USERDNSDOMAIN"
Start-Process powershell -Credential $DomainUserCreds New-DfsReplicationGroup -GroupName "RG01"
Invoke-Command -Credential $DomainUserCreds New-DfsReplicationGroup -GroupName "RG01"
postanote
  • 15,138
  • 2
  • 14
  • 25
  • Thank you very much for the response!!! The problem is I am running this script in backend and when I tested its asking for password again although I have mentioned -password. shall try with --force ? – hazel Jan 20 '18 at 15:16
  • So, you are trying to run this on a remote computer from your admin workstation, but you are logged in one way, say non-admin, and wanting to run the code on the remote host using credentials that has the admin privilege on the remote host? If that is the case then, you should be doing something like this.. Invoke-Command -ComputerName 'RemoteComputerName' -ScriptBlock {'Your code here'} -Credential $DomainUserCreds – postanote Jan 21 '18 at 00:40