Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Object Type Problem

$
0
0

The following is a small part of code from a larger script.  I have the following:

 

$OldGroups = @("user_one", "user_two", "aaaaxx_11000")

foreach ($group in $OldGroups) {

    $new_var += "`""

    $new_var += $group

    $new_var += "`""

    $new_var += "`,"

}

$var = "user_one","user_two","aaaaxx_11000"

Write-Host " "

Write-Host "Var type:    "$var.GetType()

$new_var += "`"" + "asdfasdfasdf" + "`""

Write-Host "New_Var type:"  $new_var.GetType()

Write-Host " "

Write-Host "Working var:"$var

Write-Host "New_Var:    "$new_var

 

Output is as follows:

Var type:     System.Object[]

New_Var type: System.String

 

Working var: user_one user_two aaaaxx_11000

New_Var:     "user_one","user_two","aaaaxx_11000","asdfasdfasdf"

 

In order for the script to work properly, It would appear I need the $new_var variable to be the same type as the $var variable.  That would seem relatively simple but it certainly hasn't been to me.  I am also assuming when they are both the same var type, they will print the same which means they will both work in the larger script.  How can I make these the same var type?

Any help would be greatly appreciated.

Thank you.


Viewing all articles
Browse latest Browse all 6937

Trending Articles