小编Mat*_*sen的帖子

和弦C#方法用&符分隔?

我正在阅读Polyphonic C#的介绍,第一页包含这个例子:

示例:简单缓冲区

这是Polyphonic C#类最简单有趣的例子:

public class Buffer {
    public String get() & public async put(String s) {
        return s;    
    } 
}
Run Code Online (Sandbox Code Playgroud)

我根本得不到它.方法和方法之间有
什么&关系?get()put()

c# polyphonic-c#

18
推荐指数
1
解决办法
392
查看次数

PowerShell 删除文件(如果存在)

你能帮我写一个 powershell 脚本吗?我想检查是否存在多个文件,如果存在则删除文件。如果文件已被删除,则提供信息;如果文件不存在,则提供信息。

我找到了下面的脚本,它只适用于 1 个文件,如果文件不存在,它不会给出消息。你能帮我调整一下吗?我想删除文件 c:\temp\1.txt、c:\temp\2.txt、c:\temp\3.txt(如果存在)。如果这些不存在,则会显示一条消息,表明它们不存在。如果文件不存在,Powershell 不应引发错误或停止。

$FileName = "C:\Test\1.txt"
if (Test-Path $FileName) {
   Remove-Item $FileName -verbose
}
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!汤姆

powershell

16
推荐指数
2
解决办法
2万
查看次数

如何在PowerShell中引用UWP类

我想使用通用Windows平台库中的数据类型,如何在PowerShell中引用包含的命名空间或程序集?

例如,我想使用Windows.Data.Json.JsonObject该类来解析一些json.

如果这是一个常规的.NET类,我会做类似的事情

Add-Type -AssemblyName Windows.Data.Json
$jsonObject = [Windows.Data.Json.JsonObject]::Parse('{data:["powershell","rocks"]}')
Run Code Online (Sandbox Code Playgroud)

但这种策略让我失望:

Add-Type : Cannot add type. The assembly 'Windows.Data.Json' could not be found.
At line:1 char:1
+ Add-Type -AssemblyName Windows.Data.Json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Windows.Data.Json:String) [Add-Type], Exception
    + FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
Run Code Online (Sandbox Code Playgroud)

现在,可能是我假设Windows.Data.Json命名空间的程序集是错误的Windows.Data.Json.dll,但API引用实际上似乎不包含对包含文件的任何引用,这让我相信dll文件实际上不是我的应该寻找.

我假设UWP有自己很酷的GAC类商店,我可以从中加载共享库,我只是不知道如何.

所以基本上我的问题是,如何将UWP共享库加载到PowerShell中,我应该如何引用UWP类型的文字?

在Windows 10上运行PowerShell 5.1(内部版本1703)

.net windows powershell uwp

9
推荐指数
1
解决办法
934
查看次数

PowerShell尝试/捕获并重试

我有一个相当大的PowerShell脚本,有许多(20+)个函数执行各种操作.

现在所有的代码都没有任何错误处理或重试功能.如果某个特定的任务/功能失败,它就会失败并继续.

我想改进错误处理并实现重试以使其更加健壮.

我在想类似的东西:

$tries = 0
while ($tries -lt 5) {
    try{    

       # Do Something

       # No retries necessary
       $tries = 5;
    } catch {
       # Report the error
       # Other error handling
    }
 }
Run Code Online (Sandbox Code Playgroud)

问题是我需要做很多步骤才能做到这一点.

我认为实施上述代码20次是没有意义的.这似乎真的是多余的.

我在考虑编写一个带有单个参数的"TryCatch"函数,该参数包含我想要调用的实际函数?

不过,我不确定这是正确的方法.我不会最终得到一个类似于以下内容的脚本:

TryCatch "Function1 Parameter1 Parameter2"
TryCatch "Function2 Parameter1 Parameter2"
TryCatch "Function3 Parameter1 Parameter2"
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

error-handling powershell try-catch

9
推荐指数
3
解决办法
9536
查看次数

SPF请有人向我解释这意味着什么:v = spf1 a mx~all

在我的TXT记录中,我对此感到困惑.有人可以向我解释它的含义:

v=spf1 a mx ~all
Run Code Online (Sandbox Code Playgroud)

spf

8
推荐指数
1
解决办法
6651
查看次数

在 PowerShell 中通过“证书模板名称”识别证书

