Powershell : Script assistance

Hello,

I want to prompt a window when I prompt for a server name (similar to inputbox in vbscript), and output the contents similar to msgbox window in vbscript.

I have the following script:

$domains = (Get-ADForest).Domains

$ComputerName = Read-Host 'Type in the server name'
$data = @()
foreach ($domain in $domains)
{
    $data += Get-ADComputer -Filter 'name -like $computername' -Server $domain -Properties PasswordLastSet,operatingsystem,CanonicalName | select Name
}
$data | export-csv ./computerrecords.csv  -NoType

Appreciate your help on this.
Parity123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nadav SolomonCommented:
You can keep using the one from VBscript:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$computer = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a computer name", "Computer", "$env:computername") 
[Microsoft.VisualBasic.Interaction]::MsgBox($computer)

Open in new window

0
Parity123Author Commented:
Thanks, I am getting an error on Msgbox line

Exception calling "MsgBox" with "1" argument(s): "Argument 'Prompt' cannot be
converted to type 'String'."
At C:\v\searchcomputer1.ps1:12 char:1
+ [Microsoft.VisualBasic.Interaction]::MsgBox($data)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException
0
Nadav SolomonCommented:
your error is on line 12, i supplied 3 lines, post your code and I might be able to help you, try those 3 lines alone and it should work.
what is in variable $data in your script? it's not a string and that seems to be your problem.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Parity123Author Commented:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$computerName = [Microsoft.VisualBasic.Interaction]::InputBox("Type in a server name","Test")

$domains = (Get-ADForest).Domains
$data = @()
$results=""
foreach ($domain in $domains)
{
    $data += Get-ADComputer -Filter 'name -like $computername' -Server $domain -Properties name, description
   
}
[Microsoft.VisualBasic.Interaction]::MsgBox($data)
0
Nadav SolomonCommented:
You are trying to output array in the messagebox which waits for string, you can -join the array in order to convert it to string
0
Parity123Author Commented:
Could you please help me with the syntax for -join with the array I have
0
Nadav SolomonCommented:
$data2print = $data -join ","

Or

$data2print = $data | out-string
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nadav SolomonCommented:
Glad I could help, thanks for the feedback.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.