winrm icon indicating copy to clipboard operation
winrm copied to clipboard

我使用这段代码 报panic: http response error: 401 - invalid content type 账号密码 都是正确的

Open devops-fj opened this issue 1 year ago • 6 comments

func main() { endpoint := winrm.NewEndpoint("host", 5985, false, false, nil, nil, nil, 0)

params := winrm.DefaultParameters
params.TransportDecorator = func() winrm.Transporter { return &winrm.ClientNTLM{} }

client, err := winrm.NewClientWithParameters(endpoint, "test", "test", params)
if err != nil {
	log.Fatal(err)
}

t, err := client.RunWithInput("ipconfig", os.Stdout, os.Stderr, os.Stdin)
if err != nil {
	panic(err)
}
fmt.Println(t)

}

devops-fj avatar Jul 19 '23 03:07 devops-fj

https://learn.microsoft.com/zh-cn/windows/win32/winrm/authentication-for-remote-connections

或者用户处于管理员组 administrators

gdlxSong avatar Aug 04 '23 06:08 gdlxSong

有没有解决?

JieWaZi avatar Aug 14 '23 03:08 JieWaZi

有没有解决?

并没有解决

devops-fj avatar Aug 28 '23 09:08 devops-fj

https://learn.microsoft.com/zh-cn/windows/win32/winrm/authentication-for-remote-connections

或者用户处于管理员组 administrators

我这边使用的确实是adminstrator 管理员 但是还是报401

devops-fj avatar Aug 28 '23 09:08 devops-fj

@devops-fj

想来是winrm没有配置好:

https://github.com/StefanScherer/packer-windows/blob/main/scripts/enable-winrm.ps1

gdlxSong avatar Aug 31 '23 05:08 gdlxSong

It's probably because the server requires NTLM authentication - I have a PR in to implement this in this repo but this seems to be not very active

you could use https://github.com/CalypsoSys/bobwinrm

see https://github.com/CalypsoSys/bobwinrmntlm for usage

CalypsoSys avatar Sep 26 '23 17:09 CalypsoSys