脚本 – Powershell参数
发布时间:2020-12-15 18:41:10 所属栏目:安全 来源:网络整理
导读:我的脚本中有一个Param块 Param ( [Parameter(Mandatory=$True)] [string]$FileLocation,[Parameter(Mandatory=$True)] [string]$password = Read-Host "Type the password you would like to set all the users to" -assecurestring) 我可以在必需的参数字
我的脚本中有一个Param块
Param ( [Parameter(Mandatory=$True)] [string]$FileLocation,[Parameter(Mandatory=$True)] [string]$password = Read-Host "Type the password you would like to set all the users to" -assecurestring ) 我可以在必需的参数字段中使用Read-Host CmdLet吗?如果没有,我该怎么做才能确保我采用正确类型的变量类型,以便将其传递给用户创建过程?
指定正确的密码类型应该足够了,请尝试:
Param ( [Parameter(Mandatory=$True)] [string]$FileLocation,[Parameter(Mandatory=$True)] [Security.SecureString]$password ) PowerShell将“屏蔽”密码(与read-host -asSecureString相同),结果类型将是其他cmdlet可能需要的密码. 编辑:在最近的评论之后:解决方案,它既提供了提供纯文本密码的选项,也强制用户输入密码(但屏蔽它的方式与Read-Host -AsSecureString相同),并且在两种情况下都得到[Security.SecureString] .并且,作为奖励,您会得到一些花哨的提示,以获取您的密码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |