PowerShell 是否会产生副作用,即创建一个以数字命名的文件?

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

我的笔记本昨天修完回来了。它的 HDD 换成了 SSD,全新安装了 Windows 10 Home Single Language (Update 1903),没有备份。它还带有一个名为 'user' 之类的管理员帐户。这个细节很烦人。

我本应该打出更好的研究拳头,但我太心急了。所以,我的第一个尝试是在控制面板上更改用户名。但用户文件夹名称保持不变。然后,我执行 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' porque ele não existe.
No linha:1 caractere:11
+ 1, 2, 3 | Get-ItemProperty
+           ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Windows\system32:String) [Get-ItemProperty], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

我觉得很奇怪,因为有一个 table 信息与错误消息混合在一起,就像它确实改变了什么一样。

我查看了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

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

抱歉这么久了 post。提前谢谢你。

每次执行“> 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