我对 Powershell 很陌生,实际上是从今天开始的,我需要一些帮助来获取显示输出的命令。该命令在从 powershell 运行时有效,但是当我尝试从我粘贴的脚本运行时,它似乎失败了。我什至将变量字段更改为我的用户名,但它仍然失败。
Get-ADUser jdoe -Properties Description
就像我说的那样,它在 powershell 中运行时有效,但在脚本中运行时无效。
Clear-Host
$script:ChosenFunction=Get-function #Get-Choice
function Get-function
{
Write-Host "1. IP (future addon)"
write-host "2. UserInfo"
write-host "3. CopyZ (Future addon)"
write-host "4. Local Users (Future addon)"
Write-Host "X. Exit"
$Action=Read-Host "Choose an action:"
Switch ($Action)
{
1 {$Choice="IP"}
2 {$Choice="UserInfo"}
3 {$Choice="CopyZ"}
4 {$Choice="Local Users"}
5 {$Choice="Exit"}
}
write-host "Function chosen is $Choice"
if ($Action -eq 2)
{
write-host "if is working"
$script:ChosenFunction=userInfo
}
}
function userInfo
{
cls
$Name=Read-Host "Enter user name: "
Write-Host "finding $Name"
Get-ADUser $Name -Properties Description # <---- Here's my problem get user's AD information
}