question

sqlnubi avatar image
sqlnubi asked

Powershell help

I know this isn't a powershell forum, however I am working on a job in SQL Server that will utilize this script so I am hoping someone can help me. I have an array within powershell that I am needing to append values to the end of each row in the array. For example, lets say I have a list of servers. ServerA, ServerB, ServerC in one array, and alist of paths in another array. Backups, Scripts, BatchFiles, Patches, etc. What I am needing to do is for each value in the server array I am needing to append '\' and the value in the second array. So my output or new array would be ServerA\Backups ServerA\Scripts ServerA\BatchFiles ServerA\Patches ServerB\Backups .... and you get the point. Like I said, I have my two arrays built but I can't figure out how to merge/append/join them together. I can easily combine them but that doesn't help. Anyone have a clue how to do this? I am sure it is a single line solution that I am missing. Thanks.
powershell
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Tim avatar image
Tim answered
I have worked very little with Powershell but I have had to write a few scripts with help over the past couple of years. A few of them I have posted to my blog. I remembered having to append data before so I dug out an old script. This doesn't cover your situation with appending the values from one array to each value in another array, but this will allow you to append a value to each row in and array. $string = $array1 | Foreach-Object{ $_+'Backups'} You could define this multiple times if the values in your second array are static.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sqlnubi avatar image sqlnubi commented ·
Thanks for the quick response, that will get me going.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.