Powershell 将curl与默认凭据一起使用
我想使用带有默认凭证的curl,这样我就不需要在代码中输入机密信息。可能吗 代码应该是这样的:Powershell 将curl与默认凭据一起使用,powershell,curl,credentials,Powershell,Curl,Credentials,我想使用带有默认凭证的curl,这样我就不需要在代码中输入机密信息。可能吗 代码应该是这样的: $a = curl UseDefaultCredentials -method POST .... (不输入-u username:password)在PowershellCore v7之前,curl是Invoke WebRequest的别名 Get-Alias -Definition Invoke-WebRequest | Format-Table -AutoSize # Results &l
$a = curl UseDefaultCredentials -method POST ....
(不输入-u username:password)在PowershellCore v7之前,curl是Invoke WebRequest的别名
Get-Alias -Definition Invoke-WebRequest |
Format-Table -AutoSize
# Results
<#
CommandType Name Version Source
----------- ---- ------- ------
Alias curl -> Invoke-WebRequest
Alias iwr -> Invoke-WebRequest
Alias wget -> Invoke-WebRequest
#>
Get Alias-Definition Invoke WebRequest |
表格格式-自动调整大小
#结果
调用WebRequest
别名iwr->调用WebRequest
别名wget->Invoke WebRequest
#>
PowerShell IVR(也称为curl)具有凭证参数
因此,如果您想使用real curl.exe,则必须使用该扩展名,否则将由PowerShell命令首选项接管
如果未指定路径,PowerShell将使用以下优先级
在对当前文件中加载的所有项目运行命令时进行排序
会议:
Alias Function Cmdlet外部可执行文件(程序和
非PowerShell脚本)
因此,如果键入“help”,PowerShell将首先查找别名
名为help,然后是名为help的函数,最后是名为
救命啊。它运行找到的第一个帮助项
因此,请参阅有关如何使用cmdlet的帮助文件
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Invoke-WebRequest).Parameters
(Get-Command -Name Invoke-WebRequest).Parameters.Keys
# Results
<#
...
Credential
...
#>
Get-help -Name Invoke-WebRequest -Examples
# Results
<#
$R = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+mile
$R.AllElements | where {$_.innerhtml -like "*=*"} | Sort { $_.InnerHtml.Length } | Select InnerText -First 5
the shortest HTML value often helps you find the most specific element that matches that text.
$R=Invoke-WebRequest http://www.facebook.com/login.php -SessionVariable fb
$FB
$Form = $R.Forms[0]
$Form | Format-List
$Form.fields
$Form.Fields["email"]="User01@Fabrikam.com"
$R=Invoke-WebRequest -Uri ("https://www.facebook.com" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields
# Sends a sign-in request by running the Invoke-WebRequest cmdlet. The command specifies a value of "fb" for the SessionVariable parameter, and saves
$R.StatusDescription
(Invoke-WebRequest -Uri "http://msdn.microsoft.com/en-us/library/aa973757(v=vs.85).aspx").Links.Href
#>
Get-help -Name Invoke-WebRequest -Full
Get-help -Name Invoke-WebRequest -Online
#获取模块、cmdlet或函数的详细信息
(Get命令-Name Invoke WebRequest).Parameters
(Get命令-Name Invoke WebRequest).Parameters.Keys
#结果
获取帮助-名称调用WebRequest-示例
#结果
获取帮助-名称调用WebRequest-完整
获取帮助-名称调用WebRequest-联机
或者指定扩展名并使用curl.exe的命令行选项
至于在PowerShell中使用凭据安全性,这是一个有很多文档记录的东西,有几个选项。MS powershellgallery.com中有用于凭据管理和用例的模块
Find-Module -Name '*credential*' |
Format-Table -AutoSize
# Results
<#
Version Name Repository Description
------- ---- ---------- -----------
2.0 CredentialManager PSGallery Provides access to credentials in the Windows Credential Manager
...
1.0.11 pscredentialmanager PSGallery This module allows management and automation of Windows cached credentials.
...
1.1.7 CredentialStore PSGallery CredentialStore saves powershell credentials securely to file
...
1.0.0 CredentialLocker PSGallery CredentialLocker is a module that provides commandlets to manage credentials in the password vault....
...
1.1 CredentialsManager PSGallery The module Credentials Manager provides you with convenient and safe way to store your credentials ...
...
1.1.0 PSCredentialTools PSGallery PSCredentialTools provides various methods for securely storing and retrieving credentials used in ...
...
1.0.477 PSCredentialStore PSGallery A simple credential manager to store and reuse multiple credential objects.
...
#>
Find Module-Name'*credential*'|
表格格式-自动调整大小
#结果
您是否尝试了某些操作,可能收到了错误消息?是的,我尝试了,它返回“Invoke WebRequest:找不到接受参数的位置参数”