问题标签 [new-item]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
21 浏览

powershell - 如何使用带有 $Version 的 New-Item 创建文本文件

我已经从注册表中提取了一些信息,Get-ItemPropertyValue并希望使用它来创建具有该值的文本文件。

示例输出 - 21H1

尝试New-Item$Version输出一起使用来创建一个文本文件,21H1.txt

0 投票
2 回答
49 浏览

powershell - 在 pwershell 中使用 %userProfile% 环境变量创建路径时出现意外行为

我编写了一个脚本来创建一系列符号链接。我想将目标值设置为 $shortpath 其中

$shortpath 变量的值是有效的,我可以从运行命令打开它。PS 在创建符号链接时尝试写入的字符串与预期的不同。我希望它会写入字符串的值,或者至少插入 Env 变量的值。而是添加到我传递给它的字符串中。

我希望目标值为: c:\Users\UserName\dir1\dir2\dir3\filename.ext 或 %userprofile%\dir1\dir2\dir3\filename.ext

相反,我得到: C:\windows\system32%UserProfile$\dir1\dir2\dir3\filename.ext

写入日志文件的输出示例:

谁能阐明为什么会发生这种情况?如果我使用 mklink,也会发生同样的事情。我在下面添加了整个脚本:


0 投票
0 回答
14 浏览

powershell - 创建符号链接时,Powershell New-Item 调用预先添加路径信息

当我尝试创建一个新的符号链接链接并将目标(值)路径设置为字符串“%UserProfile%\dir1\dir2\file.ext”时,生成的路径前面会加上运行脚本的目录。

因此,如果我从 c:\scripts\ 运行脚本,值将变为 c:\scripts%UserProfile%\dir1\dir2\filename.ext。有人知道解决这个问题的方法吗?我可以修改现有的符号链接以使用此路径,它按预期运行,但似乎无法以编程方式执行此操作。

注意: MkLink 和 comobject.createshortcut 表现出相同的行为。