从Windows Powershell发送HTTP请求的最佳方法是什么?
我正在尝试读取事件日志以获取除两个用户之外的所有用户的安全审核,但是可以通过-notlike运营商执行此操作吗?
它是这样的:
Get-EventLog -LogName Security | where {$_.UserName -notlike @("*user1","*user2")}
Run Code Online (Sandbox Code Playgroud)
我让它适用于单个用户,例如:
Get-EventLog -LogName Security | where {$_.UserName -notlike "*user1"}
Run Code Online (Sandbox Code Playgroud) 前段时间我正在阅读PowerShell中的多变量赋值.这可以让你做这样的事情
64 > $a,$b,$c,$d = "A four word string".split()
65 > $a
A
66 > $b
four
Run Code Online (Sandbox Code Playgroud)
或者您可以在单个语句中交换变量
$a,$b = $b,$a
Run Code Online (Sandbox Code Playgroud)
你认为你所知道的那些鲜为人知的PowerShell小块可能并不像它们应该的那样众所周知?
我有一个测试PowerShell V2脚本,如下所示:
function test_args()
{
Write-Host "here's arg 0: $args[0]"
Write-Host "here's arg 1: $args[1]"
}
test_args
Run Code Online (Sandbox Code Playgroud)
如果我从powershell命令提示符调用它,我会在屏幕上显示:
here's arg[0]: [0]
here's arg[1]: [1]
Run Code Online (Sandbox Code Playgroud)
不是我想要的.在我可以使用之前,似乎我必须将$ args [0]和$ args [1]复制到脚本中的新变量中?如果我这样做,我可以很好地访问.
有没有办法在我的代码中访问索引的$ args?我尝试过以各种方式使用花括号,但没有运气.
我最终将转向命名参数,但我正在处理的脚本(不是这个演示版)是批处理文件的直接端口.
PowerShell 5引入了New-TemporaryFilecmdlet,非常方便.我怎样才能做同样的事情而不是文件创建目录?有New-TemporaryDirectorycmdlet吗?
我在 Windows 上安装 Node.js。安装成功,我还在node.js安装程序中选择了安装必要文件(例如chocolatey)的选项。Node安装完成后,打开Powershell;安装一段时间后,出现以下错误:
# A lot of logs before, just an excerpt
Microsoft.VisualStudio.Workload.VCTools Microsoft.VisualStudio.Component.Roslyn.Compiler Microsoft.Component.MSBuild Microsoft.VisualStudio.Component.CoreBuildTools Microsoft.VisualStudio.Component.Windows10SDK Microsoft.VisualStudio.Component.VC.CoreBuildTools Microsoft.VisualStudio.Component.Static.Analysis.Tools Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.Redist.14.Latest Microsoft.VisualStudio.Component.Windows10SDK.17763 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.TestTools.BuildTools
[5330:000f][2021-04-19T18:24:09] Decorating UnelevatedProductModifier with UnelevatedInstallerTelemetryDecorator
[5330:000f][2021-04-19T18:24:09] Created a UnelevatedInstallerTelemetryDecorator
[5330:000e][2021-04-19T18:24:09] Download requested: https://aka.ms/vs/15/release/channel
[5330:001d][2021-04-19T18:24:09] Attempting download 'https://aka.ms/vs/15/release/channel' using engine 'WebClient'
[5330:001d][2021-04-19T18:24:09] WebClient error 'RequestCanceled' with 'https://aka.ms/vs/15/release/channel' - GetWebResponse failed along with a cancellation request
[5330:001d][2021-04-19T18:24:09] Error 0x8013153b: [5330:001d][2021-04-19T18:24:09] Could not update channel "https://aka.ms/vs/15/release/channel"
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Threading.CancellationToken.ThrowIfCancellationRequested()
at Microsoft.VisualStudio.Setup.Download.WebClientEngine.GetWebResponse(Uri uri, DownloadContext downloadContext, DownloadSummary& downloadSummary, HttpWebRequest& …Run Code Online (Sandbox Code Playgroud) 作为我开发的一部分,我希望能够针对单个XSD文件验证整个文件夹的XML文件.PowerShell函数似乎是一个很好的候选者,因为我可以像这样管道一个文件列表:dir*.xml | Validate-Xml -Schema.\ MySchema.xsd
我已经考虑过在C#问题中从参考XSD验证一个Xml中移植C#代码,但我不知道如何在PowerShell中添加处理程序.
我在参数中遇到空格问题,我尝试从powershell脚本发送到msdeploy.
还有许多其他相关文章,但没有一个解决问题.
使用Power Shell和MSDeploy的问题.
类似的SO问题不起作用:如何在带有空格和引号的参数的
PowerShell中运行exe PowerShell BUG:执行需要引号和变量的命令实际上是不可能的
另一个SO问题不起作用:在PowerShell 2.0中传递参数
当我使其变得更复杂时,成功然后失败的最简单的例子就是转储默认网站.
$ msdeploy ="C:\ Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"
&$ msdeploy -verb:dump -source:appHostConfig =`'default web site`'-verbose
== SUCCESS
这个?
$ sitename ="默认网站"
&$ msdeploy -verb:dump -source:appHostConfig = $ sitename -verbose
== FAIL,出现以下错误
msdeploy.exe:错误:无法识别的参数'" - source:"appHostConfig = default'.所有参数必须以" - "开头.
在C:\ xxx\test.ps1:122 char:6
+&
+ CategoryInfo:NotSpecified :(错误:Unrecogn ...以" - "开头:String)[],RemoteException
+ FullyQualifiedErrorId:NativeCommandError
错误计数:1.
以下变化也失败了
#FAIL
$ sitename =`'默认网站''
$ sitename =`'"默认网站"`'
$ sitename ="`''默认网站`'"
$ sitename ="默认网站"
$ …
似乎没有人问这个简单的问题,所以我会.
我的PowerShell脚本文件位于: C:/this-folder/that-folder/another-folder/powershell-file.ps1
如何获得返回的变量: C:/this-folder/that-folder/another-folder/
我开始使用PowerShell用于使用node.js的Windows项目.从Powershell命令行运行许多程序(包括node,supervisor和npm)时,我的PowerShell背景和前景颜色开始从默认的Powershell颜色更改.如何在PowerShell中保持一致的外观,以便我可以轻松读取运行命令的结果?
powershell ×10
node.js ×2
args ×1
colors ×1
http ×1
iis ×1
installation ×1
msbuild ×1
msdeploy ×1
networking ×1
xml ×1
xsd ×1