0

我正在尝试每天在服务器上自动构建文件夹结构。该脚本有效,但由于某种原因,它在我的桌面而不是服务器上构建它。

#get date info
$ymd = Get-Date -Format yyyy_MM_dd

#name server paths
$x = '\\server\x'

#build out the internal retouch structures for the projects
'folder1', 'folder2', 'folder3\a', 'folder3\b' |  % {New-Item -Name "$x\$ymd\$_" -ItemType 'Directory'}

即使我键入服务器路径,它也会在我的桌面上构建它:

#get date info
$ymd = Get-Date -Format yyyy_MM_dd

#name server paths
$x = '\\server\x'

#build out the internal retouch structures for the projects
'folder1', 'folder2', 'folder3\a', 'folder3\b' |  % {New-Item -Name "\\server\x\$ymd\$_" -ItemType 'Directory'}

它正在建造的道路不是\\server\x\$ymd\...C:\Users\username\Desktop\server\x\$ymd\...

如果我在 ISE 中运行它或右键单击并使用 powershell 运行,就会发生这种情况。我如何告诉它从字面上使用服务器路径而不是在本地环境中构建它?我每天访问服务器并在服务器上使用 powershell 都没有问题,我以前没有尝试过像这样制作文件夹结构,所以我假设我忽略了代码中的一些简单内容。

4

1 回答 1

1

问题是,当您不使用-Path当前位置时,默认使用。这是这个 cmdlet的MS Docs所说的:

“...省略Path时默认为当前位置...”

此外,很高兴知道这-Path是此函数位置 0 处的参数。如果你在不使用任何参数的情况下放置路径,你就不会遇到这个问题:)

于 2021-04-12T14:13:23.380 回答