Parity123
asked on
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,operatings ystem,Cano nicalName | select Name
}
$data | export-csv ./computerrecords.csv -NoType
Appreciate your help on this.
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,operatings
}
$data | export-csv ./computerrecords.csv -NoType
Appreciate your help on this.
ASKER
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:1 2 char:1
+ [Microsoft.VisualBasic.Int eraction]: :MsgBox($d ata)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException
Exception calling "MsgBox" with "1" argument(s): "Argument 'Prompt' cannot be
converted to type 'String'."
At C:\v\searchcomputer1.ps1:1
+ [Microsoft.VisualBasic.Int
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException
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.
what is in variable $data in your script? it's not a string and that seems to be your problem.
ASKER
[System.Reflection.Assembl y]::LoadWi thPartialN ame('Micro soft.Visua lBasic') | Out-Null
$computerName = [Microsoft.VisualBasic.Int eraction]: :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.Int eraction]: :MsgBox($d ata)
$computerName = [Microsoft.VisualBasic.Int
$domains = (Get-ADForest).Domains
$data = @()
$results=""
foreach ($domain in $domains)
{
$data += Get-ADComputer -Filter 'name -like $computername' -Server $domain -Properties name, description
}
[Microsoft.VisualBasic.Int
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
ASKER
Could you please help me with the syntax for -join with the array I have
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help, thanks for the feedback.
Open in new window