我希望开始在我正在从事的项目中实现一些并发功能。我最近发现了System.Collections.Concurrent我计划利用的命名空间。
我用来跟踪操作整体状态的对象本质上是一个带有一些嵌套自定义对象的字典。我的想法是,只要将最高级别的集合配置为并发/线程安全,嵌套集合是否是并发/线程安全并不重要,因为数据将被更高级别的集合锁定。
这是正确的假设吗?
例如,像下面这样的 PowerShell 中的某些内容可以安全使用吗?
[System.Collections.Concurrent.ConcurrentDictionary[[String], [MyCustomClass]]]::new()
Run Code Online (Sandbox Code Playgroud)
此外,我有一些扩展 HashSet 的自定义类以避免重复。由于 System.Collections. Concurrent 没有 HashSet 类,获得类似功能但并发的推荐方法是什么?
非常简单的设置,请在家尝试一下。
$args
Run Code Online (Sandbox Code Playgroud)
$args
Run Code Online (Sandbox Code Playgroud)
@echo off
ruby test.rb "foo bar moo"
powershell .\test.ps1 "foo bar moo"
pause
Run Code Online (Sandbox Code Playgroud)
运行测试.bat。猜猜输出。
如果你像我一样想那你就错了。
["foo bar moo"]
foo
bar
moo
Run Code Online (Sandbox Code Playgroud)
Ruby 见证了这三个单词作为单个参数传递。PowerShell 以比尔·盖茨的名义在做什么?我怎样才能让它按逻辑工作?
或者我错过了什么?
我在同一目录中有两个文件我希望比较哈希值,Release.zip和release821hash.txt
\n我必须使用的第一个命令是 get-filehash Release.zip -a md5\n我必须使用的第二个命令是get-content release821hash.txt
然后,我必须使用 -eq 来比较哈希值,按照实验室要求定义:
\n1. Type "new hash" -eq "known hash" and press Enter to determine whether the\nfile hashes match.\n\xe2\x96\xa0 The new hash is the hash generated by the get-filehash file_name -a\nmd5 command.\n\xe2\x96\xa0 The known hash is the hash generated by the get-content\nfile_name.txt command.\n\xe2\x96\xa0 Include the quotation marks and the file extensions with the file names\nin the commands.\nRun Code Online (Sandbox Code Playgroud)\n但是我的 powershell 抛出错误。我尝试使用所有可能的方法来使用 -eq 进行比较,但它不断抛出错误。我究竟做错了什么?我尝试过不使用引号,只在“get”命令周围使用引号,并对整行使用一个引号。
\n\n我正在运行以下 cmdlet,我需要在脚本中使用它。
Connect-Pfa2Array -Endpoint 10.10.10.10 -Username pureapiuser -Password $psw -IgnoreCertificateError
Run Code Online (Sandbox Code Playgroud)
我得到了以下我试图抑制的输出。我只需要 cmdlet 即可建立连接。有办法做到这一点吗?我检查了 cmdlet,没有看到执行静默连接的选项。
ArrayName ApiVersion
--------- ----------
10.100.24.50 2.2
Run Code Online (Sandbox Code Playgroud) 我在 Windows Powershell 中看到以下奇怪的行为。
脚本1:
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipArchiveMode]::Update
Run Code Online (Sandbox Code Playgroud)
输出:
PS C:\Users\Administrator> C:\Users\Administrator\Documents\Untitled1.ps1
Unable to find type [System.IO.Compression.ZipArchiveMode].
At C:\Users\Administrator\Documents\Untitled1.ps1:3 char:1
+ [System.IO.Compression.ZipArchiveMode]::Update
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.IO.Compression.ZipArchiveMode:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Run Code Online (Sandbox Code Playgroud)
脚本2:
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::Open
[System.IO.Compression.ZipArchiveMode]::Update
Run Code Online (Sandbox Code Playgroud)
输出:
PS C:\Users\Administrator> C:\Users\Administrator\Documents\Untitled1.ps1
OverloadDefinitions
-------------------
static System.IO.Compression.ZipArchive Open(string archiveFileName, System.IO.Compression.ZipArchiveMode mode)
static System.IO.Compression.ZipArchive Open(string archiveFileName, System.IO.Compression.ZipArchiveMode mode, System.Text.Encoding entryNameEncoding)
Update
Run Code Online (Sandbox Code Playgroud)
为什么 Script1 无法加载[System.IO.Compression.ZipArchiveMode]::Update?如何修复 Script1 以确保[System.IO.Compression.ZipArchiveMode]::Update正确加载?
我在 Excel 中使用 vlookup 时遇到一些问题。\n我已经看到了该问题,但还没有找到解决方案。
\n我的 txt 文件中有大量行,这些行包含 Unicode 字符。
\n示例:\n此行: 'S0841488.JPG06082014\xe2\x80\x8f\xe2\x80\x8e08.21'\n包含这两个 unicode 字符: U+200F U+200E\n'S0841488.JPG06082014 U+200F U+200E 08.21。
\n请告诉我如何使用 Powershell 删除这些 unicode 字符。
\n我通过适用于 Windows 的 AWS 的 msi 安装程序安装了 AWS SAM。运行安装程序后,我sam --version在cmd和powershell中运行。
PS C:\Users\dgupta> sam --version
SAM CLI, version 1.26.0
Run Code Online (Sandbox Code Playgroud)
它返回我刚刚安装的版本。然而,在 VS Code 中,我打开了一个终端并运行sam --version它,结果出现错误。
PS C:\Users\dgupta> sam --version
SAM CLI, version 1.26.0
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?VS Code 终端和普通终端不能访问相同的环境变量吗?
windows powershell path-variables visual-studio-code aws-sam-cli
我正在构建一个脚本,该脚本将访问大量文件并拉出特定字符串以便分配为变量。
所有文件中的字符串都是相似的,这不是问题。我能够使这个过程作为一个单独的事件运行(定义一个源文件)
$hostname_import = select-string .\test.txt -Pattern 'hostname ABC-.+'
$hostname = $hostname_import -replace '.+ ',''
Run Code Online (Sandbox Code Playgroud)
上面将输出目标文件中标识的特定主机名(第二个功能是修剪单词主机名和空格),然后我可以使用它继续根据需要使用变量来执行各种操作。
我遇到的问题是在 foreach 循环中执行此函数,以便我可以获取初始文件 - 执行选择字符串函数(或类似函数),然后按预期在循环内执行数据修改。
对于上下文 - 我正在查看配置文件 - 并根据这些配置构建一个单独的文件来报告结果 - 报告构建的一部分需要设备的主机名。
--编辑 1: 在咨询了我的橡皮鸭之后,我将尝试将这些文件作为 CSV 导入,以便可能找到解决方案。
巨大的帮助!
对于文件关联.py和.pl,我有一对ftype和 ,assoc这样我就可以运行 Perl 和 Python 脚本,而无需显式指定其各自解释器可执行文件的路径,如下所示:
C:\users\rene> .\abc.pl
C:\users\rene> .\xyz.py
Run Code Online (Sandbox Code Playgroud)
当我在 PowerShell 控制台中执行“相同”操作时,执行 Perl 脚本会打开另一个控制台并在其中执行,但 Python 脚本会在同一个控制台中执行。
因为 Perl 脚本在另一个控制台中运行,所以我面临两个问题:1)我无法重定向脚本的 STDOUT,2)脚本完成后控制台关闭,因此我看不到它的输出。
我不知道为什么 Python 脚本的行为与 Perl 脚本不同,我想知道需要进行哪些更改才能使 Perl 脚本在 PowerShell 中执行时在同一控制台中运行。
我是一名 Node 开发人员,希望将除了大的“node_modules”目录之外的所有工作保存在 Dropbox 中。我在https://help.dropbox.com/files-folders/restore-delete/ignored-files中发现了一个 Powershell 代码,它有选择地忽略 Dropbox 中存在的文件夹:
Set-Content -Path 'C:\Users\yourname\Dropbox(Personal)\YourFileName.pdf' -Stream com.dropbox.ignored -Value 1
Run Code Online (Sandbox Code Playgroud)
我想创建一个 Powershell 脚本来帮助我找到 Dropbox 下的所有“node_modules”目录,然后忽略它们。我真的需要你的帮助,因为我真的不太了解 Powershell。
在互联网上搜索时,我编写了这个小代码片段,以递归方式查找 Dropbox 文件夹内的所有“node_modules”目录。
$BaseDir = "C:\Users\giann\Dropbox\IdeaProjects"
$NameToFind = "node_modules"
$MyVariable = Get-ChildItem $BaseDir -Recurse | Where-Object { $_.PSIsContainer -and $_.Name.EndsWith($NameToFind)}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何组合这两个代码片段?你能指出我正确的方向吗?
谢谢,非常感谢您的支持。
powershell ×10
windows ×3
.net ×1
aws-sam-cli ×1
cmd ×1
collections ×1
concurrency ×1
console ×1
dropbox ×1
loops ×1
unicode ×1
zip ×1