# Script that displays computer name backwards

**URL:** <https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331>\
**Category:** PowerShell Help\
**Created:** [January 11, 2022, 11:33am UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331 "2022-01-11T11:33:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luzuko\_Goduka](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Luzuko\_Goduka](https://forums.powershell.org/u/Luzuko_Goduka)\
**Post date:** [January 11, 2022, 11:33am UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/1 "2022-01-11T11:33:29Z")

</div>

Hi All,

I am new on Powershell and I have been give this task and I am struggling with it please help.

Create a script that obtains the machine name. The script should then write out the machine name  
backwards and store it in task3.txt in the user’s temporary directory (C:\Temp or tmp). You must use a loop  
to achieve this.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 11, 2022, 12:20pm UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/2 "2022-01-11T12:20:57Z")

</div>

Luzuko,  
Welcome to the forum. 👋🏽

> [@Luzuko\_Goduka](#):
>
> I have been give this task

If this is a homework assignment or something similar you should approach your teacher or tutor if you have problems with the task.

Regardless of that - as this is actually a fairly easy and basic task - what are you struggling with exactly?

You may start with reading the help following help topics:

> **[about Environment Variables - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.2)**
>
> Describes how to access and manage environment variables in PowerShell.

> **[about For - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_for?view=powershell-7.2)**
>
> Describes a language command you can use to run statements based on a conditional test.

> **[Out-File (Microsoft.PowerShell.Utility) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.2)**
>
> The Out-File cmdlet sends output to a file. It implicitly uses PowerShell's formatting system to write to the file. The file receives the same display representation as the terminal. This means that the output may not be ideal for programmatic...

---

<div class="post-metadata">

**Author:** ![Luzuko\_Goduka](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Luzuko\_Goduka](https://forums.powershell.org/u/Luzuko_Goduka)\
**Post date:** [January 11, 2022, 12:31pm UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/3 "2022-01-11T12:31:01Z")

</div>

I am struggling with creating a loop that will display the computer name backwards and it is not a homework from school but I am learning how to script now

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 11, 2022, 12:35pm UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/4 "2022-01-11T12:35:35Z")

</div>

The second link I posted in my answer actually has the answer. 😉

Consider the name of the computer as an array of characters. If you know the length of the array you can set up a loop decreasing the index of the characters iterating over all single characters starting with the last (highest index). 😉

---

<div class="post-metadata">

**Author:** ![Luzuko\_Goduka](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Luzuko\_Goduka](https://forums.powershell.org/u/Luzuko_Goduka)\
**Post date:** [January 11, 2022, 7:45pm UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/5 "2022-01-11T19:45:11Z")

</div>

Thank you I managed to create the script

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 11, 2022, 8:44pm UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/6 "2022-01-11T20:44:38Z")

</div>

> [@Luzuko\_Goduka](#):
>
> I managed to create the script

Great. I’m proud of you. 👍🏽 🙂

Would you like to share your solution here? It might help others looking for the same or something similar. 😉

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:19pm UTC](https://forums.powershell.org/t/script-that-displays-computer-name-backwards/18331/7 "2024-05-16T20:19:50Z")

</div>

Closed on May 16, 2024, 8:19pm UTC


