PowerShell way to explore https:https://cdn.v2ex.com/navatar/8c67/44c9/776_normal.png?m=1559640109 https:https://cdn.v2ex.com/navatar/8c67/44c9/776_large.png?m=1559640109 2024-11-16T10:20:22Z Copyright © 2010-2018, V2EX 求助在 Windows 桌面运行某个程序的多个实例并在整个穿够屏幕布满的 powershell 脚本, GPT 生成的也无法平铺位置随机的。 tag:www.v2ex.com,2024-11-16:/t/1090083 2024-11-16T06:38:20Z 2024-11-16T10:20:22Z Apol1oBelvedere member/Apol1oBelvedere 求助在 Windows 桌面运行某个程序的多个实例并在整个穿够屏幕按 2 行 n 列布局布满的 powershell 脚本,我用 GPT 生成的 powershell 脚本也无法平铺,也是位置随机的。 操作系统:Windows 11 24H2 运行平台:PowerShell ,CMD 终端不具备设置窗口大小和位置的功能。 运行效果:

  1. 提示输入需要运行程序的数量。
  2. 直接在脚本里手工设置程序位置以便固定后长期使用。
  3. 脚本自动获取屏幕分辨率。
  4. 例如 6 个窗口打开后,脚本自动计算窗口大小和位置,把窗口放置好,窗口大小相等,2 行 n 列布局。
  5. 以记事本为例,能确实运行符合效果。
]]>
是我孤陋寡闻了吗? powershell 里面其实支持顺斜杠, tab 补全也能改成顺斜杠 tag:www.v2ex.com,2024-03-06:/t/1021188 2024-03-06T09:34:24Z 2024-03-06T10:55:18Z FYFX member/FYFX 最近从 linux 换会 windows,感觉 powershell 里面反斜杠有点不爽,后面查了一下 pwsh 是支持顺斜杠的,不过 tab 补全是反斜杠,然后在 github 上面也找到了将 tab 补全改成斜杠的设置

Set-PSReadLineKeyHandler -Chord Tab -ViMode Command -ScriptBlock { $cOntent= "" $index = 0 [Microsoft.PowerShell.PSConsoleReadLine]::ViTabCompleteNext() [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $content, [ref] $index) [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() [Microsoft.PowerShell.PSConsoleReadLine]::Insert($content.Replace('\','/')) [Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($index) } 

链接是这个: https://github.com/PowerShell/PSReadLine/issues/3205

cd 还有执行程序和.ps1 脚本都没啥问题,不过我也才用,可能会影响一些用到 cmd 工具的命令?

]]> 求助:如何阻止 Powershell 生成 tmp 文件 tag:www.v2ex.com,2024-02-08:/t/1014989 2024-02-08T01:41:54Z 2024-02-08T13:05:06Z KIMI360 member/KIMI360 最近在终端中使用 powershell 非常卡,加载慢,输入命令慢,返回也慢。研究了一下发现%TEMP%下存在大量 PS 开头的.tmp 文件,删除后 powershell 就恢复正常了。

想在 powershell 开始前使用命令删除这些 tmp 文件,结果执行命令时一边删除一边又生成了同样多的 tmp 文件

gci $env:TEMP\PS*.tmp -File | % { ri $_.FullName -Force } 

那么现在问题来了,如何阻止 powershell 生成这些文件呢

]]>
请教 win11 powershell 设置别名的问题 tag:www.v2ex.com,2024-01-15:/t/1008646 2024-01-15T01:10:41Z 2024-01-15T02:30:50Z bddxg member/bddxg 我自己找到了一些设置别名的教程文章 比如 https://segmentfault.com/a/1190000015928399 但是我目前遇到了一个难题, 可能是我的理解不够

我有个长命令 pnpm store prune, 我希望能用pmsp 来替代这个命令 我不知道该如何设置 我尝试过

Set-Alias -Name pmsp -Value "pnpm store prune" Set-Alias pmsp "pnpm store prune" Set-Alias pmsp pnpm store prune 

以上都不行,要么直接打开终端就报错, 要么执行 pmsp 的时候提示无法将“pnpm store prune”项识别为 cmdlet 、函数、脚本文件或可运行程序的名称

求大佬指教一下

]]>
如何确定 powershell 在终端输出的信息是 stdout 还是 stderr? tag:www.v2ex.com,2023-12-12:/t/999636 2023-12-12T03:36:02Z 2023-12-12T11:36:53Z xinghen57 member/xinghen57 最近 powershell 中用 ffmpeg ,发现它终端的输出竟然走的 stderr 。

请问 v 友,有方法确认终端输出是 stdout 还是 stderr 吗?或确定终端输出的 stream 号?

]]>
ps1 文件如何双击以管理员身份运行 tag:www.v2ex.com,2023-11-30:/t/996454 2023-11-30T02:44:06Z 2023-11-28T14:49:15Z n2l member/n2l powershell 怎么设置代理? tag:www.v2ex.com,2023-11-12:/t/991270 2023-11-12T14:25:14Z 2023-11-11T02:45:35Z n2l member/n2l ps 无法显示 bash 命令的完整参数,是 bug 吗? tag:www.v2ex.com,2023-11-12:/t/991168 2023-11-12T07:08:45Z 2023-11-08T07:08:45Z laminux29 member/laminux29
bash < test-fifo

用 ps -ef | grep bash 就无法找到 bash < test-fifo 这条完整命令。

请问这是 bug 吗?还是我的姿势不对? ]]>
powershell setx 变量后无法自身得到变量值 tag:www.v2ex.com,2023-10-03:/t/978793 2023-10-03T15:53:31Z 2023-10-03T19:01:44Z zzzkkk member/zzzkkk
echo %classpath% 无法得到值

在 cmd.exe 里面能得到刚设置的值 ]]>
请教, powershell 脚本中使用中文,脚本文本存储的是 utf-8,运行后中文就是乱码。 tag:www.v2ex.com,2023-09-15:/t/974143 2023-09-15T07:51:17Z 2023-09-15T15:18:59Z purezhang member/purezhang 请教,powershell 脚本中使用中文,脚本文本存储的是 utf-8 ,运行后中文就是乱码。 搞不定啊。。。。。

]]>
oh-my-posh 导致 powershell 启动缓慢 tag:www.v2ex.com,2023-07-15:/t/956975 2023-07-15T05:12:55Z 2023-07-16T15:23:47Z mmddisa member/mmddisa 安装 oh-my-posh 后,powershell 启动异常缓慢,且似乎受网络影响,网络正常时启动需 1900ms 左右: 若关闭网络,则需要 11 秒还多:

试过将 oh-my-posh 加入 windows defender 等方法,似乎没有用

附上网络正常/断开时的 Debug 信息:

网络正常时:

Cache path: C:\Users\login\AppData\Local\oh-my-posh Config path: C:\Users\login\AppData\Local\Programs\oh-my-posh\themes\cert.omp.json Logs: [DEBUG] 13:06:43.411 shell.go:Getenv:397 → NO DATA [TRACE] 13:06:43.411 shell.go:Getenv(TERM_PROGRAM) - 0s [DEBUG] 13:06:43.411 shell.go:Getenv:397 → C:\Users\login\AppData\Local [TRACE] 13:06:43.411 shell.go:Getenv(LOCALAPPDATA) - 0s [TRACE] 13:06:43.411 shell_windows.go:CachePath() - 0s [DEBUG] 13:06:43.412 shell.go:Getenv:397 → C:\Users\login\AppData\Local\Programs\oh-my-posh\themes\cert.omp.json [TRACE] 13:06:43.412 shell.go:Getenv(POSH_THEME) - 0s [DEBUG] 13:06:43.440 shell.go:Shell:644 → process name: pwsh.exe [TRACE] 13:06:43.440 shell.go:Shell() - 28.6409ms [TRACE] 13:06:43.440 shell.go:resolveConfigPath() - 28.6409ms [TRACE] 13:06:43.440 shell.go:Init() - 29.7168ms [TRACE] 13:06:43.440 shell.go:Flags() - 0s [TRACE] 13:06:43.441 config.go:loadConfig() - 523.2µs [TRACE] 13:06:43.441 shell.go:Flags() - 0s [DEBUG] 13:06:43.441 shell.go:Getenv:397 → NO DATA [TRACE] 13:06:43.441 shell.go:Getenv(OMP_CACHE_DISABLED) - 0s [TRACE] 13:06:43.441 shell_windows.go:WindowsRegistryKeyValue(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor) - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [DEBUG] 13:06:43.441 shell_windows.go:WindowsRegistryKeyValue:206 → ColorizationColor(DWORD): 0xC40078D4 [TRACE] 13:06:43.441 shell.go:Shell() - 0s [DEBUG] 13:06:43.441 shell.go:Getenv:397 → 7.3.6 [TRACE] 13:06:43.441 shell.go:Getenv(POSH_SHELL_VERSION) - 0s [DEBUG] 13:06:43.441 debug.go:PrintDebug:23 → Segment: Title [TRACE] 13:06:43.441 shell.go:Flags() - 0s [DEBUG] 13:06:43.441 block.go:Debug:280 → Segment: session [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [DEBUG] 13:06:43.441 shell.go:Pwd:427 → C:\Users\login [TRACE] 13:06:43.441 shell.go:Pwd() - 0s [DEBUG] 13:06:43.441 shell_windows.go:56 → C:\Users\login [TRACE] 13:06:43.441 shell.go:GOOS() - 0s [DEBUG] 13:06:43.441 shell.go:Getenv:397 → NO DATA [TRACE] 13:06:43.441 shell.go:Getenv(SSH_CONNECTION) - 0s [DEBUG] 13:06:43.441 shell.go:Getenv:397 → NO DATA [TRACE] 13:06:43.441 shell.go:Getenv(SSH_CLIENT) - 0s [TRACE] 13:06:43.441 shell_windows.go:Root() - 0s [TRACE] 13:06:43.441 shell.go:Shell() - 0s [TRACE] 13:06:43.441 shell.go:ErrorCode() - 0s [TRACE] 13:06:43.441 shell_windows.go:IsWsl() - 0s [TRACE] 13:06:43.442 shell.go:Pwd() - 0s [DEBUG] 13:06:43.442 shell_windows.go:56 → C:\Users\login [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [DEBUG] 13:06:43.442 shell.go:User:548 → login [TRACE] 13:06:43.442 shell.go:User() - 0s [DEBUG] 13:06:43.442 shell.go:Host:560 → Avalon [TRACE] 13:06:43.442 shell.go:Host() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [DEBUG] 13:06:43.442 shell.go:Getenv:397 → NO DATA [TRACE] 13:06:43.442 shell.go:Getenv(SHLVL) - 0s [TRACE] 13:06:43.442 shell.go:TemplateCache() - 1.0664ms [TRACE] 13:06:43.442 shell.go:TemplateCache() - 0s [TRACE] 13:06:43.442 shell.go:Shell() - 0s [DEBUG] 13:06:43.442 block.go:Debug:280 → Segment: path [TRACE] 13:06:43.442 shell.go:Pwd() - 0s [DEBUG] 13:06:43.442 shell_windows.go:56 → C:\Users\login [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:Pwd() - 0s [TRACE] 13:06:43.442 shell.go:Shell() - 0s [TRACE] 13:06:43.442 shell.go:Flags() - 0s [DEBUG] 13:06:43.442 properties.go:GetBool:22 → mapped_locations_enabled: true [DEBUG] 13:06:43.442 properties.go:GetString:28 →  [DEBUG] 13:06:43.442 properties.go:GetString:28 →  [DEBUG] 13:06:43.442 shell_windows.go:56 → C:\Users\login [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [DEBUG] 13:06:43.442 properties.go:GetString:28 → ~ [DEBUG] 13:06:43.442 properties.go:GetKeyValueMap:46 → mapped_locations: map[] [TRACE] 13:06:43.442 shell.go:PathSeparator() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:PathSeparator() - 0s [TRACE] 13:06:43.442 shell.go:PathSeparator() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:PathSeparator() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:PathSeparator() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:GOOS() - 0s [TRACE] 13:06:43.442 shell.go:PathSeparator() - 0s [TRACE] 13:06:43.442 shell.go:Pwd() - 0s [TRACE] 13:06:43.442 shell_windows.go:IsWsl() - 0s [TRACE] 13:06:43.442 shell.go:StackCount() - 0s [DEBUG] 13:06:43.443 win32_windows.go:isWriteable:299 → not current user or in group [DEBUG] 13:06:43.443 win32_windows.go:isWriteable:303 → current user is member of S-1-5-32-544 [DEBUG] 13:06:43.443 win32_windows.go:isWriteable:311 ↓ WRITE_DAC WRITE_OWNER SYNCHRONIZE DELETE READ_CONTROL [DEBUG] 13:06:43.443 win32_windows.go:isWriteable:313 → user has write access [TRACE] 13:06:43.443 shell_windows.go:DirIsWritable() - 524µs [TRACE] 13:06:43.443 shell.go:TemplateCache() - 0s [TRACE] 13:06:43.443 shell.go:TemplateCache() - 0s [TRACE] 13:06:43.443 shell.go:Shell() - 0s [DEBUG] 13:06:43.443 block.go:Debug:280 → Segment: git [TRACE] 13:06:43.443 shell.go:Pwd() - 0s [DEBUG] 13:06:43.443 shell_windows.go:56 → C:\Users\login [TRACE] 13:06:43.443 shell.go:GOOS() - 0s [TRACE] 13:06:43.443 shell.go:GOOS() - 0s [ERROR] 13:06:43.447 shell.go:CommandPath:602 → exec: "git.exe": executable file not found in %PATH% [TRACE] 13:06:43.447 shell.go:CommandPath(git.exe) - 4.2052ms [TRACE] 13:06:43.447 shell.go:HasCommand(git.exe) - 4.2052ms [DEBUG] 13:06:43.447 block.go:Debug:280 → Segment: time [TRACE] 13:06:43.447 shell.go:Pwd() - 0s [DEBUG] 13:06:43.447 shell_windows.go:56 → C:\Users\login [TRACE] 13:06:43.447 shell.go:GOOS() - 0s [DEBUG] 13:06:43.447 properties.go:GetString:28 → 15:04 [TRACE] 13:06:43.447 shell.go:TemplateCache() - 0s [TRACE] 13:06:43.448 shell.go:TemplateCache() - 0s [TRACE] 13:06:43.448 shell.go:Shell() - 0s [DEBUG] 13:06:43.448 shell.go:Getenv:397 → C:\Users\login\AppData\Local [TRACE] 13:06:43.448 shell.go:Getenv(LOCALAPPDATA) - 0s [TRACE] 13:06:43.448 shell_windows.go:CachePath() - 0s [TRACE] 13:06:43.448 shell.go:Flags() - 0s 

网络断开时:

Cache path: C:\Users\login\AppData\Local\oh-my-posh Config path: C:\Users\login\AppData\Local\Programs\oh-my-posh\themes\cert.omp.json Logs: [DEBUG] 13:08:36.385 shell.go:Getenv:397 → NO DATA [TRACE] 13:08:36.385 shell.go:Getenv(TERM_PROGRAM) - 0s [DEBUG] 13:08:36.385 shell.go:Getenv:397 → C:\Users\login\AppData\Local [TRACE] 13:08:36.385 shell.go:Getenv(LOCALAPPDATA) - 0s [TRACE] 13:08:36.385 shell_windows.go:CachePath() - 0s [DEBUG] 13:08:36.385 shell.go:Getenv:397 → C:\Users\login\AppData\Local\Programs\oh-my-posh\themes\cert.omp.json [TRACE] 13:08:36.385 shell.go:Getenv(POSH_THEME) - 0s [DEBUG] 13:08:36.412 shell.go:Shell:644 → process name: pwsh.exe [TRACE] 13:08:36.412 shell.go:Shell() - 26.4397ms [TRACE] 13:08:36.412 shell.go:resolveConfigPath() - 26.4397ms [TRACE] 13:08:36.412 shell.go:Init() - 26.9528ms [TRACE] 13:08:36.412 shell.go:Flags() - 0s [TRACE] 13:08:36.412 config.go:loadConfig() - 528.2µs [TRACE] 13:08:36.412 shell.go:Flags() - 0s [DEBUG] 13:08:36.412 shell.go:Getenv:397 → NO DATA [TRACE] 13:08:36.412 shell.go:Getenv(OMP_CACHE_DISABLED) - 0s [TRACE] 13:08:36.412 shell_windows.go:WindowsRegistryKeyValue(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor) - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [DEBUG] 13:08:36.412 shell_windows.go:WindowsRegistryKeyValue:206 → ColorizationColor(DWORD): 0xC40078D4 [TRACE] 13:08:36.412 shell.go:Shell() - 0s [DEBUG] 13:08:36.412 shell.go:Getenv:397 → 7.3.6 [TRACE] 13:08:36.412 shell.go:Getenv(POSH_SHELL_VERSION) - 0s [DEBUG] 13:08:36.412 debug.go:PrintDebug:23 → Segment: Title [TRACE] 13:08:36.412 shell.go:Flags() - 0s [DEBUG] 13:08:36.412 block.go:Debug:280 → Segment: session [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [DEBUG] 13:08:36.412 shell.go:Pwd:427 → C:\Users\login [TRACE] 13:08:36.412 shell.go:Pwd() - 0s [DEBUG] 13:08:36.412 shell_windows.go:56 → C:\Users\login [TRACE] 13:08:36.412 shell.go:GOOS() - 0s [DEBUG] 13:08:36.412 shell.go:Getenv:397 → NO DATA [TRACE] 13:08:36.412 shell.go:Getenv(SSH_CONNECTION) - 0s [DEBUG] 13:08:36.412 shell.go:Getenv:397 → NO DATA [TRACE] 13:08:36.412 shell.go:Getenv(SSH_CLIENT) - 0s [TRACE] 13:08:36.413 shell_windows.go:Root() - 526.5µs [TRACE] 13:08:36.413 shell.go:Shell() - 0s [TRACE] 13:08:36.413 shell.go:ErrorCode() - 0s [TRACE] 13:08:36.413 shell_windows.go:IsWsl() - 0s [TRACE] 13:08:36.413 shell.go:Pwd() - 0s [DEBUG] 13:08:36.413 shell_windows.go:56 → C:\Users\login [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [DEBUG] 13:08:36.413 shell.go:User:548 → login [TRACE] 13:08:36.413 shell.go:User() - 0s [DEBUG] 13:08:36.413 shell.go:Host:560 → Avalon [TRACE] 13:08:36.413 shell.go:Host() - 0s [TRACE] 13:08:36.413 shell.go:GOOS() - 0s [DEBUG] 13:08:36.413 shell.go:Getenv:397 → NO DATA [TRACE] 13:08:36.413 shell.go:Getenv(SHLVL) - 0s [TRACE] 13:08:36.413 shell.go:TemplateCache() - 1.1125ms [TRACE] 13:08:36.413 shell.go:TemplateCache() - 0s [TRACE] 13:08:36.413 shell.go:Shell() - 0s [DEBUG] 13:08:36.414 block.go:Debug:280 → Segment: path [TRACE] 13:08:36.414 shell.go:Pwd() - 0s [DEBUG] 13:08:36.414 shell_windows.go:56 → C:\Users\login [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:Pwd() - 0s [TRACE] 13:08:36.414 shell.go:Shell() - 0s [TRACE] 13:08:36.414 shell.go:Flags() - 0s [DEBUG] 13:08:36.414 properties.go:GetBool:22 → mapped_locations_enabled: true [DEBUG] 13:08:36.414 properties.go:GetString:28 →  [DEBUG] 13:08:36.414 properties.go:GetString:28 →  [DEBUG] 13:08:36.414 shell_windows.go:56 → C:\Users\login [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [DEBUG] 13:08:36.414 properties.go:GetString:28 → ~ [DEBUG] 13:08:36.414 properties.go:GetKeyValueMap:46 → mapped_locations: map[] [TRACE] 13:08:36.414 shell.go:PathSeparator() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:PathSeparator() - 0s [TRACE] 13:08:36.414 shell.go:PathSeparator() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:PathSeparator() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:PathSeparator() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:GOOS() - 0s [TRACE] 13:08:36.414 shell.go:PathSeparator() - 0s [TRACE] 13:08:36.414 shell.go:Pwd() - 0s [TRACE] 13:08:36.414 shell_windows.go:IsWsl() - 0s [TRACE] 13:08:36.414 shell.go:StackCount() - 0s [DEBUG] 13:08:36.415 win32_windows.go:isWriteable:299 → not current user or in group [DEBUG] 13:08:36.415 win32_windows.go:isWriteable:303 → current user is member of S-1-5-32-544 [DEBUG] 13:08:36.415 win32_windows.go:isWriteable:311 ↓ WRITE_DAC WRITE_OWNER SYNCHRONIZE DELETE READ_CONTROL [DEBUG] 13:08:36.415 win32_windows.go:isWriteable:313 → user has write access [TRACE] 13:08:36.415 shell_windows.go:DirIsWritable() - 518.6µs [TRACE] 13:08:36.415 shell.go:TemplateCache() - 0s [TRACE] 13:08:36.415 shell.go:TemplateCache() - 0s [TRACE] 13:08:36.415 shell.go:Shell() - 0s [DEBUG] 13:08:36.415 block.go:Debug:280 → Segment: git [TRACE] 13:08:36.415 shell.go:Pwd() - 0s [DEBUG] 13:08:36.415 shell_windows.go:56 → C:\Users\login [TRACE] 13:08:36.415 shell.go:GOOS() - 0s [TRACE] 13:08:36.415 shell.go:GOOS() - 0s [ERROR] 13:08:36.419 shell.go:CommandPath:602 → exec: "git.exe": executable file not found in %PATH% [TRACE] 13:08:36.419 shell.go:CommandPath(git.exe) - 4.1797ms [TRACE] 13:08:36.419 shell.go:HasCommand(git.exe) - 4.1797ms [DEBUG] 13:08:36.419 block.go:Debug:280 → Segment: time [TRACE] 13:08:36.419 shell.go:Pwd() - 0s [DEBUG] 13:08:36.419 shell_windows.go:56 → C:\Users\login [TRACE] 13:08:36.419 shell.go:GOOS() - 0s [DEBUG] 13:08:36.419 properties.go:GetString:28 → 15:04 [TRACE] 13:08:36.419 shell.go:TemplateCache() - 0s [TRACE] 13:08:36.419 shell.go:TemplateCache() - 0s [TRACE] 13:08:36.419 shell.go:Shell() - 0s [DEBUG] 13:08:36.419 shell.go:Getenv:397 → C:\Users\login\AppData\Local [TRACE] 13:08:36.419 shell.go:Getenv(LOCALAPPDATA) - 0s [TRACE] 13:08:36.419 shell_windows.go:CachePath() - 0s [TRACE] 13:08:36.419 shell.go:Flags() - 0s 
]]>
powershell 管道问题 tag:www.v2ex.com,2023-04-06:/t/930394 2023-04-06T14:14:00Z 2023-04-06T14:31:03Z xinghen57 member/xinghen57 看 Powershell Rename-Item 文档时,有批量命名文件的 example ,代码如下:

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace '.txt','.log' } 

无法理解 Get-ChildItem 获取的文件后,通过管道,具体是使用哪种方式传递给 Rename-Item ,以及传递了什么内容。

上面代码我的理解,Get-ChildItem 命令的结果通过管道传递给了 Rename-Item 的 Path 参数。但 Path 只接受 string 。如果管道是 ByValue 方式,传递的应该是 Object ,所以不是 ByValue 。如果是 ByPropertyName ,Get-ChildItem 获取的 FileInfo 对象并没有 Path 属性,理论上也无法传递。

]]>
如何在打开 powershell 脚本的时候, cd 到脚本所在目录 tag:www.v2ex.com,2023-02-18:/t/917240 2023-02-18T14:09:48Z 2023-02-21T08:42:19Z 1054850490 member/1054850490 脚本位于:C:\Users\yerin\Desktop\888.ps1
我想要打开这个脚本的时候,运行目录可以自动 CD 到:C:\Users\yerin\Desktop

注:我明白 pow 脚本,默认是以脚本所在目录运行的,但是我用键盘的宏定义打开 pow 脚本的时候,并不会按照之前的状态进行,打开的时候却是宏软件的目录,

我搜索到有一个命令有作用
```
cd (Split-Path -Parent $MyInvocation.MyCommand.Definition)
```
这样确实会跳转到脚本所在目录,但是遇到有空格的所在目录就会报错,如何才能加上双引号括住


以下有一个 CMD 我经常用的命令,而且碰到空格键也可以 CD 进去
```
cd %~dp0
%~d0
```
这样的话 CMD 就会自己 CD 到 bat 的所在目录,我不知道 powershell 有没有类似的操作 ]]>
如何让 powershell 输出的 txt 日志为 unix lf 格式 tag:www.v2ex.com,2023-02-17:/t/917100 2023-02-17T21:24:17Z 2023-02-18T03:11:04Z 1054850490 member/1054850490

```
*>&1 | ForEach-Object {if($_ -notin (Get-Content 888.txt)){Add-Content 888.txt $_ -Encoding utf8; $_}}

```
]]>
这个 powershell "比对”命令能优化吗? tag:www.v2ex.com,2023-02-17:/t/916822 2023-02-17T00:28:11Z 2023-02-17T02:01:41Z 1054850490 member/1054850490 ```
*>&1 | ForEach-Object {if($_ -notin (Get-Content 888.txt)){Add-Content 888.txt $_ -Encoding utf8; $_}}

