首页
关于
Search
1
分享一些收集的Sync Key
5,508 阅读
2
mysql错误ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server
1,634 阅读
3
对比win10系统上的三种软件包管理器scoop、chocolatey、winget
1,626 阅读
4
Resilio Sync 许可证下载
1,594 阅读
5
阿里云盘资源分享
1,249 阅读
前端
CSS
NodeJS
Javascript
小程序
Webpack
Vue
Typescript
Linux
软件教程
云服务器
脚本编程
技术扩展
Scoop
SSR
Youtube-dl
You-Get
Typecho
Annie
奇技淫巧
资源分享
Sync Key
随笔
疑难杂症
mysql
Docker
Python
Serverless
登录
Search
标签搜索
docker
K3S
powershell
scoop
webstorm
jQuery
webpack
typecho
mysql
windows10
linux
typescript
ssh
windows11
vue
git
Sync
fastify
winget
github
偏向技术
累计撰写
99
篇文章
累计收到
2
条评论
首页
栏目
前端
CSS
NodeJS
Javascript
小程序
Webpack
Vue
Typescript
Linux
软件教程
云服务器
脚本编程
技术扩展
Scoop
SSR
Youtube-dl
You-Get
Typecho
Annie
奇技淫巧
资源分享
Sync Key
随笔
疑难杂症
mysql
Docker
Python
Serverless
页面
关于
搜索到
4
篇与
powershell
的结果
2022-07-05
PowerShell最佳使用实践
PowerShell 是一种跨平台的任务自动化解决方案,由命令行 shell、脚本语言和配置管理框架组成。 PowerShell 在 Windows、Linux 和 macOS 上运行,这里主要介绍怎么使 PowerShell 在 Windows 下像 Bash 在 Linux 下一样好用。 #准备 #安装 Windows Terminal #应用商店安装(建议) Windows Terminal:点此链接 Windows Terminal Preview:点此链接 #Github 安装 进入 Release在新窗口打开 页面,选择 Win 10 或者 Win 11 系统下载 #包管理器安装(建议) 打开 PowerShell,输入 winget search "Microsoft.WindowsTerminal",结果如下所示: 复制 ❯ winget search "Microsoft.WindowsTerminal" 名称 ID 版本 源 ------------------------------------------------------------------------------- Windows Terminal Microsoft.WindowsTerminal 1.13.11431.0 winget Windows Terminal Preview Microsoft.WindowsTerminal.Preview 1.14.1432.0 winget 12345 执行安装命令 winget install --id=Microsoft.WindowsTerminal -e #Scoop 安装 powershell复制 scoop bucket add extras scoop install windows-terminal # update scoop update windows-terminal 1234 #升级 PowerShell #包管理器 powershell复制 winget install Microsoft.PowerShell # or winget upgrade Microsoft.PowerShell 123 #MSI 安装 下载对应的 msi在新窗口打开 包,进行安装 #Windows terminal 配置 #nerdfont 字体下载 Nerd Fonts在新窗口打开 是一个使用大量字体图标来解决程序员在开发过程中缺少合适字体的问题的项目,进入 nerdfonts在新窗口打开 下载页面,这里推荐 Caskaydia Cove Nerd Font在新窗口打开,下载之后,解压缩安装 #Windows terminal 设置 打开 Windows Terminal,进入设置 打开 JSON 文件 修改配置文件 settings.json 从可视化设置页面进行修改 配色方案选择 进入windowsterminalthemes在新窗口打开,选择一个喜欢的 Theme,点击 Get theme 按钮,以 Dark+ 主题为例 进入配置文件 settings.json,找到 schemes,将复制好的 json 内容复制到该位置下,记好对应的 name 修改 colorScheme,即完成了主题更换 #PowerShell 配置 #准备 确认当前 PowerShell 版本在 7.x 以上,如果当前显示的版本不是 7.x 以上,修改上文 Windows terminal 设置 中的默认配置文件过程 powershell复制 ❯ $PSVersionTable Name Value ---- ----- PSVersion 7.2.5 PSEdition Core GitCommitId 7.2.5 OS Microsoft Windows 10.0.25151 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 12345678910111213 #安装 PowerShell 模块 powershell复制 # posh-git 是一个提供 Git/PowerShell 集成的 PowerShell 模块 Install-Module posh-git -Scope CurrentUser # 适用于任何 shell 的提示主题引擎,美化作用 Install-Module oh-my-posh -Scope CurrentUser # 一个提供快速注册 tab-completion 和添加别名的模块 Install-Module Register-Completion -Scope CurrentUser 123456 #PowerShell 设置 打开配置文件,第一次可能不存在配置文件,执行下面命令,如果不存在,则创建,接着会在 powershell复制 if (!(Test-Path $profile)) { New-Item $profile -Force } notepad $profile # 如果有使用 vscode,推荐通过 vscode 打开 code $profile 123456 进入打开的 $profile 文件,导入模块,这样会在每次启动 Terminal 前执行其中的命令 复制 Import-Module posh-git Import-Module oh-my-posh Import-Module Register-Completion 123 #其他设置 进入 ohmyposh在新窗口打开 主题页面,选择一个主题,这里推荐 paradox powershell复制 # 设置 oh-my-posh 主题 Set-PoshPrompt -Theme paradox 12 切换字符格式 powershell复制 chcp 936 1 PSReadLine 配置(非常有用) powershell复制 # 设置预测文本来源为历史记录,(推荐) Set-PSReadLineOption -PredictionSource History # 每次回溯输入历史,光标定位于输入内容末尾 Set-PSReadLineOption -HistorySearchCursorMovesToEnd # 设置 Tab 为菜单补全和 Intellisense,(推荐) Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete # 设置向上键为后向搜索历史记录 Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向下键为前向搜索历史纪录 Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward 1234567891011121314 设置 Alias,这里借助 Register-Completion,可以实现和 Bash 设置别名一样的体验,下面是一些示例: powershell复制 Register-Alias ll ls Register-Alias la ls Register-Alias np notepad Register-Alias swd "echo $pwd" Register-Alias apps "cd ~/Projects" Register-Alias i "cd ~/Projects/$($args[0])" Register-Alias which Get-Command Register-Alias ip "ipconfig /all | findstr '192'" # 可以查看所有通过此方式注册的所有 Alias,除了纯粹的别名外(ll,la,np这种) Register-Alias myAlias "Get-Command -CommandType Function -Name '*AliasFunction'" 12345678910 常用命令自动补全结合 Alias 使用,执行下面命令后,输入 nc <Tab>,如果有经常使用的命令,可以添加到下面,更多内容点击查看在新窗口打开 powershell复制 # 下面命令请勿用双引号包裹 Register-Alias nc '"$args" | Invoke-Expression' # 下面命令,仅做演示用,真实场景可用于 ssh 命令或者真正的常用命令 New-Completion nc @{ 'scoop update' = @{'#tooltip' = 'Update scoop'}; 'winget upgrade' = @{'#tooltip' = 'Upgrade winget'}; } 1234567 Winget 自动补全在新窗口打开 powershell复制 # https://github.com/microsoft/winget-cli/blob/master/doc/Completion.md Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() $word = $wordToComplete.Replace('"', '""') $ast = $commandAst.ToString().Replace('"', '""') winget complete --word="$word" --commandline "$ast" --position $cursorPosition | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } 1234567891011 近期系统错误 powershell复制 function Get-ErrorEvent { param ( # suggest today, yesterday, and last week: [ArgumentCompleter({ $today = Get-Date -Format 'yyyy-MM-dd' $yesterday = (Get-Date).AddDays(-1).ToString('yyyy-MM-dd') $lastWeek = (Get-Date).AddDays(-7).ToString('yyyy-MM-dd') # create the completions: [System.Management.Automation.CompletionResult]::new($today, "Today", "ParameterValue", "all errors after midnight") [System.Management.Automation.CompletionResult]::new($yesterday, "Yesterday", "ParameterValue", "all errors after yesterday") [System.Management.Automation.CompletionResult]::new($lastWeek, "Last Week", "ParameterValue", "all errors after last week") })] [DateTime] $After ) # forward the parameter -After to Get-EventLog # if the user does not specify the parameter, all errors are returned: Get-EventLog -LogName System -EntryType Error @PSBoundParameters } 1234567891011121314151617181920212223 #总结 通过这几项设置,可以将 PowerShell 的体验拉到最好!!!
2022年07月05日
112 阅读
0 评论
0 点赞
2021-08-19
PowerShell 升级和 Windows Terminal 配置 PowerShell
#写作前面 如果你钟爱命令行工具,那么 Windows Terminal 和 Windows PowerShell 就是你不可或缺的工具。而且现在基本上都是 Windows 10 时代了嘛,所以 PowerShell 的安装更新方式也增加了几种,最简单的当然是在 Windows 10 应用商店中搜索 powershell,然后下载安装,目前最新版本为 7.1.4,这里我们介绍另外一种下载安装方式 —— Winget 首先我们要知道像 Mac、*nix 系统都是有自己的包管理器的,类似应用市场,遵循固定的格式和 Schema 就能让包管理器从互联网识别,由官方和社区维护,大家都可以通过一个命令来安装软件,这样听起来是不是很爽?再想想 Windows 安装软件的方式,想要安装,得跑去官网找下载地址,然后还有一系列安装流程,一不留神就安装了好几个软件,再一个是卸载软件,总是卸载不干净,这些年, Windows 上也踊跃出了不少的包管理器,比如 chocolatey、scoop,前者由官方和社区维护,后者由社区维护。 #下载安装 #第一步 查看 piwershell 当前版本,$psversiontable 或者 Get-Host | Select-Object Version,5.1 就是我目前的版本,这也是 Windows 10 自带的版本 powershell复制 ❯ $psversiontable Name Value ---- ----- PSVersion 5.1.22000.65 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.22000.65 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 123456789101112 #第二步 打开 Windows Terminal 终端,输入 winget 并回车,我们就能看到下面 winget 的使用方式。 powershell复制 ❯ winget Windows Package Manager v1.0.11694 版权所有 (C) Microsoft Corporation。保留所有权利。 WinGet 命令行实用工具可从命令行安装应用程序和其他程序包。 使用情况: winget [<命令>] [<选项>] 下列命令有效: install 安装给定的程序包 show 显示包的相关信息 source 管理程序包的来源 search 查找并显示程序包的基本信息 list 显示已安装的程序包 upgrade 升级给定的程序包 uninstall 卸载给定的程序包 hash 哈希安装程序的帮助程序 validate 验证清单文件 settings 打开设置 features 显示实验性功能的状态 experimental 实验性功能示例 export 导出已安装程序包的列表 import 安装文件中的所有程序包 如需特定命令的更多详细信息,请向其传递帮助参数。 [-?] 下列选项可用: -v,--version 显示工具的版本 --info 显示工具的常规信息 可在此找到更多帮助: https://aka.ms/winget-command-help 12345678910111213141516171819202122232425262728293031 接着执行 winget search powershell,我们可以看到出现了有10条记录,要认准官方正版的是 ID 带有 Microsoft 前缀,这意味着带有 Microsoft 前缀的软件都属于微软开发的 powershell复制 ❯ winget search powershell 名称 ID 版本 匹配 源 ----------------------------------------------------------------------------------------------- PowerShell Microsoft.PowerShell 7.1.4.0 winget Windows Terminal Preview Microsoft.WindowsTerminalPreview 1.10.1933.0 Tag: PowerShell winget Windows Terminal Microsoft.WindowsTerminal 1.9.1942.0 Tag: powershell winget PowerShell Preview Microsoft.PowerShell.Preview 7.2.0.8 Tag: powershell winget ConEmu Maximus5.ConEmu 11.210.8160 Tag: powershell winget EasyConnect lstratman.easyconnect 3.1.0.105 Tag: powershell winget Oh My Posh JanDeDobbeleer.OhMyPosh 3.173.0 Tag: PowerShell winget electerm electerm.electerm 1.16.1 Tag: PowerShell winget TfsCmdlets Igoravl.TfsCmdlets 2.1.0.2485 Tag: powershell winget PowerShell Universal IronmanSoftware.PowerShellUniversal 2.0.0 winget 12345678910111213 然后执行 winget install Microsoft.PowerShell,出现多条记录时,通过 ID 来进行下载 powershell复制 ❯ winget install Microsoft.PowerShell 已找到 PowerShell [Microsoft.PowerShell] 此应用程序由其所有者授权给你。 Microsoft 对第三方程序包概不负责,也不向第三方程序包授予任何许可证。 Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x64.msi ██████████████████████████████ 94.9 MB / 94.9 MB 已成功验证安装程序哈希 正在启动程序包安装... 已成功安装 123456789 #第三步 打开 Windows Terminal 的“设置” 接着点击“打开 JSON 文件”,文件位于 $home\AppData\Local\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\settings.json 然后,我们看到 “profiles” 下的 “list” 列表,正常情况下 Windows.Terminal.PowershellCore 是处于最后一个,这里我已经将它挪到了第一位,同时,我们将 “profiles” 上方的 "defaultProfile" 设置为 PowerShell 7 的 guid 值,这样,我们每次打开 Windows Terminal,就会是 PowerShell 7 了 #第四步 验证版本信息,可以看到已经是 7.1.4 了,可执行文件位置在 C:\Program Files\PowerShell\7\pwsh.exe,如果遇到 IDE,可以通过这个路径指定 PowerShell的版本 powershell复制 ❯ $psversiontable Name Value ---- ----- PSVersion 7.1.4 PSEdition Core GitCommitId 7.1.4 OS Microsoft Windows 10.0.22000 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 12345678910111213
2021年08月19日
263 阅读
0 评论
0 点赞
powershell使用ssh连接服务器免密登录
#服务器 powershell复制 # 生成密钥对,记住生成的目标位置 ssh-keygen # Generating public/private rsa key pair. # Enter file in which to save the key (/root/.ssh/id_rsa): # 查看配置,可先绕过这一步,如果一切顺利,就不需要这一步 # RSAAuthentication yes # PubkeyAuthentication yes # AuthorizedKeysFile /home/<username>/.ssh/authorized_keys sudo nano /etc/ssh/sshd_config # 更改公钥名称 进入第一步中的.ssh目录 mv id_rsa.pub authorized_keys # 查看私钥,复制到客户端保存 cat id_rsa 12345678910111213141516 #客户端 powershell复制 # 记录私钥保存的位置 ssh -i d:\id_rsa_ubuntu <username>@<hostname> # 注意:如果出现以下提示 # Load key "d:/id_rsa_ubuntu": invalid format # 请仔细检查id_rsa_ubuntu文件,最后一行需保留一行空行 123456
2021年01月10日
475 阅读
0 评论
0 点赞
powershell脚本开发中遇到的一些问题
#介绍 在使用 powershell 脚本开发过程中,遇到的一些问题,收藏在这里,方便下次查找。 #问题集合 windows 10应用商店无法访问 powershell复制 $manifest = (Get-AppxPackage Microsoft.WindowsStore).InstallLocation + '\AppxManifest.xml'; Add-AppxPackage -DisableDevelopmentMode -Register $manifest 12
2020年09月08日
63 阅读
0 评论
0 点赞