本文将介绍PowerShell中的Git配置双引号的详细情况,特别是关于powershell安装git的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关
本文将介绍PowerShell 中的 Git 配置双引号的详细情况,特别是关于powershell安装git的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于Kubernetes powershell 模块的 Powershell cmdlet 参考、Microsoft.SharePoint.PowerShellpipe理单元:不正确的Windows PowerShell版本3.0 当前控制台支持Window PowerShell 2.0版、MSSQL/WMI/PowerShell结合篇(四)PowerShell发送微信信息、Powershell – 使用Powershell对Azure AD应用程序执行“授予权限”操作的知识。
本文目录一览:- PowerShell 中的 Git 配置双引号(powershell安装git)
- Kubernetes powershell 模块的 Powershell cmdlet 参考
- Microsoft.SharePoint.PowerShellpipe理单元:不正确的Windows PowerShell版本3.0 当前控制台支持Window PowerShell 2.0版
- MSSQL/WMI/PowerShell结合篇(四)PowerShell发送微信信息
- Powershell – 使用Powershell对Azure AD应用程序执行“授予权限”操作
PowerShell 中的 Git 配置双引号(powershell安装git)
如何解决PowerShell 中的 Git 配置双引号?
这被问到 here,但没有为 PowerShell 提供解决方案。给出的解决方案不适用于 PowerShell(特别是 VSCode 中的 PowerShell 5.1)。
我试过了
git config --global mergetool.vscode.cmd ''"code --wait $MERGED"''
但我丢失了双引号(即相应的 .gitconfig
文件中没有双引号)。仅供参考,单引号是将 $MERGED
作为字符串文字传递而不是让 PowerShell 尝试扩展它所必需的。
我也试过
echo ''"code --wait $MERGED"'' | git config --global mergetool.vscode.cmd
git config --global mergetool.vscode.cmd ''`"code --wait $MERGED`"''
git config --global mergetool.vscode.cmd @''
code --wait $MERGED
''@
但没有任何效果。有没有办法在 PowerShell 中执行此操作?
另外,我研究了this question,以及
的解决方案git config --global mergetool.vscode.cmd ''\"code --wait $MERGED\"''
也没有
git config --global mergetool.vscode.cmd "\"code --wait $MERGED\""
也不起作用。
我得到的最接近的是使用
git config --global mergetool.vscode.cmd ''" code --wait $MERGED "''
但这会输出字符串中的空格:
[mergetool "vscode"]
cmd = " code --wait $MERGED "
解决方法
不幸的是,需要一个模糊的解决方法(有关通过可安装模块的通用解决方案,请参阅底部部分):
git config --global mergetool.vscode.cmd --% "\"code --wait $MERGED\""
注意:这假设您希望在 ~/.gitconfig
中得到以下内容,这可能不是您的意图:
[mergetool "vscode"]
cmd = \"code --wait $MERGED\"
相反,正如 one of the answers you link to 建议的那样,只有 $MERGED
部分应该被双引号加上嵌入双引号,在这种情况下,您应该使用(见底部的替代方案):
git config --global mergetool.vscode.cmd --% "code --wait \"$MERGED\""
那会给你:
[mergetool "vscode"]
cmd = code --wait \"$MERGED\"
也就是说,只有 shell 命令中那些单独的参数需要你的值构成,为了 shell > 必须用 "..."
括起来。
请注意,重新转义逐字 git
字符的是 "
。在给定的配置值中作为配置文件中的 \"
。配置文件中的 Unescaped "
- 具有 语法 函数 对于 git
本身 - 仅在您通过带有前导和/或尾随空格的值,以便将值作为一个整体进行分隔; 带有(内部)空格的值本身不需要手动双引号:git
将它们按原样存储在配置文件中,除了将嵌入的 \
转义为\\
和 "
为 \"
。
从 PowerShell 传递 --% "code --wait \"$MERGED\""
表示将 逐字 值 code --wait "$MERGED"
传递给 git config --global mergetool.vscode.cmd
的意图,这是 {{1 }} 命令行[1](sh
是一个兼容 POSIX 的 shell,sh
甚至在 Windows 上也可以使用,通过 git
实现随附),其中(环境)变量引用 bash
周围的 "..."
确保扩展值按原样传递给目标二进制文件 $MERGED
,即使它包含空格,例如。
您可以通过查询之后的值来验证这一点:
code
# After running the command above:
PS> git config --global mergetool.vscode.cmd
code --wait "$MERGED"
和配置文件格式记录在 here 中,也可以通过运行 git config
在本地获得,或者仅在类 Unix 平台上使用 git help config
解决方法的说明:
使用 man git-config
,即 stop-parsing symbol,允许您控制传递给外部程序的后续参数的精确引用(同时还抑制 PowerShell 变量的扩展,因此 --%
是保持原样),而 PowerShell 默认在执行自己的解析后在幕后执行重新引用。
撇开双引号整个命令行最终不是正确的方法,纯粹从 PowerShell 语法的角度来看,您尝试了什么,$MERGED
,应该 工作 - PowerShell 应该在幕后自动将其转换为 ''"code --wait $MERGED"''
- 但从 PowerShell 7.1 开始,由于长期存在的错误,描述详情见this answer。
虽然显式 "\"code --wait $MERGED\""
转义嵌入的 \
字符。(!)通常是一种更好的解决方法,并且在 PowerShell (Core) 7+ 中可靠地工作,在 Windows PowerShell 中存在一些边缘情况,而您遇到了其中一种情况:
"
这在 Windows PowerShell 中不起作用的原因是它错误地得出 # Alternative workaround for *PowerShell (Core) v7+ only*
git config --global mergetool.vscode.cmd ''\"code --wait $MERGED\"''
构成句法双引号的结论,因此没有将参数括在 {{1} };也就是说,它不传递 \"...\"
,而是只传递 "..."
作为目标进程命令行的一部分。
请注意,引用参数单独避免了讨论的边缘情况,因此即使在 Windows PowerShell 中,显式的 "\"...\""
转义也可以工作:
\"...\"
通过模块 \
的通用解决方案:
如果您想解决大多数[2](在Windows上)/所有(在Unix上)对外部程序调用的引用问题,考虑一下我的 Native
module 的 # Also works in Windows PowerShell,because the edge case is avoided.
git config --global mergetool.vscode.cmd ''code --wait \"$MERGED\"''
函数,它封装了所有必需的解决方法:
Native
[1] ie
似乎在调用 # Install the module in the current user''s scope.
Install-Module Native
# Simply prepend `ie` to your external-program calls,which correctly
# handles all behind-the-scenes re-quoting,allowing you to focus on
# PowerShell syntax only.
ie git config --global mergetool.vscode.cmd ''code --wait "$MERGED"''
如下(使用带有占位符的 git
语法进行说明):sh
也就是说,在调用配置值中存储的命令行时,附加了 sh
提供的传递参数。请注意,第一个 post sh -c ''<config-value> "$@"'' ''<config-value>'' <git-supplied args>
参数再次是配置值,它绑定到 git
,即设置调用名称,因此不是传递数组的一部分- 通过参数,-c
。 $0
提供的传递参数的一个示例是要编辑的文件的路径,该文件被传递到存储在 "$@"
配置值中的命令行。
[2] 适用于所有外部程序的解决方案在 Windows 上从根本上是不可能的,因为每个程序都可以自行决定如何解析对传递的参数进行编码的字符串。但是,git
知道并适当地应用了一些普遍存在的模式,这特别使它与批处理文件和类似 core.editor
的可执行文件一起工作。
Kubernetes powershell 模块的 Powershell cmdlet 参考
如何解决Kubernetes powershell 模块的 Powershell cmdlet 参考?
在哪里可以看到 k8s 模块 here 的 cmdlet 参考?
谢谢
解决方法
这是为了更好的可见性而发布的社区 wiki 答案。
正如评论中已经提到的,您正在寻找的参考资料可以在 here(module page 左侧的 Project Site
链接)中找到。
Microsoft.SharePoint.PowerShellpipe理单元:不正确的Windows PowerShell版本3.0 当前控制台支持Window PowerShell 2.0版
我在我的机器上安装了SharePoint 2010,用于开发目的,而且我错误地升级到.Net 4.0和PowerShell 3.0。
解决这个问题,使用-version 2.0或-v 2 switch / arguement运行powershell并不完全正常。
所以,这个问题是如何在PowerShell中添加Microsoft.Sharepoint.PowerShellpipe理单元,在具有.Net 4.0框架的机器上?
尝试1:
Windows中的IP发现
在Windows中检测文件“copY”操作
HRESULT:0x80040154(REGDB_E_CLASSNOTREG))
对于Windows窗体,PostMessage等于自己的什么?
从C#中selectsql Server数据库中的特定logging
PS> Add-PSSnapin Microsoft.Sharepoint.Powershell The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered. PS> Get-SPSite('http://myServerName/') Get-SPSite : Microsoft SharePoint is not supported with version 4.0.30319.18052 of the Microsoft .Net Runtime.
好的,所以我尝试2:
PS> powershell.exe -version 2.0 PS> Add-PSSnapin Microsoft.Sharepoint.Powershell Add-PSSnapin : Incorrect Windows PowerShell version 3.0. Windows PowerShell version 2.0 is supported in the current console. At line:1 char:13 + Add-PSSnapin <<<< Microsoft.Sharepoint.PowerShell + CategoryInfo : InvalidArgument: (Microsoft.Sharepoint.PowerShell:String) [Add-PSSnapin],PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
我也尝试设置快捷方式的目标。 并卸载以q结尾的Windows更新
所以,这是我的错误,我无法find任何信息: 不正确的Windows PowerShell版本3.0。 当前控制台支持Windows PowerShell版本2.0。
有什么想法吗?
在哪里写日志的Windows应用程序
如何测量C#中的系统空闲时间,不包括看电影等?
如何在Windows窗体上显示必填字段
.NET EXE和DLL之间的堆栈/堆区别
采用Windows媒体基础的H.264编码
如果我打电话,它似乎为我工作
powershell.exe -version 2.0
从命令提示符而不是从Powershell调用它。
最近SharePoint 2010更新后,我可以添加PowerShell管理单元,而在版本2.0中运行PowerShell
MSSQL/WMI/PowerShell结合篇(四)PowerShell发送微信信息
本文介绍如何通过PowerShell发送微信信息
先申请企业微信(企业、政府、组织三种类型),通过PowerShell调用企业微信的API群发接口发送微信信息,API详细信息可参考企业微信开发者文档
以下为PowerShell调用企业微信API发送文本信息
----Script File: send_WeChat.ps1
param($param1,$param2,$param3)
##设置16-32位长度的密钥
function Set-Key {
param([string]$string)
$length = $string.length
$pad = 32-$length
if (($length -lt 16) -or ($length -gt 32)) {Throw "String must be between 16 and 32 characters"}
$encoding = New-Object System.Text.ASCIIEncoding
$bytes = $encoding.GetBytes($string + "0" * $pad)
return $bytes
}
##解密方法
function Get-EncryptedData {
param($key,$data)
$data | ConvertTo-securestring -key $key |
ForEach-Object {[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::securestringToBSTR($_))}
}
##发送微信方法
function send_WeChat_To_DBA {
Param(
[String]$corpid,
[String]$pwd,
[String]$Content
)
$auth_string = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$pwd"
$auth_values = Invoke-RestMethod $auth_string
$token = $auth_values.access_token
$body="{
`"toparty`":`"receive group id`",
`"agentid`":`"your agent id`",
`"text`":{
`"content`":`"$content`"
},
`"msgtype`":`"text`"
}"
$CN=[System.Text.Encoding]::UTF8.GetBytes($body)
Invoke-RestMethod "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token" -ContentType "application/json" -Method Post -Body $CN
}
##解析帐号密码
$cidstr= Get-Content E:\Monitor\cidstr.txt;
$pwdstr = Get-Content E:\Monitor\keystr.txt;
$cidkey = Set-Key $cidstr;
$pwdkey = Set-Key $pwdstr;
$cidfromFile = Get-Content E:\Monitor\wxcid.txt;
$pwdfromFile = Get-Content E:\Monitor\wxpwd.txt;
$corpid = Get-EncryptedData -data $cidfromFile -key $cidkey;
$pwd = Get-EncryptedData -data $pwdfromFile -key $pwdkey;
$content=$param1+$param2+$param3
##调用发送方法
send_WeChat_To_DBA -corpid $corpid -pwd $pwd -Content $content
##send_WeChat.ps1调用方式
E:\Monitor\send_WeChat.ps1 $param1 $param2 $param3
Powershell – 使用Powershell对Azure AD应用程序执行“授予权限”操作
当我在Azure门户中创建的应用程序中单击“授予权限”按钮并重试对API的调用时,调用正在运行.
我没有找到任何地方如何使用Powershell执行此“授予权限”操作.有没有办法做到这一点 ?
谢谢
达米安
解决方法
我的博客的原始帖子/参考在这里:http://www.lieben.nu/liebensraum/2018/04/how-to-grant-oauth2-permissions-to-an-azure-ad-application-using-powershell-unattended-silently/
应该帮助您完成此任务的特定代码示例:
Function Grant-OAuth2PermissionsToApp{ Param( [Parameter(Mandatory=$true)]$Username,#global administrator username [Parameter(Mandatory=$true)]$Password,#global administrator password [Parameter(Mandatory=$true)]$azureAppId #application ID of the azure application you wish to admin-consent to ) $secpasswd = ConvertTo-securestring $Password -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($Username,$secpasswd) $res = login-azurermaccount -Credential $mycreds $context = Get-AzureRmContext $tenantId = $context.Tenant.Id $refreshToken = @($context.TokenCache.ReadItems() | where {$_.tenantId -eq $tenantId -and $_.ExpiresOn -gt (Get-Date)})[0].RefreshToken $body = "grant_type=refresh_token&refresh_token=$($refreshToken)&resource=74658136-14ec-4630-ad9b-26e160ff0fc6" $apiToken = Invoke-RestMethod "https://login.windows.net/$tenantId/oauth2/token" -Method POST -Body $body -ContentType 'application/x-www-form-urlencoded' $header = @{ 'Authorization' = 'Bearer ' + $apiToken.access_token 'X-Requested-With'= 'XMLHttpRequest' 'x-ms-client-request-id'= [guid]::NewGuid() 'x-ms-correlation-id' = [guid]::NewGuid()} $url = "https://main.iam.ad.ext.azure.com/api/RegisteredApplications/$azureAppId/Consent?onBehalfOfAll=true" Invoke-RestMethod -Uri $url -Headers $header -Method POST -ErrorAction Stop }
我们今天的关于PowerShell 中的 Git 配置双引号和powershell安装git的分享就到这里,谢谢您的阅读,如果想了解更多关于Kubernetes powershell 模块的 Powershell cmdlet 参考、Microsoft.SharePoint.PowerShellpipe理单元:不正确的Windows PowerShell版本3.0 当前控制台支持Window PowerShell 2.0版、MSSQL/WMI/PowerShell结合篇(四)PowerShell发送微信信息、Powershell – 使用Powershell对Azure AD应用程序执行“授予权限”操作的相关信息,可以在本站进行搜索。
本文标签: