标签: powershell

如何重置 powershell 中的所有别名

我最近将别名设置为非命令,因为我不知道如何使用设置别名。我想知道如何重置所有别名而不影响 powershell 附带的默认别名。

我尝试使用Remove-Alias但它返回给我这个错误:

PS C:\Users\me\Desktop\Projet\> Remove-Alias lua
Remove-Alias : The term 'Remove-Alias' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a 
path was included, verify that the path is correct and try again.
At line:1 char:1
+ Remove-Alias lua
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Remove-Alias:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

powershell bash shell command-line

2
推荐指数
1
解决办法
1679
查看次数

Ubuntu 上的 PowerShell 中是否有等效的“sudo”命令?

我想尝试使用 PowerShell 作为 Ubuntu 18.04 上的默认 shell,但是使用 bash,我可以选择运行一些命令,但sudo我不确定如何使用 PowerShell 来执行此操作,因为它没有sudo作为一个概念。

在 Windows 上的 PowerShell 中,您必须以管理员身份运行 shell。如果我将默认 shell 设置为 PowerShell,我担心如果没有 sudo,我将无法运行我可能需要的命令,我是否必须进入 bash?我不想默认以管理员身份运行默认 shell。

powershell ubuntu

2
推荐指数
1
解决办法
5026
查看次数

为计划的 powershell 脚本指定日志文件

我在 Windows 中创建了一个计划任务,以在特定时间运行 powershell 脚本。正如您所看到的,在操作页面中,我已指定 powershell 路径作为程序,并将我的脚本指定为参数。计划任务运行良好。

在此输入图像描述

我想包括我自己的日志文件,该文件在那里打印我的脚本的输出。我怎样才能做到这一点?

powershell scheduled-tasks

2
推荐指数
1
解决办法
6145
查看次数

如何重定向 Powershell Core 中的错误输出?

我试图将任何错误重定向到 null,但我似乎无法理解它。有什么帮助吗?

这是我的代码:$names | foreach-object{Copy-Item -Path C:\Users\$_\* -Destination C:\Users\$user\Desktop\${_}_removed -Recurse} | out-null

完整错误文本:
在此输入图像描述

powershell

2
推荐指数
1
解决办法
4942
查看次数

管理员命令可以使用终端正常运行,但不能在 .bat 文件中运行

我有以下命令:

& '.\FocusAssist\LGPO\LGPO.exe' /t '.\FocusAssist\disable_toast_notifications.txt'

如果我使用管理员权限打开 Windows Powershell,该命令将成功运行。

但是,如果我将此命令放入 .bat 文件(我们称之为disable_toast_notifications.bat)中,该命令将无法运行。我努力了:

  • 正常运行 .bat 文件并使用“以管理员身份运行”选项
  • '.\FocusAssist\LGPO\LGPO.exe' /t '.\FocusAssist\disable_toast_notifications.txt'& '.\FocusAssist\LGPO\LGPO.exe' /t '.\FocusAssist\disable_toast_notifications.txt'作为 的内容disable_toast_notifications.bat(区别在于&命令开头的 )。

如何成功运行这个 .bat 文件?.bat 文件是否需要不同的语法?

windows powershell command-line batch-file windows-11

2
推荐指数
1
解决办法
280
查看次数

颜色突出显示选择字符串 powershell

我有一个很大的日志文件(.log)。我试图找到一些需要突出显示的关键字,以便我可以更快地跳过日志中的其他行。但是,我不想只过滤选择字符串,而是突出显示选择字符串。另外,我对Powershell一无所知,到目前为止,我通过谷歌搜索得到了以下命令。

C:\users\proto> cat txtlog.log select-string "Valid" | write-host -foregroundcolor red
Run Code Online (Sandbox Code Playgroud)

它不会输出我想要的内容,因为它只返回红色的“有效”行,而不返回其他行。

windows powershell command-line

2
推荐指数
1
解决办法
5204
查看次数

如何查看在 PowerShell 控制台中运行的程序的退出代码

我确实需要检查在 Windows PowerShell 中运行的命令的数值。

\n

唯一$?返回 True 或 False,但我需要实际的错误号。

\n

那可能吗?在linux下就可以了,echo $?但是在Windows下就很难了!

\n
PS C:\\work\\> copy\n\nCmdlet Copy-Item an der Befehlspipelineposition 1\nGeben Sie Werte f\xc3\xbcr die folgenden Parameter an:\nPath[0]:\nPS C:\\work\\> echo $?\nFalse\nPS C:\\work\\>\n
Run Code Online (Sandbox Code Playgroud)\n

当您在这里时,正常命令提示符的解决方案是什么?

\n

windows powershell windows-10

2
推荐指数
1
解决办法
7919
查看次数

有没有办法使用 powershell (Win10) 识别设备的 PCIE 速度?

这样我就可以确定设备的传输速率并将其与 PCIE 设备的生成(PCIE 3.0、4.0 等)相关联

motherboard pci-express powershell windows-10

2
推荐指数
1
解决办法
5724
查看次数

Windows 终端中的语句完成显示但不参与

最近 Windows Terminal 进行了更新,并获得了历史记录建议。它看起来像这样:

在此输入图像描述

当我输入时,它会显示与我的输入相匹配的历史记录项。我以为按 Tab 会自动完成灰色部分,但事实并非如此。我尝试了各种其他热键,但它们也没有任何作用。我查看了 Windows 终端设置,但找不到任何相关内容。

我该怎么做才能完成文本?

PS 我不能 100% 确定这是否是 Windows 终端功能。我想它可能是 Powershell 或 PSReadLine。

windows terminal powershell windows-10 windows-terminal

2
推荐指数
1
解决办法
555
查看次数

使用 PowerShell 安装 msi 包

我正在尝试msi使用安装 Window 应用程序驱动程序包cmd /PS ,但无法管理它,因为该包似乎需要用户交互

msiexec /i D:\a\test\ultimate\WindowsApplicationDriver_1.2.1.msi /qn
Run Code Online (Sandbox Code Playgroud)

运行上面的命令并没有安装应用程序,而且我没有看到任何输出。我需要将此应用程序安装在默认位置,并在后台执行。

windows powershell

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