我有一个家庭作业的问题,我不能完成它:
Write a shell that has two folder names as parameters and moves the second folder as subfolder of the first one and adds '.unu' to all filenames in that second folder.
这是我写的,但它不起作用:
gci D:\powershell\dir2 | foreach-object{ ren -new ($_.Name + ".unu")}
Copy-Item
如何传递$dir和$file,然后将它们到一条路径?
输出:
posh>
posh> pwsh ./worker.ps1
dir is /home/nicholas/powershell/regex a.log
file is
full is /home/nicholas/powershell/regex a.log/
posh>
库:
function SearchFile($dir,$file)
{
"dir is $dir"
"file is $file"
$full = [string]::Concat("full is
我在Windows 2019服务器上运行。
每当我从docker上的dockerfile调用powershell时,我都会收到一个错误。
->在6efa29aa8a4a中运行的命令“powershell -Command DIR”返回非零代码: 3221226505
Dockerfile..
# escape=` (backtick)
FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN DIR
RUN ["powershell", "-Command", "DIR"]
COPY
当我在Powershell中输入dir时,我想看到彩色文件名。因此,我在我的配置文件中添加了这里中的Set-ChildItemColor函数。我还在概要文件的末尾添加了这一行,以覆盖dir别名:
Set-Alias dir Get-ChildItemColor
现在,当我打开Powershell时,会得到以下错误:
Set-Alias : The AllScope option cannot be removed from the alias 'dir'.
At C:\Users\joe\Documents\WindowsPowerShell\Microsoft.PowerSh
如何在Powershell中递归列出目录?
我尝试过dir /S,但没有成功:
PS C:\Users\snowcrash> dir /S
dir : Cannot find path 'C:\S' because it does not exist.
At line:1 char:1
+ dir /S
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\S:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId
PowerShell似乎不识别\\?\符号。为什么不行?
=== cmd.exe
C:>ver
Microsoft Windows [Version 10.0.17763.1935]
C:>DIR "\\?\C:\Users\*"
Volume in drive \\?\C: is Windows
Volume Serial Number is 1C66-809A
Directory of \\?\C:\Users
2021-08-04 12:27 <DIR> .
2021-08-04 12:27 <DI
场景:
我对Powershell有点陌生,我希望能在这里得到一点帮助。看起来Powershell在运行此脚本后出现了会话内存泄漏。在尝试删除第58日志位置(如果我使用批处理文件运行此脚本)之后,它将停止,应该有93条总计可供删除。在进行了一些研究之后,我发现这是Microsoft的一个已知错误,在当前会话中执行powershell后,powershell不会完全关闭命令。
目标:
目标是编写一个自动化脚本,在执行命令时删除文件夹和文件,其日期要比用户输入的日期要早(使用天数)。
test1.ps1内容:
# Gets number of days input by user as a vari
将Powershell脚本组合在一起,我似乎得到了与dir (Get-ChildItem cmdlet)的-Directory开关不一致的行为。 如果我运行一个常规的Powershell实例并输入dir -Directory,它就能正常工作。 但是,当我把它放在一个.ps1文件中并运行它时,我得到的结果是: Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'. 怎么回事? 我使用的是装有Powershell 5.1的Windows 10
我有一个位于D:\temp的PowerShell脚本。
当我运行这个脚本时,我希望列出文件的当前位置。我该怎么做呢?
例如,下面的代码可以在DOS批处理文件中完成;我正在尝试将其转换为PowerShell脚本……
FOR /f "usebackq tokens=*" %%a IN ('%0') DO SET this_cmds_dir=%%~dpa
CD /d "%this_cmds_dir%"