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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

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
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.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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)
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
Parity123Author Commented:
Could you please help me with the syntax for -join with the array I have
Nadav SolomonCommented:
$data2print = $data -join ","

Or

$data2print = $data | out-string

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.
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.