标签: powershell

如何不终止批处理作业

在我的 power shell 命令提示符下,当我运行命令并按ctrl+ 时,会c出现一条消息,询问Terminate batch job (Y/N)?是否输入Y, 或Nn,它会终止作业。

我的问题是如何取消终止并保持应用程序运行?(因为好像提示没用)

请参阅下面的屏幕截图

在此处输入图片说明

terminal powershell batch command-line

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

Windows 10 版本 1803(2018 年 4 月更新)无法删除语言

更新最新版本后,我卡住了英语(美国)和英语(英国),并且不能删除它们。“删除”按钮呈灰色。无法卸载语言包。更改默认输入和显示语言并不能解决问题。

powershell language input-languages windows-10

5
推荐指数
0
解决办法
991
查看次数

在本地组策略中以编程方式创建机器启动脚本:脚本执行但在组策略编辑器中不可见

我设法以编程方式为 Windows 10 Pro 创建机器启动 Powershell 脚本并将其放置在本地组策略中(请参阅下面用于创建启动脚本的 powershell 脚本)。
重申一下:我使用的是本地组策略,而我的计算机不在域中。

启动脚本将其执行记录在事件日志中,当我在日志中看到适当的事件时,一切都很顺利。

问题

当我打开本地组策略编辑器 ( gpedit.msc) 并查看计算机启动脚本时,您可以从屏幕截图中看到,没有注册任何脚本:

组策略编辑器的屏幕截图

脚本本身已正确放置在组策略脚本 ( C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup)目录中


用于在本地组策略中创建机器启动脚本的 Powershell 脚本

$path = "$ENV:systemRoot\System32\GroupPolicy\Machine\Scripts\Startup"
if (-not (Test-Path $path)) {
    New-Item -path $path -itemType Directory
}
'Write-EventLog -LogName xxx -source Scripts -EntryType Information -EventId 2 -Message "Execute machine startup script: $psCommandPath"' | 
    Out-File -filePath "$path\AllUsersStartup.ps1" -encoding ascii

