如果我有一个具有以下功能的 .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) 基于此处的 stimms 答案: Azure Storage API ContentDisposition
以及在此处找到的信息: 公开下载 Azure blob 时的友好文件名
我已经能够在上传新文件时设置内容配置。但我也希望能够设置现有文件的内容配置。
blob.Properties.ContentDisposition = string.Format("attachment;filename=\"{0}\"", friendlyName);
Run Code Online (Sandbox Code Playgroud)
在上传文件之前设置时工作正常,但如果我在现有 blob 上尝试它则无效。
更改现有 blob 的内容配置是完全不可能的,还是我做错了什么?
有没有办法在不使用 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)。
我试图让这个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) 我可以通过这样做添加到 JSON 正文:
_request.AddJsonBody(obj1);
_request.AddJsonBody(obj2);
Run Code Online (Sandbox Code Playgroud)
怎样才能清理尸体呢?没有任何RemoveJsonBody()方法或类似的东西。
为什么以下结果会产生一个包含 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) 我想使用以下方法搜索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
我想使用 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) 我有一个带有一堆属性的类,该类没有继承或实现任何东西。
为什么这两个属性(在下面的红色方块中)与其他属性具有不同的图标?
这就是类的样子:
正如你所看到的,CompanyID并且CompanyName也是公共属性,但是EAP这是一个公共财产不具有相同的图标。
如果属性值不为空,则使用错误的图标,如果值为空,则使用正确的扳手图标。
我使用的是 VS Enterprise 2017,版本 15.9.15。
我有这样一个文件:
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)
返回一个字符串,而不是一个元素的数组.当我遍历它时,它遍历字符串中的每个字符.
如何使用一个元素而不是字符串使其成为一个数组?