我需要使用 PowerShell 脚本来选择“证书模板名称”作为“机器”的证书。在 certmgr.msc 中,它具有值为“计算机”的“证书模板”。在详细信息中,相同的“证书模板名称”为“机器”。

如何在 PowerShell 脚本中使用这些值中的任何一个?

到目前为止,我有:

get-childitem cert:\localmachine\my | where-object {$_.}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了智能感知加载的几乎所有方法,但无法找到满足我需求的任何方法。

谢谢你,

powershell certificate

7
推荐指数
2
解决办法
2万
查看次数

ngserve --open 无法从 Powershell 和 VS 终端(Powershell)工作

当我遇到这个问题时,那时我已经尝试从 Pwershell 触发此命令,无论是管理员还是非管理员

得到这个错误:

''' ng :无法加载文件 C:\Users\vishi\AppData\Roaming\npm\ng.ps1,因为在此系统上禁用运行脚本。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkID=135170 上的 about_Execution_Policies。行:1 字符:1

  • ng 服务 --open
    • 类别信息:安全错误:(:) []、PSSecurityException
    • FullQualifiedErrorId:未经授权的访问“”

然后我尝试从 CMD 运行,因为此问题是由于 Powershell 上应用的安全策略造成的,然后 CMD 显示此错误:

'''新命令需要在项目外部运行,但在 C:\Users\vishi\ImprovApp\angular.json 中找到了项目定义”。'''

我的问题是,如果我们不是管理组的一部分,那么我们无法更改 PS 安全策略,那么还有其他方法可以运行 nodejs Ng 或 npm 命令吗???

windows powershell visual-studio angular-cli

7
推荐指数
1
解决办法
4780
查看次数

Powershell wget协议违规

我正在尝试使用wget/invoke-webrequest在嵌入式Web服务器上浏览命令.如何避免这种错误?

wget:服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF

已经尝试过多种方法,例如下面没有成功:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Run Code Online (Sandbox Code Playgroud)

当使用BITS时,这就是我得到的错误

start-bitstransfer:服务器没有返回文件大小.URL可能指向动态内容.Content-Length标头在服务器的HTTP回复中不可用.

非常感谢你的帮助克莱姆

powershell wget

6
推荐指数
1
解决办法
3668
查看次数

使用 powershell 正确格式化 JSON

我有一个 JSON 格式的以下文件:

之前ConvertTo-JSON

[
    {
        "Yura": {
            "Cashier": {
                "branch": "release/Retail-v4.0",
                "configuration": "RetailDemo Debug",
                "datetime_deployed": "Apr 18 2018 07:45:05",
                "deployed_by": "anonymous",
                "host": "cashier2-retail4.testing.aws.com",
                "job": "http://jenkins-testing.aws.com:8080/job/CashierDeployment",
                "lineserver": "",
                "messagebus": "",
                "product": "Cashier",
                "publish_profile": "cashier2.retail.dev.pubxml"
            },
            "ContentManager": {
                "branch": "release/Retail-v3.31.1",
                "configuration": "RetailDemo Debug",
                "datetime_deployed": "Jan 17 2018 11:59:24",
                "deployed_by": "anonymous",
                "host": "contentmanager2-retail3.testing.aws.com",
                "job": "http://jenkins-testing.aws.com:8080/job/ContentManagerDeployment",
                "lineserver": "",
                "messagebus": "",
                "product": "ContentManager",
                "publish_profile": "..\\ContentManager.PublishProfiles\\contentmanager2.retail5.dev.pubxml"
            }
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

使用此代码操作数据后:

$json = Get-Content 'D:\script\test.json'  -encoding utf8 | ConvertFrom-Json
$json.yura.ContentManager.branch = 'test'
Run Code Online (Sandbox Code Playgroud)

我将 …

powershell formatting json

6
推荐指数
4
解决办法
1万
查看次数

PowerShell Hashtable show first key

I am playing around with hashtables in powershell and try to figure out, if there is a way, to show the content of Key1 (not the value).

I tried several ways to have as an result "Monday" but either I get all the names of the table, a blank return or an error message.

here's my table:

$Weekdays = @{Monday = 'Montag';Tuesday = 'Dienstag'}
Run Code Online (Sandbox Code Playgroud)

If possible, I would like to have as an output only "Monday", is there a …

powershell hashtable

6
推荐指数
1
解决办法
2881
查看次数