首页 > 解决方案 > PowerShell 是否会产生创建以数字命名的文件的副作用?

问题描述

我的笔记本昨天维修回来了。它的 HDD 被 SSD 取代,全新安装Windows 10 Home Single Language (Update 1903),没有备份。它还带有一个管理员帐户,称为“用户”。这个细节很烦人。

我本应该做一个更好的研究拳头,但我太不耐烦了。所以,我的第一次尝试是在控制面板上更改用户名。但用户文件夹名称保持不变。然后,我Control UserPasswords2在那里执行并更改了用户名。第二次运行它,我看不到任何列出的用户,但我只需要重新启动。我不记得以前的用户名是什么,但到那时显示的是新用户名。但是,同样,文件夹名称没有改变。

我注意到另一个奇怪的事情:我的 Wi-Fi 被复制了。例如,我可以使用“NET”和“NET 2”。这是通过删除两个网络来解决的。以防万一,我检查了 Temp 文件夹是否重复,但事实并非如此。

然后,我进行了更长时间的研究,许多地方都指出了一个解决方案,该解决方案需要更改注册表中所有匹配的用户路径值,大约 100 个条目。使用 PowerShell 脚本看起来是个好主意。我没有找到任何代码,但我已经在使用 PowerShell。尝试一些简单的事情。

我认为坚持Get-命令和避免Set-是安全的。但是当我执行以下操作时:

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

输出是:

    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

我觉得这很奇怪,因为有一个表格,其中包含混合了错误消息的信息,就像它确实改变了一些东西一样。

我查看了 System32 文件夹,有两个文件,没有扩展名,分别命名为12. 这些是今天在该文件夹中创建和修改的唯一文件。并且12.

这是里面的内容1

3

该文件2为空。

即使关闭 PowerShell,文件也会保留在那里。

这是我在最后一次(也是唯一一次)会话中执行的命令的历史记录:

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

我不打算更改注册表,我认为只需恢复旧名称并创建一个单独的帐户就可以了。但是我应该担心这两个文件吗?

对不起,很长的帖子。先感谢您。

标签: powershellwindows-10filenamesuser-accountsside-effects

解决方案


每当您执行“> 1”时,您都会创建一个名为“1”的文件。或 "> 2" 表示“2”。它(几乎)与| out-file 1. 比 powershell 更大的是“-gt”。你后来似乎明白了这一点。

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

是的,这些会生成一个名为“1”的文件,即使出现终止错误。

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

推荐阅读