所以我正在测试我的一些路由Postman,我似乎无法接受此调用:
API函数
[RoutePrefix("api/Employees")]
public class CallsController : ApiController
{
[HttpGet]
[Route("{id:int?}/Calls/{callId:int?}")]
public async Task<ApiResponse<object>> GetCall(int? id = null, int? callId = null)
{
var testRetrieve = id;
var testRetrieve2 = callId;
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
邮差要求
http:// localhost:61941/api /员工/电话不工作
错误:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:61941/api/Employees/Calls'.",
"MessageDetail": "No action was found on the controller 'Employees' that matches the request."
}
Run Code Online (Sandbox Code Playgroud)
http:// localhost:61941/api/Employees/1/Calls WORKS
http:// localhost:61941/api/Employees/1/Calls/1 WORKS
知道为什么我不能在我的前缀和自定义路线之间使用可选项吗?我已经尝试将它们组合成一个自定义路线并且不会改变任何东西,任何时候我试图删除它导致问题的ID.
尝试在IIS中获取特定名称的应用程序池标识,例如:Test
成功通过下面的代码得到它,但不想遍历所有的webapps,是否有任何容易通过指定名称得到它?
Import-Module WebAdministration
Get-WebApplication
$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}
if ($webapp.name -eq 'Test')
{
$item = $webapp.processModel.identityType
break
}
}
echo $webapp.processModel.identityType
Run Code Online (Sandbox Code Playgroud) 我试图了解如何pipe |对象并调用该属性或方法.
Ex:
$a = Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\
$a.GetSomething() //calls the method
(Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\).GetSomething() //calls the method
Run Code Online (Sandbox Code Playgroud)
我可以管的输出Get-Item和invoke properties/methods上呢?
Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\ | call GetSomething()
Run Code Online (Sandbox Code Playgroud) 我有两个功能:
void DoSomething( const tchar* apsValue )
void DoSomething( size_t aiValue )
Run Code Online (Sandbox Code Playgroud)
现在我想传递'0'作为size_t:
DoSomething(0);
Run Code Online (Sandbox Code Playgroud)
编译器抛出一个错误:"对重载函数的模糊调用"
要解决这个问题,我可以使用static_cast,例如:
DoSomething(static_cast<size_t>(0));
Run Code Online (Sandbox Code Playgroud)
或者简单:
DoSomething(size_t(0));
Run Code Online (Sandbox Code Playgroud)
其中一个比另一个好吗?有没有其他方法可以解决这个问题?
这是我的代码:
$a = @()
for ($i = 0; $i -lt 5; $i++)
{
$item = New-Object PSObject
$item | Add-Member -type NoteProperty -Name 'Col1' -Value 'data1'
$item | Add-Member -type NoteProperty -Name 'Col2' -Value 'data2'
$item | Add-Member -type NoteProperty -Name 'Col3' -Value 'data3'
$item | Add-Member -type NoteProperty -Name 'Col4' -Value 'data4'
$a += $item
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我可以得到如下结果:
Col1 Col2 Col3 Col4
---- ---- ---- ----
0 1 2 3
1 2 3 4
2 3 4 5
3 4 …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的PowerShell脚本实现GUI,以简化其他用户的某个过程.我有以下PowerShell脚本:
if ($checkBox1.Checked) {
Try{
Start-Job { & K:\sample\adp.cmd }
$listBox1.Items.Add("ADP-Job started...")
}catch [System.Exception]{
$listBox1.Items.Add("ADP --> .cmd File not found!")}
}
if ($checkBox2.Checked) {
Try{
Start-Job { & K:\sample\kdp.cmd }
$listBox1.Items.Add("KDP-Job started...")
}catch [System.Exception]{
$listBox1.Items.Add("KDP --> .cmd File not found!")}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法连续检查所有正在运行的作业,并为已完成的每个作业执行某些操作?例如,在我的列表框中打印出类似这样的内容:ADP-Files have been uploaded
由于每个Job约需5分钟--4个小时我想到了一个循环,如果一个Job完成,每5分钟检查一次,但我无法弄清楚如何区分每个Job来做一些特定的事情.
我有一个脚本调用另一个脚本(带参数).被调用的脚本包含Install-WindowsFeaturecmdlet.当我运行脚本时,被调用的脚本会运行,但会返回以下错误:
Install-WindowsFeature : The term 'Install-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path
Run Code Online (Sandbox Code Playgroud)
当然,我可以从PowerShell控制台运行cmdlet.我也可以从PowerShell控制台运行被调用的脚本并且Install-WindowsFeature工作正常.那么,从运行cmdlet的脚本调用脚本是否有用呢?这是我的调用代码:
$script = "C:\Path\script.ps1"
$argumentList = @()
$argumentlist += ("-Arg1", "value")
$argumentlist += ("-Arg2", "value")
$argumentlist += ("-Arg3", "value")
Invoke-Expression "$script $argumentList"
Run Code Online (Sandbox Code Playgroud)
在被调用的脚本中,我调用Install-WindowsFeature如下:
if ($someValue) { Invoke-Command -ScriptBlock {Install-WindowsFeature -Name RSAT-AD-Tools} }
Run Code Online (Sandbox Code Playgroud)
我也尝试过如下:
if ($someValue) { Install-WindowsFeature …Run Code Online (Sandbox Code Playgroud) 更新:
好像其他人有同样的问题并报告了它.
从Azure自动化Runbook调用时,我遇到了一个简单的PowerShell脚本问题.在本地运行它时,同一段代码完美无瑕.
我已使用密码凭据在Azure Active Directory(托管在Azure德语云中)中添加了服务主体,并授予其参与者对订阅的访问权限(也在Azure德语云中托管).
Azure自动化服务托管在北欧,因为它目前在Azure德国云中不可用.
我尝试做的就是使用Add-AzureRmAccountcmdlet 使用上面提到的主体登录我的订阅.之后,我尝试使用Set-AzureRmContext并设置当前上下文并获取以下错误消息:
Set-AzureRmContext : Please provide a valid tenant or a valid subscription.
At line:26 char:1
+ Set-AzureRmContext -TenantId $TenantId -Su ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmContext], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
Run Code Online (Sandbox Code Playgroud)
这是我尝试运行的脚本(将配置留空):
$TenantId = ""
$ApplicationId = ""
$ClientSecret = ""
$SubscriptionId = ""
$secpasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force
$mycreds = New-Object …Run Code Online (Sandbox Code Playgroud) 我经常编写事物列表并对它们执行枚举以执行一些get/set.
我讨厌枚举哈希表,因为每当我必须这样做时,我必须向后弯曲以处理hashtable对象.
$hashtablelistofitems = @{}
$hashtablelistofitems.add("i'm a key", "i'm a value")
foreach ($item in $hashtablelistofitems.keys) {
$item
$hashtablelistofitems.item($item)
}
Run Code Online (Sandbox Code Playgroud)
相反,我通常会恢复使用具有两个noteproperties的自定义对象的单维数组.
$array = @()
$listofitems = "" | select key,value
$listofitems.key = "i'm a key"
$listofitems.value = "i'm a value"
$array += $listofitems
foreach ($item in $listofitems) {
$item.key
$item.value
}
Run Code Online (Sandbox Code Playgroud)
我为什么要使用hashtable这种方法呢?仅仅因为它只保证每个键的单个值?
我尝试在 Terraform 项目中使用 Azure/Azapi Provider,但在添加提供程序并运行之后terraform init,出现以下错误:
Error: Failed to query available provider packages\nCould not retrieve the list of available versions for provider hashicorp/azapi: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/azapi \nRun Code Online (Sandbox Code Playgroud)\n这就是我的providers.tf 的样子:
\nterraform {\n required_providers {\n azurerm = {\n source = "hashicorp/azurerm"\n version = "=3.16.0"\n }\n azapi = {\n source = "azure/azapi"\n version = "=0.4.0"\n }\n\n }\n\n required_version = "=1.2.6"\n}\n\nprovider "azurerm" {\n features {}\n}\n\nprovider "azapi" {\n}\nRun Code Online (Sandbox Code Playgroud)\n当我跑步时terraform providers,我可以看到提供程序在我的模块中有错误的注册表 …
powershell ×7
azure ×2
asp.net ×1
azure-mcd ×1
c# ×1
c++ ×1
hashtable ×1
iis ×1
jobs ×1
overloading ×1
static-cast ×1
terraform ×1