Admin Power Level: Intermediate Chapter 15: Small Commands, Big Everyday Wins
Host, files, time, and keyboard
Four small jobs, one lesson: rename a computer, write text to a file, read the date and time, and change the keyboard layout list.
Lesson 4 of 5 in Chapter 15: Small Commands, Big Everyday Wins. Previous step in this path: Network: adapters, IP addresses, and DNS. 3 learning objectives, 7 examples, and a knowledge check.
Start: what you will learn
Four small jobs, one lesson: rename a computer, write text to a file, read the date and time, and change the keyboard layout list.
Learning objectives
- Rename a computer with Rename-Computer
- Write text to a file
- Read and format date and time, and change the keyboard list
Concept in simple words
What it is: this lesson covers four small jobs in one place: renaming a computer, writing text to a file, reading the date and time, and changing the keyboard language list. Each job has its own cmdlet, and each one is short, so this lesson is really about picking the right short tool for each job, and about the one classic mistake that belongs to each tool.
Why it works
Why these four belong together: on a real admin day, these are the jobs you do between the big jobs. You rename a fresh computer so it fits your naming plan, you write a short note or log line to a file, you stamp a file name or a log with the date and time, and you fix a keyboard list so a user can type in the language they need. None of them needs a long script, but each of them can go wrong in a small, annoying way, and this lesson teaches you the safe habit for each one.
Renaming, in depth: Rename-Computer renames the local computer, or one remote computer, and it renames one computer in each command. The new name goes in -NewName, and -Restart restarts the computer at once so the change takes effect, while leaving -Restart out means you must restart later yourself. A restart is often required to make the change effective, so a rename without a restart can leave the old name showing in some places, which confuses everyone. -WhatIf shows what would happen without renaming anything, which is the safe first run, and -Force skips the confirmation prompt, so only use it after you have checked the names.
Computer name rules, in plain words: keep names short and simple, with letters, digits, and hyphens, such as Office-PC-01. Avoid spaces, underscores, periods, and special characters, avoid a name made only of numbers, and avoid starting or ending with a hyphen. As a practical rule, keep the name to 15 characters or fewer, because longer names can cause compatibility problems with older naming limits, even if a longer name seems to be accepted at first. If a name breaks these rules, check it before you run the rename, not after a restart that did not fix the confusion.
Files, in depth: Set-Content writes text to a file, replacing it if it already exists. Add-Content adds text to the end of a file, without deleting what is already there. Get-Content reads a file back. In each case, -Path names the file, with a full path so there is no doubt about which file you mean, and -Value gives the text to write or add. If the folder in the path does not exist, the write fails, just like a download to a missing folder fails, so check the folder first, or create it before you write.
Time, in depth: Get-Date returns the current date and time as a DateTime object, which is a structured value you can inspect, not just a line of text. Without -Format, you get that object, and you can read parts of it with dot notation, such as Year, Month, Day, Hour, and Minute. With -Format and a pattern string, you get a text string instead, which is perfect for a file name or a log line, but you cannot do date maths on that string afterwards, so keep the object when you need to calculate, and format only when you need to display or store text.
Date format tokens, the ones you will use most: yyyy means the four digit year, MM with capitals means the month, dd means the day, HH means the hour on a 24 hour clock, hh with small letters means the hour on a 12 hour clock, mm with small letters means minutes, ss means seconds, MMMM means the full month name, dddd means the full day name, and tt means AM or PM. The capitals matter: MM is month and mm is minutes, so yyyy-mm-dd gives you minutes where you wanted the month, which is one of the most common date mistakes in PowerShell. For file names, yyyyMMdd_HHmmss is a strong choice, because it has no characters a file name forbids, and it sorts in time order.
Keyboard languages, in depth: Get-WinUserLanguageList reads the language list for the current user, and Set-WinUserLanguageList sets that list. The list holds language objects, each with a language tag such as en-US or fr-FR, plus its input methods, which are the keyboard layouts tied to that language. The order of the list matters, because the first language is the main one, and the user switches between the listed languages when typing. New-WinUserLanguageList creates a fresh list for one language, which is useful when you want to start clean, but dangerous if you use it to replace a list that still holds languages someone needs.
The keyboard habit that saves you: never set a brand new single language list without reading the old list first. The safe pattern is to read the current list into a variable, add a language to that variable with the Add method, and then set the whole revised list back. That way you add, instead of replacing, and you keep every language that was already there. Set-WinUserLanguageList replaces the whole list with whatever you give it, so giving it a one language list removes every other language, even if you only meant to add one.
Think of it like this
Think of it like this: a set of small tools in one drawer. A label maker renames a box, a notebook either gets a fresh page or a new line added at the end, a clock tells you the time in the format you ask for, and a language switch changes which keyboard layout you type with. You would not use the label maker to add a line to a notebook, and the same idea applies here, each cmdlet has one job, and the skill is choosing the right one and checking the result.
How it works, step by step
How it works, step by step, for a rename: First, check the current name, and choose a new name that follows the name rules above. Second, run Rename-Computer with -WhatIf first, and read the preview carefully, checking that the new name is exactly the one you meant. Third, save all open work, warn anyone using the computer, and only then run the real rename, with -Restart if you want the restart at once, or plan a restart right after if you leave it out. Fourth, after the restart, check the new name, because the job is not done until the new name shows where it should.
How it works, step by step, for a file: First, decide whether you want to replace or append, because that one choice decides between Set-Content and Add-Content. Second, use a full path, and check that the folder exists. Third, write the text, then read the file back with Get-Content, so you can see whether the old content is still there when you appended, or gone when you replaced. That read back step is the difference between hoping and knowing, and it takes one extra line.
How it works, step by step, for time: First, run Get-Date on its own and look at the object it returns. Second, decide whether you need a value for maths, in which case keep the object, or a string for a file name or log, in which case add -Format with a pattern. Third, build the pattern token by token, checking capitals as you go, especially MM for month and mm for minutes, and HH for 24 hour time versus hh plus tt for 12 hour time. Fourth, test the pattern once and read the result, because a pattern that looks right can still give minutes instead of months.
How it works, step by step, for keyboard languages: First, read the current list with Get-WinUserLanguageList, and note which languages are already there, in which order. Second, if you want to add a language, copy that list into a variable, add the new language tag to the variable, and set the revised list back, instead of building a fresh one language list. Third, answer the confirmation prompt carefully, and check the list again after, to prove the new language is there and the old ones are still there. If a language you needed has gone missing, you have replaced instead of adding, and you need to add it back.
Let us walk through the first example: take Get-Date -Format "yyyy-MM-dd HH:mm". Get-Date reads the current date and time. -Format turns that datetime object into a text string in the pattern you give, where yyyy means the four digit year, MM means the month with a capital M, dd means the day, HH means the hour, and mm with a small m means minutes. In the output, look for a tidy string such as 2026-11-03 21:00, which sorts well in file names and logs because year comes first. If you change MM to mm, the month position will show minutes instead, which is an easy way to spot this classic mistake in your own output.
Let us walk through the second example: take Set-Content -Path "C:\Temp\note.txt" -Value "Hello from PowerShell". -Path names the file, and -Value gives the text to write. If the file does not exist yet, it is created, and if it already exists, its old content is replaced, not added to. In the output, look for a confirmation that the file was written, and then read it back if you want proof, because the write itself does not print the file content. If you change Set-Content to Add-Content here, an existing file keeps its old lines and gains a new one, which is the whole difference between the two cmdlets.
Let us walk through the third example: take Add-Content -Path "C:\Temp\note.txt" -Value "Second line" on the first line, then Get-Content -Path "C:\Temp\note.txt" on the second line. Add-Content appends text to a file without replacing what is already there, where -Path names the file and -Value gives the new line. Get-Content then reads the file back, using the same path, so you can see both the original line and the new line together and confirm the append worked instead of replacing the file. If the second line shows only the new line, the first line was a replace, not an append, and the old content is gone, which is why the read back matters.
Let us walk through the fourth example: take Rename-Computer -NewName "Office-PC-01" -WhatIf. -NewName gives the new name, and -WhatIf is a preview switch, which means PowerShell shows what would happen without actually renaming anything. In the output, look for a what if message naming the rename, and read the new name letter by letter, because this is your last cheap chance to catch a typo. If the preview names a computer you did not mean, stop, because the real command renames one computer, and a wrong target means a wrong rename plus a restart to fix it.
Let us walk through the fifth example: take Rename-Computer -NewName "Office-PC-01" -Restart. This is the same rename, but real, and -Restart restarts the computer at once so the change takes effect. Warning: only rename your own computer, with permission, and only after you have saved all open work and warned anyone using the computer, because -Restart does not wait for unsaved work. After the restart, check the new name, and expect the old name to still show in a few cached places until those places refresh, which is normal, but the computer itself should now carry the new name.
Let us walk through the sixth example: take Get-WinUserLanguageList. With no extra parameters, this reads the language list for the current user and shows each language in it. In the output, look for the language tags, such as en-US, and note the order, because the first language is the main one. If you only see one language and you expected three, that is a clue that an earlier set replaced the list instead of adding to it, and the missing languages need to be added back with the pattern in the next example.
Let us walk through the seventh example: take $list = Get-WinUserLanguageList on the first line, $list.Add("fr-FR") on the second line, and Set-WinUserLanguageList -LanguageList $list on the third line. The first line reads the current list into a variable called $list. The second line adds French (France), with the tag fr-FR, to that variable, keeping every language that was already there. The third line sets the whole revised list back, with -LanguageList naming the variable to set. If you change the second line to a different tag, you add a different language, but the pattern stays the same: read first, add to the copy, set back, and then read again to prove the old languages survived.
Worked examples
Read each example in order. Each one explains its parts, then shows what to look for in the output.
Syntax
Rename-Computer -NewName <Name>Example 1
Formats the current date and time as a sortable string, useful in file names and logs. yyyy is the four digit year, MM with capitals is the month, dd is the day, HH is the hour on a 24 hour clock, and mm with small letters is minutes. If you swap MM and mm, you get minutes where you wanted the month.
Get-Date -Format "yyyy-MM-dd HH:mm"Illustrative output: 2026-11-03 21:00
Example 2
Writes text to a file, replacing it if it already exists. -Path names the file, and -Value gives the text. Use Add-Content to append instead. The folder in the path must already exist, or the write fails.
Set-Content -Path "C:\Temp\note.txt" -Value "Hello from PowerShell"Illustrative output: File C:\Temp\note.txt written.
Example 3
Add-Content appends text to a file without replacing what is already there, where -Path names the file and -Value gives the new line. Get-Content then reads the file back, using the same path, so you can see both the original line and the new line together and confirm the append worked instead of replacing the file.
Add-Content -Path "C:\Temp\note.txt" -Value "Second line"
Get-Content -Path "C:\Temp\note.txt"Illustrative output: Hello from PowerShell Second line
Example 4
Previews a rename without doing it. -NewName gives the new name, and -WhatIf shows what would happen, so you can check the new name letter by letter before the real run. Always preview first, especially when a wrong target would mean a wrong rename plus a restart to fix it.
Rename-Computer -NewName "Office-PC-01" -WhatIfIllustrative output: What if: Performing the operation "Rename Computer" on target "Office-PC-01".
Example 5
Renames the computer for real, and -Restart restarts it at once so the change takes effect. Warning: only rename your own computer, with permission, and only after you have saved all open work and warned anyone using the computer, because the restart does not wait for unsaved work. Check the new name after the restart.
Rename-Computer -NewName "Office-PC-01" -RestartIllustrative output: Computer renamed to Office-PC-01. Restarting.
Example 6
Reads the language list for the current user, with no extra parameters needed. Look for the language tags in order, because the first language is the main one. If a language you expected is missing, an earlier set probably replaced the list instead of adding to it.
Get-WinUserLanguageListIllustrative output: LanguageTag en-US
Example 7
The first line reads the current list into $list. The second line adds French (France), tag fr-FR, to that variable, keeping every language already there. The third line sets the whole revised list back, with -LanguageList naming the variable. Read the list again after, to prove the old languages survived and the new one was added.
$list = Get-WinUserLanguageList
$list.Add("fr-FR")
Set-WinUserLanguageList -LanguageList $listIllustrative output: Language list updated.
Nothing on this page executes PowerShell code. The outputs above are illustrative only.
Common mistakes and troubleshooting
Read these before you try the examples, so you can spot the same problems in your own work.
- Renaming a computer and forgetting the restart, then wondering why the old name still shows.
- Using Set-Content when you meant to append, and losing the old file content. Use Add-Content for appends.
- Writing a date format with a small mm for the month, as in yyyy-mm-dd, and getting minutes instead of the month, because in date formats MM with capitals means month while mm with small letters means minutes.
- Using HH for a 12 hour clock, or hh without tt, and getting a time that does not say AM or PM, so 03:00 could mean morning or afternoon. Use HH for 24 hour time, or hh plus tt for 12 hour time with AM or PM.
- Formatting a date into a string with -Format, and then trying to do date maths on that string, which no longer behaves like a date. Keep the DateTime object for maths, and format only for display or for a file name.
- Setting a fresh one language list with Set-WinUserLanguageList, and removing every other language someone needed, because Set replaces the whole list. Read first, add to the existing list, set back, and read again.
- Renaming with a name that breaks the rules, such as spaces, a name made only of numbers, or a very long name, or running a rename with -Restart before saving work. Preview with -WhatIf first, save work, and only rename your own computer with permission.
Knowledge check
Knowledge check
Which cmdlet appends text to an existing file without replacing it?
Pick one answer. Feedback appears right away, and you can try again.
Remember this and next step
Remember this: replace is Set-Content, append is Add-Content, time is Get-Date with a format, and a rename needs a restart. Four small tools, each with one clear job, and the habit of reading first will save you from the classic mistakes: losing file content, getting minutes instead of months, removing a keyboard language you still needed, and wondering why a new name has not appeared yet. Preview a rename with -WhatIf, read a file back after a write, test a date pattern once, and read a language list before you set it, and these small jobs will stay small.
Next step: CSV: import and export