```

规则是“整行”内容匹配,而不是“包含”内容匹配

解释一下,上面是将 888.txt 里的内容跟 powershell 控制台的输出进行比对,也就是说,控制台输出了“hello world”的话,就会比对 888.txt 有没有相同的内容,如果 888.txt 里也有一整行写着“hello world”则不追加写入 txt ]]>
powershell 运行 ps 文件的时候,如何支持带空格的路径 tag:www.v2ex.com,2023-02-13:/t/915817 2023-02-13T13:07:45Z 2023-02-14T04:46:21Z 1054850490 member/1054850490
C:\Users\yerin\Desktop\新建文件夹 (2)\无标题 8.ps1

我们可以看到上面的路径中有空格,由于 ps 文件默认是以当前运行的目录作为运行路径,而上面路径也没有双引号圈起来,也没法圈路径,该如何解决当前路径带有空格的问题?虽然控制台可以双引号路径,但是 ps 文件没法事先双引号路径


还有另一个问题,就是我右键 ps 文件的时候,有个选项是“使用 powershell 运行”,这时候当前路径带空格也没事
但是如果我绑定了默认应用,也就是所有 ps1 文件都以“C:\Windows\System32\WindowsPowerShell\v1.0”改路径下的 powershell 运行,然后此时我双击运行的时候,就会出现我上述第一个问题,该路径找不到 ]]>
cmd 输出日志的时候,如何不写入重复日志 tag:www.v2ex.com,2023-02-10:/t/914935 2023-02-10T07:48:55Z 2023-02-10T08:48:43Z 1054850490 member/1054850490
注意!是整行内容相匹配就不追加写入,而不是出现“hello world”就整行不不写入 ]]>
请教-关于 PowerShell 的使用场景问题——竞赛,编程挑战,运维需求在哪里找 tag:www.v2ex.com,2023-01-11:/t/908061 2023-01-11T01:06:41Z 2023-01-11T06:12:40Z SuzhaharCan member/SuzhaharCan 贴主,23 年本科毕业生,现在杭州传统互联网的公司实习,C#/WinForm 开发,先学,之后精进 ,考虑转其他的路线;(介绍只是 想表明 ,自己 刚进入行业没多久 ) 但是,自己自学 PowerShell ,管道、文件、WMI 等部分都学习涉猎; 理论部分都学完 2 遍,都能理解,但是没有以模块化脚本编写过

我个人是在 Windows 端使用,23 年 9 月会 使用 Linux 和黑苹果,所以 ,不受系统的限制 个人目前 是 借助 CodeWars 这个刷题网站来练习 PowerShell 脚本编写;感觉 和用 C#编写方法函数差不多

现在学习有些吃力,想通过 脚本竞赛、编程挑战网站、外包运维需求等 方式,上手实践练习一番 ; 所以,我想请教一下 通过业务场景或者 需求 来驱动 练习 PowerShell 的方式有哪些? 个人知道 Windows 运维 多少需要学一下 PowerShell 的; 如有** 路过的运维师,可否指点一下 PowerShell 的学习,可以的话,真心感谢** pS:PowerShell 传教士的群,我加入,确实吸收不错的内容;

]]>
Windows 运行 ffmpeg 批量脚本的时候,如何在不中断的情况下限制 CPU 使用率 tag:www.v2ex.com,2022-10-13:/t/886777 2022-10-13T15:44:56Z 2022-10-15T05:40:06Z 1054850490 member/1054850490 cmd 控制台显示输出日志过滤 tag:www.v2ex.com,2022-10-03:/t/884551 2022-10-03T16:17:17Z 2022-10-03T21:24:35Z 1054850490 member/1054850490




所用代码">> log.txt 2>&1"

例:
[youtube] OT5CfLnS3i4: Downloading webpage
[youtube] OT5CfLnS3i4: Downloading android player API JSON
[info] OT5CfLnS3i4: Downloading 1 format(s): 313+251
[download] Destination: [8K] 220930 (VIVIZ)(EUNHA)-BOP BOP!FANCAM by DahinMaru [OT5CfLnS3i4].f313.webm

[download] 0.0% of 347.69MiB at 20.51KiB/s ETA 04:49:21
[download] 0.0% of 347.69MiB at 60.87KiB/s ETA 01:37:28
[download] 0.0% of 347.69MiB at 142.04KiB/s ETA 41:46
[download] 0.0% of 347.69MiB at 304.37KiB/s ETA 19:29
[download] 0.0% of 347.69MiB at 153.67KiB/s ETA 38:36
[download] 0.0% of 347.69MiB at 200.95KiB/s ETA 29:31
[download] 0.0% of 347.69MiB at 262.78KiB/s ETA 22:34
[download] 0.1% of 347.69MiB at 420.53KiB/s ETA 14:06
[download] 0.1% of 347.69MiB at 657.11KiB/s ETA 09:01
[download] 0.3% of 347.69MiB at 971.20KiB/s ETA 06:05
[download] 0.6% of 347.69MiB at 1.60MiB/s ETA 03:36
[download] 1.2% of 347.69MiB at 2.82MiB/s ETA 02:01
[download] 2.3% of 347.69MiB at 4.85MiB/s ETA 01:10
[download] 2.8% of 347.69MiB at 5.51MiB/s ETA 01:01
[download] 2.8% of 347.69MiB at 6.04KiB/s ETA 15:54:40
[download] 2.8% of 347.69MiB at 18.07KiB/s ETA 05:19:14
[download] 2.8% of 347.69MiB at 42.17KiB/s ETA 02:16:49
[download] 2.8% of 347.69MiB at 90.36KiB/s ETA 01:03:50
[download] 2.8% of 347.69MiB at 142.10KiB/s ETA 40:35 ]]>
powershell7, 执行速度和自动补全速度都慢的令我抓狂 tag:www.v2ex.com,2022-09-13:/t/879763 2022-09-13T09:00:09Z 2022-09-14T03:10:43Z chackchackGO member/chackchackGO powershell7 第一条指令的延迟大概 3s+, 后续使用 ls 指令也有 2s 左右延迟, 自动补全速度也很慢.

我没有 google 到类似的问题, 请问有类似情况的朋友吗?
我的环境是原版 windows10, 保持着更新. version 21h2(build 19044.1889)

]]>
请教一下.ps1 运行时如何让 powerShell 同时显示所运行命令的内容 tag:www.v2ex.com,2022-08-25:/t/875276 2022-08-25T03:24:54Z 2022-08-30T10:49:29Z Moris member/Moris 我写了个 test.ps1 ,内容是

echo TEST 

运行结果只有一个 TEST

请问如何让 echo TEST 同时显示出来?

]]>
有什么不错的 powershell 书籍吗? tag:www.v2ex.com,2022-07-14:/t/866249 2022-07-14T14:13:44Z 2022-07-21T23:32:51Z 7zlid member/7zlid PowerShell 是否可以实现类似 expect 的功能? tag:www.v2ex.com,2022-05-26:/t/855365 2022-05-26T02:06:14Z 2022-06-02T01:52:54Z Kaiv2 member/Kaiv2 如题,最近切换到了 Windows 了,登录服务器(有跳板机)太麻烦 ,想配置自动化脚本(发布,查询日志)。PowerShell 中是否有类型 expect 的软件

]]>
PowerShell 启动慢 tag:www.v2ex.com,2022-04-06:/t/845128 2022-04-06T01:15:36Z 2022-10-11T13:07:35Z CUPAIR member/CUPAIR pwsh:powershell7.15; powershell: powershellv1.0,不知道啥版本,就 win11 自带的 :

这个延迟太高了,不知道有什么优化方法没,stackoverflow上提到.net 框架升级,感觉不怎么靠谱,因为powershell -noprofile这个指令基本没啥延迟,所以感觉应该是配置文件优化的问题,有 v 友懂如何优化吗

]]>
现在 PowerShell 是不是没有什么用? tag:www.v2ex.com,2022-03-05:/t/838173 2022-03-05T05:53:33Z 2022-03-06T20:01:34Z fengsien1999 member/fengsien1999 是不是掌握 Linux 的 Shell 就可以了?

]]>
PowerShell 竟然强悍如斯! tag:www.v2ex.com,2022-01-15:/t/828462 2022-01-15T10:35:09Z 2022-01-15T17:28:11Z Tumblr member/Tumblr 有大佬用 PowerShell 写了个 Windows 的远程桌面工具,据作者说,并没有依赖于任何现有的远程桌面应用或协议,这个项目演示了为什么 PowerShell 敢用 Power 这个词!

Github: https://github.com/DarkCoderSc/PowerRemoteDesktop

]]>
请问如何使用 powershell 禁用/启用设备? tag:www.v2ex.com,2021-07-18:/t/790254 2021-07-18T13:49:41Z 2021-07-18T13:52:09Z youcall911 member/youcall911 触摸板有时会失灵,我想用脚本的方式重启设备,可以实现吗?

希望能有比较详细的教学,谢谢。

]]>
逐浪 CMSv8.2 发布-集成 Node 与 Vue 脚手架和 PowerShell 支持的新一代网站管理系统 tag:www.v2ex.com,2020-10-23:/t/717685 2020-10-23T01:14:05Z 2020-10-23T02:01:25Z zoomla member/zoomla

楼倚霜树外,镜天无一毫。 南山与秋色,气势两相高。 -(唐)杜牧

北京时间 2020 年 10 月 20 日:领先的 CMS 与 web 内核服务商、中国唯一具备 CMS 与字库图库全 web 呈现自主知识产权、alexa 排名第一的中文 CMS 厂商--上海 Zoomla!逐浪软件团队宣布,发布最新一代 CMS 产品:Zoomla!逐浪 CMS v8.2.0 。

这是继逐浪 CMS V8.1.x 之后的全新一代产品,我们为此启用了全新的版本号, 即:v8.2.x 系列。

在这里插入图片描述

一键集成 Github 与 Npm 发布功能,与 node 开发平台无缝集合,从而支持更加强大的智能开发。

在这里插入图片描述

集成 PowerShell 管理功能,这是与 python 同级别的智能语言体系,驱动未来,驱动智能 AI 新时代。

在这里插入图片描述

是的,现在你不需要为配置复杂的 IIS,任何 64 位系统(商业版支持其它位数),只要点击根目录的 ZoomLaCMS.exe 就能快速启动,同时集成自动集成 CI/CD,强大卓越,效率极速

Areas/User/Views/Content/MyMDPic.cshtml Areas/User/Views/Content/AddMDPic.cshtml 

前台访问路径:/User/Content/MyMDPic?NodeID=绑定图库模型节点 ID

在这里插入图片描述

集成 OCR 识别与文字出版,是国内唯一具备字体设计中台内核的强大 CMS

我们同时将这一功能发布在 http://v.ziti163.com 平台,使每个开发者都能体验到国内首个开放字体生产技术的软件团队-逐浪软件团人的智慧结晶。

]]>
Powershell 的管道兼容性 tag:www.v2ex.com,2020-07-29:/t/694017 2020-07-29T05:44:31Z 2020-10-10T08:17:21Z ColinZeb member/ColinZeb 在 windows 上试用 gzip 遇到个管道的坑。

windows 上是没有 gzip 命令的。

首先安装 scoop install gzip

压缩命令一般这么写 cat script.ps1|gzip >script.gz

这个写法在 bash zsh 和 cmd 都能正常工作,但是 pwsh 不行,甚至 powershell 5 也不行。

我知道 ps 管道可以传 PS-Object,但不会不会兼容文件流吧,目前还没找到说这个问题的,先在这分享一下继续寻找 解决方案。

]]>
powershell 的独门秘技之气运“丹田” tag:www.v2ex.com,2020-06-05:/t/678918 2020-06-05T04:26:20Z 2020-06-03T04:24:20Z ps1aniuge member/ps1aniuge
若没有 [管道两端传对象] ,这条命令就无法运行。
dir |where-object { $_.length -gt 1000} #返回大于 1000 字节的文件。

[管道两端传对象] 相当于 ps 之人的 [丹田] ,练 ps 武功的根基。只需要打坏练武之人的 [丹田] ,就可以废他 9 成武功。


我把 [ win,linux 脚本用户] ,比喻成“女人”,
我把 [管道传递对象] ,比喻成“美颜相机”。

在 win7 中有 ps 管道传递对象功能。这个“美颜相机”,可以被看做早期的,功能简陋的,高端用户手中的玩具。
随着时间推移,随着 2020 年 1 月 14 日 win7 的 eol ;随着 win10 的上位普及;随着高级手机的普及;
powershell 在 win 中无敌了。代表“美颜相机”的管道传递对象功能普及了。

现在每个“win 女人”手里都拿着“美颜相机”版手机。当然,美颜相机也可以关掉不用。只用管道传递字符串。

这样的“win 女人”,占所有女人的 89%(世界上 win 用户大概有 89%这个样子)

现在每个“linux 女人”,手里的默认手机( bash,zsh )都不能美颜。但这些 linux 女人,可以一键安装开源免费的 powershell (美颜相机)详见 https://gitee.com/chuanjiao10/kasini3000_agent_linux

现在知乎上有人说“powershell 发明的管道传对象,没前途不可行”。被我类比为“美颜相机是幺蛾子,没前途,女人不应该用”。

实际上,我很讨厌女人用美颜相机,她们简直是“容貌诈骗犯”,欺骗了我的眼睛和感情。我对老婆这样一说,结果被她一脚踢下了床。

可见“女人们”并不这么想。比如:
vmware 有两种管理命令行,一种是基于 linux 的,一种是基于 powershell 的 powercli 。很显然 powercli 比基于 linux 的简单强大。
这里面少不了管道传对象,这个“美颜相机”的功能。

你说:“ [管道两端传对象] 不行”。
我说:“为啥以 shell 的标准看 powershell ?”
管道传对象到底行不行?我说行,你说不行,到底看好不?走着瞧呗。

手机厂家,带着美颜相机,已经征服世界上绝大多数女人。乔碧萝都能给你搞成可爱大眼萌;祛斑减皱纹,老太太用了都说好

powershell 带着管道传对象,征服大多数 linux 用户,还远吗? ]]>
powershell 的 tab 参数补全的,两个不同方式详解。 tag:www.v2ex.com,2020-04-21:/t/664697 2020-04-21T08:34:08Z 2020-04-19T08:32:08Z ps1aniuge member/ps1aniuge
默认值:win 用 win 的 tab 补全。这种是:先按“-”,然后按“tab”,补全出第一个参数名,或所选字母打头的参数名。再按 tab,补全出第二个参数名。
默认值:linux 用类似 bash 的 tab 补全。这种是:先按“-”,然后按两次“tab”,列出所有参数名,或所选字母打头的参数名。

linux 版 ps,若想改变成兼容 win 也容易:
1 建立$profle 。
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
2 写入 psreadline 选项。
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile ' #兼容 win ]]>
在 PowerShell 中好好说话 tag:www.v2ex.com,2020-04-16:/t/663224 2020-04-16T14:17:00Z 2020-04-16T15:35:34Z Tumblr member/Tumblr 首先感谢 @wsph123 提供的服务,征得作者同意后发出。
在 Mac 上也会经常用wtf查一些缩写,现在有了中文的,不胜欣喜。对于常用用命令行的同学来说,去 web 里查找略显烦琐,因此写了个 PowerShell 函数,方便使用。

Talk is cheap!
https://paste.ubuntu.com/p/3dRsf4krbb/ (Expired in a week)

语法错误不要说出来,比如aan。。。给个面子哦🙈

]]>
在 PowerShell 中使用 fish-style 自动补全提示 tag:www.v2ex.com,2020-03-19:/t/654386 2020-03-19T13:22:08Z 2020-05-19T14:33:50Z h404bi member/h404bi fish-pwsh

]]>
PowerShell 与 Windows Terminal 增强配置 tag:www.v2ex.com,2020-02-29:/t/648742 2020-02-29T19:50:56Z 2020-03-02T01:30:31Z raawaa member/raawaa 双系统切换来切换去还是挺麻烦的。加上 Windows Terminal + PowerShell 的体验越来越好于是去年年底把 Arch Linux 彻底卸掉了。本身不是专业的,在终端里最多就是批处理一下文件,PowerShell 开箱即用虽然挺糟糕,但是调教一下还是够用了。

PSReadLine

PSReadLine 是 PowerShell 的官方模块,为 PowerShell 提供了缺失的交互特性。例如像 zsh/fish 那样的交互式的补全、语法高亮、emacs 按键模式等等。有了 PSReadLIne 之后的 PowerShell 才终于像点样了。

安装(详见官方项目 README):

Install-Module PSReadLine 

安装之后,PSReadLine 的一些特性并不会自动启用,可以在 PowerShell 的 profile 配置文件里自己按需配置。但是自己从头搞毕竟很烦,直接白嫖官方提供的配置样例就可以,已经非常好用了。

posh-git 与 oh-my-posh

posh-git 可以为 PowerShell 提供 git 命令补全。oh-my-posh 可以美化 prompt,提供各种主题。直接把两个一起安上:

Install-Module posh-git -Scope CurrentUser Install-Module oh-my-posh -Scope CurrentUser 

在 profile 配置文件中启用模块并选择 prompt 样式主题:

Import-Module posh-git Import-Module oh-my-posh Set-Theme Powerlevel10k-Lean 

Windows Terminal 美化

主要是配置字体和配色方案。配色方案可以在 iTerm2-Color-Schemes 这个项目中挑选。个人比较喜欢 Gruvbox Dark 配色。

Gruvbox Dark 配色预览

在 Windows Terminal 配置文件中加入 Gruvbox Dark 配色方案。

"schemes": [ { "name": "Gruvbox Dark", "black": "#1e1e1e", "red": "#be0f17", "green": "#868715", "yellow": "#cc881a", "blue": "#377375", "purple": "#a04b73", "cyan": "#578e57", "white": "#978771", "brightBlack": "#7f7061", "brightRed": "#f73028", "brightGreen": "#aab01e", "brightYellow": "#f7b125", "brightBlue": "#719586", "brightPurple": "#c77089", "brightCyan": "#7db669", "brightWhite": "#e6d4a3", "background": "#1e1e1e", "foreground": "#e6d4a3" } ] 

在 PowerShell 的 profile 部分选择 Gruvbox Dark 作为配色方案。同时做一些其他调整(因为 Windows Terminal 支持字体 ligature,所以选择了 Fira Code 字体):

{ // Make changes here to the powershell.exe profile "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "name": "Windows PowerShell", "commandline": "powershell.exe", "hidden": false, "fontFace": "Fira Code", "fontSize": 11, "colorScheme": "Gruvbox Dark", "cursorShape": "vintage" } 

最终效果

]]>
怎么把一个脚本方法注册为系统的环境变量? tag:www.v2ex.com,2020-02-26:/t/647802 2020-02-26T11:38:24Z 2020-02-26T09:37:21Z YOOHUU member/YOOHUU 网上搜到的一个脚本教程, 链接如下:
https://virtualcornerstone.com/2018/04/09/use-powercli-to-manage-users-on-an-esxi-host/

本来打算直接拿来用的, 看这老哥的用法我就直接懵逼了

翻了下脚本代码, 这个方法在脚本里面, 可怎么直接调用起来的? powershell 菜鸡一枚, 来请教下大佬

]]>
!微软又放鸽子了! tag:www.v2ex.com,2020-01-08:/t/636305 2020-01-08T14:49:11Z 2020-01-08T17:38:03Z Tumblr member/Tumblr 今天上午,微软 PowerShell 团队经理Steve Lee发推称:

在对 PowerShell 7.0 RC1 的所有已合并 PR 分类后,我们已经决定拟在下周发布个 RC2。GA 有望在二月早期发布。
你鸽你有理

站在产品的角度来说,也算是个好事吧。

]]>
分享 powershell ssh to Linux 脚本。 tag:www.v2ex.com,2019-12-26:/t/632549 2019-12-26T06:42:55Z 2019-12-24T06:40:55Z ps1aniuge member/ps1aniuge
win 连接 linux,有 3 种情况。
1 win 的 cmd to linux 的 bash
2 win 的 powershellv6,v7 to linux 的 bash
3 win 的 powershellv6,v7 to linux 的 powershell。



------讲解上述情况 2-----
在 powershell 中运行:ssh root@ip
在 win term 中编写

"commandline" : "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe -noexit -command 'ssh root@ip' ",


------讲解上述情况 3-----
3.1 脚本下载地址:
powershell 入门资料下载:含绝大多数电子书,入门基础资料。
https://pan.baidu.com/s/1p2zK-BewhursJxDNQnq5PQ



3.2 需求:
需要 linux 中安装 powershell,并改写 sshd 配置文件。
需要先配好 sshkey。

3.3 脚本用途:

3.3.1 在 powershell v6,v7 中,直接运行 ssh_to_centos7.ps1 ,可以进入 linux powershell 命令行。

3.3.2 建议改写 win term 标签配置文件。
{
"acrylicOpacity" : 0.5,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"tabTitle" : "ps62",
"commandline" : "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe -noexit -file d:\\ps\\ssh_to_centos7.ps1",
"scrollbarState": "visible",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Monaco_YH_Nero_Mono",
"fontSize" : 18,
"guid" : "{c3d2cb60-5f6d-4e83-89ee-eec17960fc9a}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png",
"name" : "PowerShell Core 7",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "c:\\ProgramData\\kasini3000",
"backgroundImage": "d:\\ps 壁纸.jpg",
"backgroundImageAlignment": "center",
"backgroundImageAlignment": "uniformToFill",
"backgroundImageOpacity" : 0.2
},

编写并保存后,点击 win term 标签,即可打开远程终端,基本可以代替终端软件。 ]]>
PowerShell Core 7.0 RC 已经发布 tag:www.v2ex.com,2019-12-17:/t/629879 2019-12-17T09:12:26Z 2019-12-17T09:10:26Z Tumblr member/Tumblr Joey Aiello ( PowerShell 团队 PM )在微软的开发者博客上宣布 PowerShell 7.0 的 RC 版本发布,并公布将在下个月发布 GA。

PowerShell 7.0 对广大 Windows 平台的 PowerShell 用户来说,最惊艳的莫过于 Out-GridView 命令的回归,同时 Joey 也列了一些功能卖点:

  • .NET Core 3.1 (LTS)
  • ForEach-Object -Parallel
  • Windows compatibility wrapper
  • New version notification
  • New error view and Get-Error cmdlet
  • Pipeline chain operators (&& and ||)
  • Ternary operator (a ? b : c)
  • Null assignment and coalescing operators (?? and ??=)
  • Cross-platform Invoke-DscResource (experimental)
  • Out-GridView, -ShowWindow and other legacy GUI cmdlets are back on Windows
  • A ton of awesome quality-of-life improvements too numerous to list out here
]]>
powershell 一个很诡异的问题 tag:www.v2ex.com,2019-11-23:/t/622499 2019-11-23T13:57:19Z 2019-11-24T01:38:20Z yukinotech member/yukinotech
先说自己的版本,版本非常低的 win10 专业版,因为比较厌恶升级,已经关了自动更新 2,3 年了。至今我的任务管理器仍然不能显示 GPU。。

回到正题,是一个什么问题呢?就是 powershell 会卡住,然后 ctrl+c 一下就不卡了。。

2 个例子
1. 用 youtube-dl (一个命令行工具)下视频时,有时候会卡住,shell 里显示的速度和已下载一直卡住不动,这时候 ctrl+c 一下,就马上不卡了

2.自己写的一个 http 代理模块,在访问到网页时会打 log。代理程序是用 powershell 在命令行起的。用这个代理访问网页有时候会一直转,加载不出来。然后会发现 log 在 powershell 没打出来。这时候 ctrl+c 一下,log 刷的一下就打出来了。网页也进去了。

有没有大神赐教,这是啥问题? ]]>
powershell 的 ntp 校时脚本,光棍节秒杀专用! tag:www.v2ex.com,2019-11-07:/t/617147 2019-11-07T03:21:10Z 2019-11-05T03:19:10Z ps1aniuge member/ps1aniuge 管理员权限运行,

11 月 7 日是京东双 11“电脑数码狂欢日”,京东为在这一天购买电脑的网友给出了四个秒杀时间节点,分别是 0 点,10 点,16 点和 20 点,部分笔记本电脑和 NAS 设备甚至有千元以上的降价幅度。

我的所有 powershell 脚本,下载地址:
https://pan.baidu.com/s/16deKKe3ZnCg809lffiVZWg

欢迎收藏,给我铜币。 ]]>
PowerShell 如何强行覆盖一个文件 tag:www.v2ex.com,2019-11-05:/t/616379 2019-11-05T03:17:11Z 2019-11-10T01:26:41Z wwwwzf member/wwwwzf PS D:\test\hhff> Move-Item D:\test\hhff/*.jpg D:\test\Protected Move-Item : 当文件已存在时,无法创建该文件。

移动的文件夹,与目标文件夹有相同文件名的文件,如何强行覆盖?

]]>
如何使用命令行或 PowerShell 删除一个已经安装好的证书 tag:www.v2ex.com,2019-11-04:/t/616237 2019-11-04T13:29:13Z 2019-11-04T15:27:13Z wwwwzf member/wwwwzf 已知,使用下面命令,可以导入一个 PFX 证书: certutil -f -importPFX -p passwd D:\cert\server.pfx

现在问题是,如何删除一个已经导入进去的 IIS 证书,比如 IIS 证书名是:Name, 有无方法,用命令行或 PowerShell 来删除它。

网上找到的方法是采用 CertUtil [选项] -delstore CertificateStoreName CertId 来删除,但无法读到 CertificateStoreName 与 CertId,也就没有办法了,请求协助。

]]>
PowerShell 如何导入已有的 SSL 证书 tag:www.v2ex.com,2019-11-02:/t/615532 2019-11-02T04:43:38Z 2019-11-03T04:43:39Z wwwwzf member/wwwwzf 一个 IIS 导出的 SSL 安全证书,如名叫:test.pfx 它包含密码,比如叫:123456

如何用 powershell 将他导到另一台服务器上呢? 因为操作系统是 windows core 模式,没有视窗界面,然后卡在这上面了,呜呜,求大佬帮忙。

]]>
PowerShell 如何定义文件夹的权限 tag:www.v2ex.com,2019-11-02:/t/615502 2019-11-02T02:59:57Z 2019-11-02T18:35:40Z wwwwzf member/wwwwzf icacls D:\test\gg* /grant[:r] Users:F /t #覆盖子目录所有文件完全控制

上面命令,仅能对文件夹中的文件起作用,文件夹本身不起作用,请问有什么语法,支持直接操作文件夹权限的吗?

希望哪位大哥相助:)

]]>
推荐一个 github 上的 PowerShell 项目 tag:www.v2ex.com,2019-09-09:/t/599459 2019-09-09T15:30:44Z 2019-11-05T15:01:52Z Tumblr member/Tumblr 无意中发现一个PowerShell 的项目,其它语言的项目蛮多的,PowerShell 的项目确实不多,即便有,多数也是脚本式的存在。

这个项目看上去气势磅礴,值得关注。

项目地址: https://github.com/chuanjiao10/kasini3000

]]>
Out-GridView 在 PowerShell Core 中回归了 tag:www.v2ex.com,2019-09-06:/t/598656 2019-09-06T09:15:22Z 2019-09-06T09:12:22Z Tumblr member/Tumblr 自 PowerShell Core 在 Linux 和 Mac 上的首秀,已经差不多 3 年了。今天,Out-GridView 通过GraphicalTools 模块在全部支持 PowerShell Core 的平台上登场了。


安装

如果要使用,运行以下 cmdlet 安装:

Install-Module Microsoft.PowerShell.GraphicalTools 

更多信息请访问微软开发者博客:Out-GridView Returns

]]>
powershell 6, 7 的新特性。 tag:www.v2ex.com,2019-07-02:/t/579290 2019-07-02T06:23:14Z 2019-07-02T06:29:43Z ps1aniuge member/ps1aniuge 1 每个特性都注明了版本号,从这个版本开始,才支持这个特性。
2 欢迎挑毛病,让我更完善帖子。
3 大都是 ps6 的新特性。ps7 刚刚开始开发,新特性也只有一点点。



----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛


在 powershell 6.0 中新增内置变量
$IsCoreCLR
$IsLinux
$IsMacOS
$IsWindows
用于判断系统。

#假想中的复制文件脚本,由于 win,linux 目录路径,不兼容。
#所以你要在一个脚本中,分别写 2 段代码。
if ($IsWindows)
{
copy-item c:\xxx d:\yyy
}

if ($IsLinux)
{
copy-item /home/user1 /home/user2
}



我原创 分享! 2016-12-02
if ($PSEdition -eq 'Desktop')
{
#win
}

if ($PSEdition -eq 'Core')
{
#linux
}
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛

powershell6.0 即 linux 版中,New-PSSession 新增 3 个参数, [-HostName ] , [-UserName ] , [-KeyFilePath ] ,
-SSHTransport 布尔型 强制使用 ssh 协议,而不是 winrm 协议
用于 linux 客户机,连接 linux 服务器。

命令:
$连接 2 = New-PSSession -HostName 127.0.0.1 -UserName user006 #手动输入密码或用-KeyFilePath 选项
Invoke-Command -Session $连接 2 -ScriptBlock {new-item ~/ccc.txt}

用了-HostName 参数后,端口默认 22。
用了-computername 参数后,端口默认 5985。
----------------------------------------------------------------
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃███V6.0██████┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
Get-Content $Path -Encoding Byte (或许临时)变更为
Get-Content $Path -AsByteStream ]]>
新出炉的 ssh-copy-id6.ps1,是新版 vscode 的最佳拍档 tag:www.v2ex.com,2019-06-14:/t/573889 2019-06-14T04:05:46Z 2019-07-15T09:39:13Z ps1aniuge member/ps1aniuge 这个版本原生支持从本地 vscode 经 ssh,打开编写,任何远程代码。
它基于使用秘钥的 ssh。

而我编写的这个脚本,专门帮助你实现,从 win 发布公钥到 linux。 ]]>
把那 5000 多万条企业数据放到 SQLite 数据库里 tag:www.v2ex.com,2019-06-10:/t/572537 2019-06-10T09:20:16Z 2019-06-10T23:02:31Z Tumblr member/Tumblr 至于是哪 5000 多万条,自己去找吧。

需要先安装 PSSQLite 模块,具体可以参考用 PowerShell 玩转 SQLite 数据库

Import-Module PSSQLite $ent_codes_db = "D:\Scripts\DB\ent_codes.sqlite" $query = "INSERT INTO ent_codes VALUES (@name, @code, @regday, @character, @legalr, @capital, @bscope, @prov, @city, @addr)" Get-ChildItem D:\Downloads\json\ -Recurse -File | % { (Get-Content $_.fullname | ConvertFrom-Json).erDataList | % { $name = $_.name $code = $_.code $regday = $_.registrationDay $character = $_.character $legalr = $_.legalRepresentative $capital = $_.capital $bscope = $_.businessScope $prov = $_.province $city = $_.city $addr = $_.address Invoke-SqliteQuery -DataSource $ent_codes_db -Query $query -SqlParameters @{ name = $name code = $code regday = $regday character = $character legalr = $legalr capital = $capital bscope = $bscope prov = $prov city = $city addr = $addr } } } 
]]>
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86