[英]WIndows Form textbox pass text value to a Powershell Runscript
我正在使用C#开发Win窗体 ,以创建一个工具,该工具将在PowerShell运行空间内运行多个PowerShell脚本,并在文本文件上显示结果。
现在,我有以下内容。
...带有按钮的Win表单,它将返回以下PowerShell脚本的结果:
txtUserInfo.Text = RunScript(@"Get-ADUser UserNameGoesHere -Properties * | Select-Object Enabled, @{Expression={$_.LockedOut};Label='Locked';}, DisplayName, GivenName, SurName, Mail, @{ Expression ={[DateTime]::FromFileTime($_.LastLogon)}; Label='Last Logon';}, @{Expression={$_.Created};Label='Date Created';}, passwordlastset, Passwordneverexpires | Format-list");
该脚本正在运行,并在文本框中显示结果。
这可以与硬编码到PowerShell脚本中的用户名一起使用:
RunScript(@“ Get-ADUser UserNameGoesHere -Properties * |
我试图找到一种方法来使用文本框在Win窗体上输入并将该值作为变量传递给PowerShell运行空间。 但是我找不到能够帮助我的任何信息。
任何指针表示赞赏
问候,
除非我有误会,否则只需将其添加到字符串中
txtUserInfo.Text = RunScript(@"Get-ADUser " + YourTextBox.Text + @" -Properties * |
Select-Object Enabled, @{Expression={$_.LockedOut};Label='Locked';},
DisplayName, GivenName, SurName, Mail,
@{ Expression={[DateTime]::FromFileTime($_.LastLogon)}; Label='Last Logon';},
@{Expression={$_.Created};Label='Date Created';},
passwordlastset, Passwordneverexpires |
Format-list");
要建立Sorceri所说的话,您需要使用按钮来完成所有工作,并使用从文本框中获取的数据。
txtUserInfo.Text = RunScript(@"Get-ADUser " + YourTextBox.Text + @" -Properties * | Select-Object Enabled, @{Expression={$_.LockedOut};Label='Locked';}, DisplayName, GivenName, SurName, Mail, @{ Expression ={[DateTime]::FromFileTime($_.LastLogon)}; Label='Last Logon';}, @{Expression={$_.Created};Label='Date Created';}, passwordlastset, Passwordneverexpires | Format-list");
$yourbutton.Add_Click({
#do all your stuff
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.