加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

PowerShell 脚本中调用密文密码

发布时间:2020-12-15 23:12:48 所属栏目:安全 来源:网络整理
导读:1. 把密码转变为加密的字符串。使用命令 ConvertFrom-SecureString Read-Host "Enter Password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:pwd.txt"????????? #弹出输入密码的对话框,然后把加密后的密码保存到输出的文件中。 2. 把加密后

1. 把密码转变为加密的字符串。使用命令 ConvertFrom-SecureString

Read-Host "Enter Password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:pwd.txt"????????? #弹出输入密码的对话框,然后把加密后的密码保存到输出的文件中。

2. 把加密后的字符串转换成SecureString对象。使用命令 ConvertTo-SecureString

$f = "D:pwd.txt"
$SecurePwd = Get-Content $f | ConvertTo-SecureString
?
3. 使用密码文件创建 Credential 信息
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList UserName,(Get-Content $f | ConvertTo-SecureString)? #UserName替换成你要创建的用户名密码是引用第二步的内容
example:
Enter-PSSession -ComputerName?10.1.1.1 -Credential $Cred???? #此命令可远程登录指定机器

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读