小编Bac*_*ave的帖子

从脚本中获取函数列表

如果我有一个具有以下功能的 .ps1 文件

function SomeFunction {}

function AnotherFunction {}
Run Code Online (Sandbox Code Playgroud)

如何获取所有这些函数的列表并调用它们?

我想做这样的事情:

$functionsFromFile = Get-ListOfFunctions -Path 'C:\someScript.ps1'
foreach($function in $functionsFromFile)
{
   $function.Run() #SomeFunction and AnotherFunction execute
}
Run Code Online (Sandbox Code Playgroud)

powershell

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

是否可以设置现有 Azure blob 的内容配置?

基于此处的 stimms 答案: Azure Storage API ContentDisposition

以及在此处找到的信息: 公开下载 Azure blob 时的友好文件名

我已经能够在上传新文件时设置内容配置。但我也希望能够设置现有文件的内容配置。

blob.Properties.ContentDisposition = string.Format("attachment;filename=\"{0}\"", friendlyName);
Run Code Online (Sandbox Code Playgroud)

在上传文件之前设置时工作正常,但如果我在现有 blob 上尝试它则无效。

更改现有 blob 的内容配置是完全不可能的,还是我做错了什么?

azure azure-storage azure-storage-blobs

3
推荐指数
1
解决办法
4580
查看次数

如何在未安装 Excel 的情况下使用 Powershell 将 .xls 转换为 .csv

有没有办法在不使用 Powershell 安装 Excel 的情况下将 .xls 转换为 .csv?

我无法在特定机器上访问 Excel,因此在尝试时出现错误:

New-Object -ComObject excel.application
Run Code Online (Sandbox Code Playgroud)

新对象:检索具有 CLSID {00000000-0000-0000-0000-000000000000} 的组件的 COM 类工厂由于以下错误而失败:80040154 类未注册(来自 HRESULT 的异常:0x80040154)。

excel powershell

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

无法使用System.IO.Compression.FileSystem.dll

我试图让这个Powershell代码工作:

     Add-Type -Path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll'
     $startPath = "D:\nade\CBA\Zip\StartPath"
     $zipPath = "D:\nade\CBA\Zip\result.zip"
     $extractPath = "D:\nade\CBA\Zip\Extract"
     [System.IO.Compression.FileSystem.ZipFile]::CreateFromDirectory($startPath, $zipPath)
     [System.IO.Compression.FileSystem.ZipFile]::ExtractToDirectory($zipPath, $extractPath)
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

Unable to find type [System.IO.Compression.FileSystem.ZipFile]. Make sure that the assembly that contains this type is loaded.
Run Code Online (Sandbox Code Playgroud)

我尝试使用此处的其他DLL:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.IO.Compression.FileSystem.dll
Run Code Online (Sandbox Code Playgroud)

但是我仍然得到同样的错误.

如何正确导入此库?

编辑:我已经尝试了以下所有,但没有一个工作:

[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
Add-Type -Path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.IO.Compression.FileSystem.dll'
Add-Type -Path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll'
Add-type -AssemblyName "System.IO.Compression.FileSystem"
Run Code Online (Sandbox Code Playgroud)

powershell zip

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

Restsharp.RestRequest.RemoveJsonBody()

我可以通过这样做添加到 JSON 正文:

_request.AddJsonBody(obj1);
_request.AddJsonBody(obj2);
Run Code Online (Sandbox Code Playgroud)

怎样才能清理尸体呢?没有任何RemoveJsonBody()方法或类似的东西。

c# rest web asp.net-web-api asp.net-web-api2

3
推荐指数
1
解决办法
2734
查看次数

String.Split() 的奇怪结果

为什么以下结果会产生一个包含 7 个元素和 5 个空白的数组?我希望只有 2 个元素。5个空白元素来自哪里?

$a = 'OU=RAH,OU=RAC'

$b = $a.Split('OU=')
$b.Count 
$b

<#

Outputs:

7



RAH,


RAC

#>
Run Code Online (Sandbox Code Playgroud)

powershell

3
推荐指数
1
解决办法
1232
查看次数

通过DirectoryEntry还是DirectorySearcher指定Active Directory域控制器?

我想使用以下方法搜索AD时可以指定域控制器:

$principalContext  = New-Object 'System.DirectoryServices.AccountManagement.PrincipalContext'([System.DirectoryServices.AccountManagement.ContextType]::Domain, $DomainControllerIpAddress, $Container)
Run Code Online (Sandbox Code Playgroud)

如何使用DirectoryEntry或指定域控制器DirectorySearcher

powershell active-directory domaincontroller directorysearcher

3
推荐指数
1
解决办法
2862
查看次数

使用默认的 ASP.NET Core DI 容器在 Service Fabric 上设置依赖注入

我想使用 ASP.NET Core 的默认 DI 容器来为我的 Service Fabric 项目设置 DI。

//This is what I've got so far, and it works great
ServiceRuntime.RegisterServiceAsync(
  "MyServiceType",
  context => new MyService(context, new MyMonitor()
).GetAwaiter().GetResult();

//This is how I use it
public MyService(StatefulServiceContext context, IMonitor myMonitor)
  : base(context)
{
  this._myMonitor = myMonitor;           
}
Run Code Online (Sandbox Code Playgroud)

如果MyMonitor类依赖于ConfigProvider类,我将如何设置 DI ,如下所示:

public MyMonitor(IConfigProvider configProvider)
{
  this._configProvider = configProvider;
}
Run Code Online (Sandbox Code Playgroud)

dependency-injection .net-core azure-service-fabric

3
推荐指数
1
解决办法
3147
查看次数

这些 Visual Studio 调试图标是什么意思?

我有一个带有一堆属性的类,该类没有继承或实现任何东西。

为什么这两个属性(在下面的红色方块中)与其他属性具有不同的图标?

图标代表什么? 在此处输入图片说明

这就是类的样子:

在此处输入图片说明

正如你所看到的,CompanyID并且CompanyName也是公共属性,但是EAP这是一个公共财产不具有相同的图标。

如果属性值不为空,则使用错误的图标,如果值为空,则使用正确的扳手图标。

在此处输入图片说明

我使用的是 VS Enterprise 2017,版本 15.9.15。

.net c# visual-studio visual-studio-debugging

3
推荐指数
1
解决办法
672
查看次数

Powershell使用Where-Object获取内容

我有这样一个文件:

line one email1
line two email1
line three email2
line four email1
Run Code Online (Sandbox Code Playgroud)

如果我只想提取包含"email1"的行,我这样做:

$text = Get-Content -Path $path | Where-Object { $_ -like *email1* }
Run Code Online (Sandbox Code Playgroud)

$ text现在是一个包含3行元素的数组,我按照这样迭代:

for ($i = 0; $i -lt $text.Length; $i++)
{
#do stuff here
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我想获取包含"email2"的行.

$text = Get-Content -Path $path | Where-Object { $_ -like *email2* }
Run Code Online (Sandbox Code Playgroud)

返回一个字符串,而不是一个元素的数组.当我遍历它时,它遍历字符串中的每个字符.

如何使用一个元素而不是字符串使其成为一个数组?

powershell

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