GVKun编程网logo

PowerShell 第 2 轮中的 Git 配置双引号

21

这篇文章主要围绕PowerShell第2轮中的Git配置双引号展开,旨在为您提供一份详细的参考资料。我们将全面介绍PowerShell第2轮中的Git配置双引号,同时也会为您带来Kubernetesp

这篇文章主要围绕PowerShell 第 2 轮中的 Git 配置双引号展开,旨在为您提供一份详细的参考资料。我们将全面介绍PowerShell 第 2 轮中的 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 第 2 轮中的 Git 配置双引号

PowerShell 第 2 轮中的 Git 配置双引号

如何解决PowerShell 第 2 轮中的 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"'' -replace ''"'',''\"'')

也不起作用。 (我不使用 PowerShell Core、v7 或其任何跨平台变体)。

解决方法

这不是一个答案,而是一些可以尝试的想法。我无法通过调用 git 所涉及的所有引号,所以我作弊并将 GIT 目录放在我的路径中以使其工作。这不是一个持久的变化,但它足以玩弄一下。

$ENV:Path+=";C:\Program Files\Git\cmd"

完成后,我创建了一个包含命令的 PS 变量并使用 Invoke-Expression 运行它。这允许使用诸如 $merged 之类的变量动态创建命令。

$myCMD = "GIT Status"
Invoke-Expression $CMD

就您而言,看看这是否有助于拉近您的距离。使用 PS 变量将允许将 $merged 作为命令的一部分进行扩展。我不知道 $merged 是什么,所以我使用了一个虚拟值。

$Merged = "FooBar"
$Command = "GIT Config --global mergetool.vscode.cmd --wait $Merged"
Invoke-Expression $Command

不确定这是否有帮助,但是,试一试

Kubernetes powershell 模块的 Powershell cmdlet 参考

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版

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发送微信信息

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应用程序执行“授予权限”操作

Powershell – 使用Powershell对Azure AD应用程序执行“授予权限”操作

我正在使用AzureAD模块创建一个Azure AD应用程序来调用Microsoft Graph API.我可以成功生成访问令牌.但是,当我尝试调用API时,我有一个错误“消息”:“无效的范围声明/角色.”.

当我在Azure门户中创建的应用程序中单击“授予权限”按钮并重试对API的调用时,调用正在运行.

我没有找到任何地方如何使用Powershell执行此“授予权限”操作.有没有办法做到这一点 ?

谢谢

达米安

解决方法

有一种简单的方法(作为管理员),它要求您为Powershell安装AzureAD和AzureRM模块,并且不受Microsoft支持.

我的博客的原始帖子/参考在这里: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 第 2 轮中的 Git 配置双引号的分享已经告一段落,感谢您的关注,如果您想了解更多关于Kubernetes powershell 模块的 Powershell cmdlet 参考、Microsoft.SharePoint.PowerShellpipe理单元:不正确的Windows PowerShell版本3.0 当前控制台支持Window PowerShell 2.0版、MSSQL/WMI/PowerShell结合篇(四)PowerShell发送微信信息、Powershell – 使用Powershell对Azure AD应用程序执行“授予权限”操作的相关信息,请在本站查询。

本文标签: