标签: powershell

使用“powershell”命令行创建多个文件夹时出错

我正在尝试windows powershell通过在命令行中键入来创建多个文件夹mkdir folder-one folder-one/sub-folder folder-two

但是,我收到以下错误:

C:\Tutorials\try> mkdir folder-one folder-one/sub-folder folder-two
mkdir : A positional parameter cannot be found that accepts argument 'folder-one/sub-folder'.
At line:1 char:1
+ mkdir folder-one folder-one/sub-folder folder-two
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [mkdir], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,mkdir
Run Code Online (Sandbox Code Playgroud)

我这里的命令有什么问题?谁能帮我创建多个文件夹(嵌套文件夹)?

windows-7 powershell

3
推荐指数
1
解决办法
1287
查看次数

Chocolatey 无法安装应用程序,“您想如何打开此文件?” 对话框被打开

该对话框,当我运行任何打开choco install*的命令,手动浏览到choco.exeC:\ProgramData\chocolatey没有解决这个问题:

在此处输入图片说明

PowerShell 版本:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14393  0
Run Code Online (Sandbox Code Playgroud)

我通过运行安装了 Chocolateyiwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        24.8.2016     11.09                chocInstall
Getting latest version of the Chocolatey package for download.
Downloading https://chocolatey.org/api/v2/package/chocolatey/0.10.0 to C:\Users\user\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip
Download 7Zip commandline tool
Downloading https://chocolatey.org/7za.exe to C:\Users\user\AppData\Local\Temp\chocolatey\chocInstall\7za.exe
Extracting C:\Users\user\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\user\AppData\Local\Temp\chocolatey\chocInstall...

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Processing archive: C:\Users\user\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip …
Run Code Online (Sandbox Code Playgroud)

powershell chocolatey

3
推荐指数
1
解决办法
1224
查看次数

如何获取空闲时触发的任务列表?

有没有办法通过cmdpowershell空闲时触发的任务列表来获取?


为什么我需要它?

svchost.exe当我有一段时间不做任何事情时,我注意到 CPU 消耗 (25%)正在运行。为了确认这一点,我让 sysinternals 的进程资源管理器运行,几分钟后 svchost 出现。我不知道如何追踪它,因为一旦我移动鼠标,它就会消失并停止,所以我无法看到更多细节。

powershell cmd.exe windows-10

3
推荐指数
1
解决办法
1458
查看次数

Powershell 脚本不删除子项

运行 PowerShell 脚本时出现错误。它在说明

Microsoft.Powershell.Core\FileSystem::\[path to directory] ​​中的项目有子项,并且未指定 Recurse 参数。

在我的 PowerShell 脚本中,我确实指定了它。是不是在错误的位置?

# Add CmdletBinding to support -Verbose and -WhatIf 
[CmdletBinding(SupportsShouldProcess=$True)]
param
(
# Mandatory parameter including a test that the folder exists       
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_ -PathType 'Container'})] 
[string] 
$Path,

# Optional parameter with a default of 60
[int] 
$Age = 60   
)

# Identify the items, and loop around each one
Get-ChildItem -Path $Path -Recurse -Force | where {$_.lastWriteTime -lt (Get-Date).addDays(-$Age)} | ForEach-Object {

# display what is happening …
Run Code Online (Sandbox Code Playgroud)

powershell

3
推荐指数
1
解决办法
6057
查看次数

Powershell 自动完成设置。

我想知道是否有办法改变当前 powershell 自动完成的工作方式。我一直在使用 bash 并对其进行了更改,以提供一些我希望在我的 powershell 体验中使用的功能。

目前powershell,因为我正在编写一个带有文件夹的命令,它将选项卡自动完成并循环浏览我的文件夹。这是我喜欢的方式,但我想念的一个功能是使用命令的部分匹配并按下向上键,它会找到与我所做的其余部分匹配的命令。

所以我写'回声测试'然后我写其他命令并尝试'ec'并点击并且'回声测试'将完成而不是我输入的最后一个命令

只是想知道是否有办法让这个回来?

powershell

3
推荐指数
1
解决办法
1万
查看次数

Powershell 在删除目录时抛出错误

我正在尝试使用以下命令删除大型目录:( rajkaml 是文件夹名称)

rmdir /s /q rajkamal
Run Code Online (Sandbox Code Playgroud)

但得到错误为:

Remove-Item : A positional parameter cannot be found that accepts argument '.\rajkamal'.
At line:1 char:6
+ rmdir <<<<  /s/q .\rajkamal
    + CategoryInfo          : InvalidArgument: (:) [Remove-Item], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Run Code Online (Sandbox Code Playgroud)

如何解决?我的命令有什么问题?

提前致谢。

powershell

3
推荐指数
1
解决办法
5888
查看次数

是否默认启用受限语言模式?

默认情况下,Powershell 中是否启用了约束语言模式?在最新的 Windows 10 FCU 版本中,是最新的

powershell security-policy windows-10

3
推荐指数
1
解决办法
1万
查看次数

通过 CMD/Powershell 禁用 Windows 10 快速启动

我与 Ubuntu 一起双启动 Windows 10。当我尝试从 Ubuntu 访问我的 NTFS (Windows) 驱动器时,我经常会收到类似这样的错误。

Error mounting /dev/sda5 at /media/mani/0AC217250AC21725:  
Command-line `mount -t "ntfs" -o "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000" "/dev/sda5" "/media/mani/0AC217250AC21725"' exited with non-zero exit status 14:  
The disk contains an unclean file system (0, 0).  
Metadata kept in Windows cache, refused to mount.  
Failed to mount '/dev/sda5': Operation not permitted  
The NTFS partition is in an unsafe state. Please resume and shutdown Windows fully (no hibernation or fast restarting), or mount the volume read-only with the 'ro' …
Run Code Online (Sandbox Code Playgroud)

powershell command-line cmd.exe windows-10

3
推荐指数
1
解决办法
5万
查看次数

使用powershell搜索pdf内容并输出文件列表

这是我想要做的:

我有一大堆各种格式的文件(大约一万个)。每个文件都可以定义为某种类型(例如:产品表、商业计划、报价、演示文稿等)。这些文件没有特定的顺序,不妨将其视为一个列表。我有兴趣按类型创建目录。

这个想法是,对于某种格式和某种类型,我知道要在文件内容中查找哪些关键字。我想要一个 powershell 脚本,它基本上执行一系列脚本,查找包含特定关键字的特定格式的所有文件,并将每个列表输出到单独的 csv。这里的关键点是关键字将在内容(pdf 的正文、excel 的单元格等)中,而不是在文件名中。到目前为止,我已经尝试了以下方法:

get-childitem -Recurse | where {!$_.PSIsContainer} |
select-object FullName, LastWriteTime, Length, Extension | export-csv -notypeinformation -delimiter '|' -path C:\Users\Uzer\Documents\file.csv  -encoding default
Run Code Online (Sandbox Code Playgroud)

这很好,并为我提供了完整的文件列表,包括它们的大小和扩展名。我正在寻找类似但按内容过滤的东西。有任何想法吗?

编辑:基于她下面的解决方案的新代码:

$searchstring = "foo"
$directory = Get-ChildItem -include ('*.pdf') -Path "C:\Users\Uzer\Searchfolder" -Recurse

foreach ($obj in $directory)
{Get-Content $obj.fullname | Where-Object {$_.Contains($searchstring)}| select-object FullName, LastWriteTime, Length, Extension | export-csv -notypeinformation -delimiter '|' -path C:\Users\Uzer\Documents\file2.csv  -encoding default}
Run Code Online (Sandbox Code Playgroud)

但是我收到了一堆这些错误:

 An object at the specified path C:[blabla]\filename.pdf does not exist, or has been filtered by …
Run Code Online (Sandbox Code Playgroud)

pdf powershell

3
推荐指数
2
解决办法
3万
查看次数

是否有将 evt 转换为 csv 的 Powershell 方法?

我有许多来自旧操作系统的日志文件需要转换为 csv。有没有办法使用 Powershell 做到这一点?

powershell

3
推荐指数
1
解决办法
8316
查看次数