我创建了 PowerShell 脚本来在远程 Windows Server 上创建用户并添加到管理员组:
\n\n$Computer = Read-Host "Computer name:"\n$UserName = Read-Host "User name:"\n$Password = Read-Host "Password" -AsSecureString\n$AdminGroup = [ADSI]"WinNT://$Computer/Administrator,group"\n$User = [ADSI]"WinNT://$Computer/$UserName,user"\n$Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, (ConvertTo-SecureString $Password -AsPlainText \xe2\x80\x93Force)\n$User.SetPassword($Cred.GetNetworkCredential().Password)\n$AdminGroup.Add($User.Path)\nRun Code Online (Sandbox Code Playgroud)\n\n它给了我以下错误:
\n\n\n检索成员“SetPassword”时发生以下异常:“\n找不到用户名。\n在 C:\\test1.ps1:7 char:18\n+ $User.SetPassword <<<< ($Cred. GetNetworkCredential().Password)\n + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException\n + ExcellentQualifiedErrorId : CatchFromBaseGetMember\n\n检索成员“Add”时发生以下异常:“指定的\n本地组不存在。 \n在 C:\\test1.ps1:8 字符:16\n+ $AdminGroup.Add <<<< ($User.Path)\n + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException\n + ExcellentQualifiedErrorId : CatchFromBaseGetMember \n\n
我正在尝试从 ansible 发送电子邮件
如果我使用 gmail 尝试它,它可以完美运行,但是如果我尝试使用 Office 365,它就无法正常工作。
下面是我的剧本。
---
- name: Mail Sendig using Ansible
hosts: localhost
tasks:
- name: Mail sending using Mail Module
mail:
host: "smtp.office365.com"
port: 587
username: "dcalert@mycompany.com"
password: "mypasswd"
to: "Jon Snow <jon.snow@mycompany.com>"
subject: "Ansible"
body: "Hello from Ansible"
secure: starttls
Run Code Online (Sandbox Code Playgroud)
我得到以下错误
ASK [Send email]
*******************************************************************
An exception occurred during task execution. To see the full
traceback, use -vvv. The error was: SMTPSenderRefused: (501, '5.1.7
Invalid address', 'root')
fatal: [localhost -> localhost]: FAILED! => …Run Code Online (Sandbox Code Playgroud)