# Add script to Group Policy through the Registry
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Startup\0\0',
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0\0' |
  ForEach-Object { 
    if (-not (Test-Path $_)) …
Run Code Online (Sandbox Code Playgroud)

windows powershell group-policy windows-10 powershell-5.0

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

如何根据文件名将文件分类到文件夹中 - Windows CMD

如何使用 CMD / PowerShell 命令根据文件名将文件分类到文件夹中?

假设我有一个包含大量文件(超过 20,000 个文件)的文件夹,其中所有文件都具有相同的命名约定,例如:(注意模式)

t_1001_1801.png
t_1001_1802.png
t_1001_1803.png
...
t_1001_2112.png (last file starts with 't_1001_')
t_1002_1801.png
t_1002_1802.png
t_1002_1803.png
....
t_1002_2112.png
t_1003_1801.png
t_1003_1802.png
t_1003_1803.png
...
t_1214_2112.png (last file in folder)
Run Code Online (Sandbox Code Playgroud)

我运行这个 CMD 命令来创建一个文件夹列表:
for /l %i in (1001,1,1214) do md x%i
它创建一个文件夹列表,例如:

x1001
x1002
x1003
...
x1214
Run Code Online (Sandbox Code Playgroud)

现在我想根据文件名将文件排序(移动)到文件夹中,例如:

- move the files t_1001_1801.png to t_1001_2112.png to the folder x1001.
- move the files t_1002_1801.png to t_1002_2112.png to the folder x1002.
...
Run Code Online (Sandbox Code Playgroud)

我可以为此目的使用 shell 命令吗?

windows powershell command-line shell-script

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

指定用户和密码的 Powershell 远程桌面连接

在powershell中使用mstsc命令时如何指定用户?虽然我可以指定服务器,但我不能指定用户。

假设服务器名称 = server01,用户名 = Test,密码 = PW

示例 1 mstsc /v:server01 /user server01\test /password 密码

这只会显示“远程桌面连接使用”帮助菜单。

示例 2 mstsc /v:server01

这有效,为用户和密码调出正常的 RDP 连接提示。

示例 3 mstsc /v:server01 /user server01\test

即使尝试仅指定用户也失败,再次调出帮助菜单。

一些关于 powershell 的网站文章建议使用“Connect-RDP”或“Connect-Mstsc”而不是上面示例中的“mstsc”,但这只会带来错误代码。我对 powershell 的了解非常基础,所以我可能在某处犯了一个简单的错误。

remote-desktop powershell windows-10

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

在 PowerShell 中使用 UWP API 命名空间

我一直在寻找如何在 PowerShell 中使用命名空间来处理 Windows 10 锁定屏幕并遇到了这个答案:https : //superuser.com/a/1062551/700258,但是它没有说明如何导入或将该命名空间添加到 PowerShell 以供使用。我尝试为程序集查找引用的 DLL 文件,但它们不在我的计算机上。当我看到它们是 Windows 桌面扩展 API 的一部分时,我出去下载了 Windows 10 SDK,但 DLL 文件也不在其中。如何在 PowerShell 脚本中使用 Windows.System.UserProfile 命名空间中的此 LockScreen 类?

powershell windows-10 uwp

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

在 Windows 10 中以不同用户身份从 Powershell 运行时无法输入 cmd- 或 Powershell-window

当我执行以下代码时:

$creds = Get-Credential -UserName other -Message none
# answering the creds dialogue with correct password here
Start-Process C:\Windows\system32\cmd.exe -Credential $creds
Run Code Online (Sandbox Code Playgroud)

一个cmd窗口打开(看起来完全正常,我可以更改设置...)但我无法在窗口中输入任何内容。无论是普通用户还是管理员帐户,powershell 本身都以普通用户或管理员身份运行。除非 Powershell 作为系统运行(通过 Sysinternal 的psexec):然后我收到以下错误:

Start-Process : This command cannot be run due to the error: Access denied
At line:1 char:1
+ Start-Process C:\Windows\system32\cmd.exe -Credential $creds
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Run Code Online (Sandbox Code Playgroud)

我将它与cmd.exeandpowershell而不是整个 cmd-path结合起来,并添加了-NoNewWindow参数,但没有任何区别(尽管打开了一个新窗口-NoNewWindow)。当运行“正常”程序时,notepad一切都按预期工作 - 当我运行时,例如runas …

powershell windows-10

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

如何禁用右键单击以粘贴到 PowerShell 中?

如何禁用右键单击以在 PowerShell 中粘贴?

在其他程序中,我习惯于右键单击上下文菜单,并且根据剪贴板的内容,在 PowerShell 中这可能是致命的。

windows powershell paste right-click windows-10

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

在 Windows 10 上找不到 Wget 的输出

我运行 wget URL,它在 PowerShell 窗口中提供一个弹出进度条,然后以某种状态(-v 选项)结束,但没有结果文件。

我之前已经看到过多次关于此的讨论,有些说它应该在当前目录中,有些在用户主目录中,有些在 AppData 下的 VirtualStore - 但在这些位置中的任何一个都没有。

这是从 PowerShell 命令窗口运行的 Windows 10。

我的会话(使用假 URL):

PS P:\ftp> wget -v  http://mysystem/image.jpg
VERBOSE: GET http://mysystem/image.jpg with 0-byte payload
VERBOSE: received 70544-byte response of content type image/jpeg


StatusCode        : 200
StatusDescription : OK
Content           : {255, 216, 255, 224...}
RawContent        : HTTP/1.1 200 OK
                    Keep-Alive: timeout=5, max=100
                    Connection: Keep-Alive
                    Accept-Ranges: bytes
                    Content-Length: 70544
                    Content-Type: image/jpeg
                    Date: Sun, 03 Mar 2019 02:09:03 GMT
                    ETag: "11390-531efc...
Headers           : {[Keep-Alive, timeout=5, max=100], …
Run Code Online (Sandbox Code Playgroud)

windows powershell wget

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

如何在 MobaXterm 中获得提升的 powershell?

是否可以使用 MobaXterm 创建提升的 powershell 提示?也就是说,具有管理员权限的外壳?

下面是 MobaXterm 的“会话”窗口的图片,其中选择了“外壳”选项卡,1。可以选择 Bash、Cmd、Powershell 或 Ubuntu Bash。但是,它们以当前用户的权限打开。我想以管理员身份打开它们(最好是 Powershell)。

我目前使用 MobaXterm 来满足我的 ssh 需求,并使用 Cmder 来满足本地 shell。我想将其统一为一个工具。Cmder 可以选择以管理员身份启动一个新的 shell,但是我在 MobaXterm 中找不到这个选项。

运行 Chocolatey 是我使用提升的 shell 的主要目的,所以偶尔启动一些其他 shell并没有那么烦人。

mobaxterm 外壳窗口

powershell mobaxterm

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