Search code examples
powershellwindows-10filenamesuser-accountsside-effects

Does PowerShell produce a side effect that creates a file named with a number?


My notebook came back from a repair yesterday. Its HDD was replaced with an SSD, with a fresh installation of Windows 10 Home Single Language (Update 1903), no backup. It also came with an administrator account called something like 'user'. This detail was bothering.

I should have made a better research fist, but I was too impatient. So, my first try was changing user name on Control Panel. But the user folder name remained the same. Then, I executed Control UserPasswords2 and changed the username there. Running it second time, I couldn't see any user listed, but I just had to reboot. I don't remember what user name was there before, but by then the new one was displayed. But, again, the folder name didn't change.

I noticed another strange thing: my Wi-Fi was duplicated. I could use, let's say, 'NET' and 'NET 2'. This was solved by removing both networks. Just in case, I checked whether the Temp folder was duplicated, and it wasn't.

Then, I made a longer research and many places were indicating a solution which required changing all matching user path values in registry, about 100 entries. Using a PowerShell script looked a good idea. I didn't found any code for that, but I was already playing with PowerShell. Trying some simple things.

I thought that sticking to Get- commands and avoiding Set- would be safe. But when I executed the following:

PS C:\Windows\system32> 1, 2, 3 | Get-ItemProperty

The output was:

    Diretório: C:\Windows\system32


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       14/07/2019     11:21              8 1
-a----       14/07/2019     11:10              2 2
Get-ItemProperty : Não é possível localizar o caminho 'C:\Windows\system32\3' porque ele não existe.
No linha:1 caractere:11
+ 1, 2, 3 | Get-ItemProperty
+           ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Windows\system32\3:String) [Get-ItemProperty], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

I found it strange, because there was a table with information mixed with an error message, like it did altered something.

I looked at System32 folder and there were two files, without extension, named as 1 and 2. Those are the only files created and modified today in that folder. And 1 is older than 2.

Here is what is inside 1:

3

The file 2 is empty.

The files stay there even closing the PowerShell.

Here is the history of commands I executed at the last (and only, I think) session:

PS C:\Windows\system32> help GetItemProperty 

PS C:\Windows\system32> GetChildItem -path HKCU:\ | GetItemProperty

PS C:\Windows\system32> Get-ChildItem -path HKCU:\ | Get-ItemProperty

PS C:\Windows\system32> Get-ChildItem -path HKCU:\

PS C:\Windows\system32> Get-ChildItem -path HKCU:\ | Get-ItemProperty Name

PS C:\Windows\system32> Get-ChildItem -path HKCU:\ | Get-ItemProperty -Name

PS C:\Windows\system32> Get-ChildItem -path HKCU:\ | Get-ItemProperty -Property "Name"

PS C:\Windows\system32> Get-ChildItem -path HKCU:\ | Get-ItemProperty

PS C:\Windows\system32> Get-ChildItem -path HKCU:\

PS C:\Windows\system32> 1,2,3 | Get-ItemProperty

PS C:\Windows\system32> 1, 2, 3 | Where $_ > 2

PS C:\Windows\system32> 1, 2, 3 | Where ($_ > 2)

PS C:\Windows\system32> 1, 2, 3 | Where $PSItem > 2

PS C:\Windows\system32> 1, 2, 3 | Where $_ -eq 2

PS C:\Windows\system32> 1, 2, 3 | Where -($_ > 2)

PS C:\Windows\system32> 1, 2, 3 | Where-Object $_ -eq 2

PS C:\Windows\system32> 1, 2, 3 | Where-Object -$_ -eq 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ -eq 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ = 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ == 2

PS C:\Windows\system32> 1, 2, 3 | Where - $_ -eq 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ -eq 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ -greater 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ -gt 2

PS C:\Windows\system32> 1, 2, 3 | Where -$_ -gt 0

PS C:\Windows\system32> 1, 2, 3 | Where -gt 0

PS C:\Windows\system32> 1, 2, 3 | Where-Object -$ -gt 1

PS C:\Windows\system32> 1, 2, 3 | Where-Object -$_ -gt 1

PS C:\Windows\system32> 1, 2, 3 | Where-Object -gt 1

PS C:\Windows\system32> 1, 2, 3 | Where -Property $_ Value 2

PS C:\Windows\system32> help Where

PS C:\Windows\system32> 1, 2, 3 | Where { $_ > 1 }

PS C:\Windows\system32> 1, 2, 3 | % { $_ > 1 }

PS C:\Windows\system32> 1, 2, 3 | % { $_ > 1 } | Write

PS C:\Windows\system32> 1, 2, 3 | % { $_ > 1 } | Write-Verbose

PS C:\Windows\system32> 1, 2, 3 | Where { $_ -eq 1 }

PS C:\Windows\system32> 1, 2, 3 | Where { $_ -gt 1 }

PS C:\Windows\system32> 1, 2, 3 | % { $_ -gt 1 }

PS C:\Windows\system32> 1, 2, 3 | % { if ($_ -gt 1) { Write $_ } }

PS C:\Windows\system32> help Write

PS C:\Windows\system32> 1, 2, 3 | Get-ItemProperty

I'm not planning changing registry, I think just putting back the old name and creating a separate account is fine. But should I be worry with that two files?

Sorry for the long post. Thank you in advance.


Solution

  • Any time you're doing "> 1" you're creating a file called "1". Or "> 2" for "2". It's (almost) the same as | out-file 1. Greater than in powershell is "-gt". You seemed to catch on to that later.

    echo hi > 1  # makes a file, encoded in unicode
    echo hi > 2  # can also overwrite a file
    echo hi >> 1  # append a file, but can mix encodings
    echo hi >> 2
    

    Yes, these make a file called "1", even with a terminating error.

    1 | where $_ > 1
    1 | where ($_ > 1) 
    1 | where -($_ > 1)
    1 | where $psitem > 1