问题标签 [powershell-4.0]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
powershell - PowerShell: What exactly is $input inside Start-Job?
Consider the following code. I am simply passing in an array of 32-bit, signed integers [Int32[]]
into the Start-Job
cmdlet, by using the -InputObject
parameter.
The result of this code is:
Looking at the documentation for the PipelineReader .NET class, it has a ReadToEnd()
method. Therefore, the following code ought to work:
But instead, I get an error message:
Method invocation failed because [System.Int32] does not contain a method named 'ReadToEnd'. + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound + PSComputerName : localhost
So then I think, I'll just use the PSBase
property to get the "real" object.
But then I get a similar error message:
Method invocation failed because [System.Management.Automation.PSInternalMemberSet] does not contain a method named 'ReadToEnd'. + CategoryInfo : InvalidOperation: (ReadToEnd:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound + PSComputerName : localhost
I noticed that there is a Microsoft Connect bug filed around this confusion, but it confuses me even more. Apparently the PipelineReader
class has a confusingly-named property <>4__this
, which has a Read()
method, which you can't actually see by using Get-Member
.
Bottom line: Does anyone know how to simply "unwrap" the contents of the $input
automatic variable, when input is submitted via the -InputObject
parameter on the Start-Job
cmdlet, so that I can work with the objects on an individual basis?
This script should simply return 1
, not 1, 2, 3
.
nat - 使用 Powershell 将 Windows 设置为路由器
我正在运行一个连接到 VPN 的虚拟 Windows 2012 R2 服务器。为了与其他客户端共享对该 VPN 的访问,我使用“Rouing 和 RAS”设置了服务器。我使用带有 VPN NIC 的 NAT 选项作为公共接口。这个设置很好用。
出于维护原因,我希望能够使用 Powershell 配置完全相同的设置。所以我摆弄了这些Network Address Translation (NAT) Cmdlet。但我无法让它工作。这些 Cmdlet 没有太多选择 - 所以我已经被困住了。有谁知道一个工作教程,或者有一个工作设置?
提前致谢。
sql-server-2012 - PowerShell 4 安装后 Invoke-Sqlcmd 不起作用
我在周末安装了 PowerShell 4,从那时起,当我尝试运行 Invoke-Sqlcmd commandlet 时,我收到错误“‘Invoke-Sqlcmd’一词未被识别为 cmdlet、函数的名称”。
在 PowerShell 4 之前,这几个月来一直运行良好。
我安装了 CU7 的 SQL 2012 SP1。VS 2013 与 .NET 4.5.1。据我所知,我拥有 PowerShell 所需的所有最新功能。
我怎样才能解决这个问题?
Invoke-Sqlcmd :术语“Invoke-Sqlcmd”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在行:1 字符:1
powershell - 如何让 PowerShell 4 cmdlet(例如 Test-NetConnection)在 Windows 7 上运行?
情况。在 Windows 7 SP1 机器上,我使用 Windows6.1-KB2819745-x64-MultiPkg.msu 进行了更新。此外,在 PowerShell $PSVersionTable 现在报告“PSVersion 4.0”。
目前,我的结论是,许多 PowerShell 4 cmdlet,例如 Test-NetConnection,只能在 Windows 8.1 上运行。但是,我想知道是否有一种解决方法可以在我的 Windows 7 机器上导入 PowerShell 4 模块。
powershell - Powershell 中线程的详细信息
如何以类似于此的格式获取通过 powershell 在进程中运行的所有线程的 CPU 消耗
运行时找不到任何处理器信息gwmi win32_thread|select -First 1
。而且Start Address
是数字!?!
powershell - 在哪里放置 out-file cmdlet ?
我过去正在做一个小脚本,它在特定位置搜索大文件。现在我想用我的结果创建一个 .txt 文件。但不幸的是,我没有设法正确放置 cmdlet。我超越了其他事情,但是在这里我遇到了一些麻烦。
我尝试过 tee 对象并输出变量,我尝试将输出文件放在最后,并尝试在格式化大小之前放置它。
只有当我将它放在格式化之前它才有效。但我很想在我的 .txt 中有格式化的大小,在其他地方它只是创建了一个空白的 .txt 文件。
powershell - 如何在powershell中迭代“对于每个具有值的对象”
我正在使用 gwmi 在系统上返回许多不同的信息。我使用以下命令获取网络信息:
它返回一组网络适配器和有关它们的信息。由于有许多我不感兴趣的网络适配器,我如何过滤掉“坏”的?我想我只需要获得具有 IPv4 地址的那些,但我该如何指定呢?
我是否必须使用嵌套在 for 循环中的 if,还是有更快的方法?
伪代码:
powershell - 对使用 test-path cmdlet 的 Powershell 变量 $null 的功能感到好奇
我正在构建一个使用 test-path cmdlet 的脚本,如果该路径存在,我想删除一个不同的路径。
这很有效,但即使我很想了解变量 $null 是如何工作的。
这是一个片段:
如果我有“$sourcezip”,它现在会删除文件夹“$destzip*”的内容
但在知道它是如何工作的之前,我一直在寻找类似的东西:
if (Test-Path -path "$sourcezip") -eq $true
没有成功,这就是为什么我很好奇这个 $null 变量是如何工作的。
powershell - 刷新 PowerShell DSC 资源
我正在调试 v4.0 附带的 PowerShell DSC 资源。更具体地说,我正在通过添加诊断日志来测试 MSFT_ProcessResource。在我对资源进行更改并运行我的配置以使用该资源后,我看不到我刚刚添加的日志记录。最终,几分钟后,PowerShell 似乎刷新了它拥有的任何资源缓存。我试过 Get-DscResource 和 Import-Module MSFT_ProcessResource
这些都没有奏效。
有没有办法强制重新加载资源?
powershell - 安装 v4 后,你能模仿 PowerShell v3 吗?
我想模拟 PowerShell 3.0
在 PowerShell v3 或 v4 中,您可以使用以下命令模拟 v2:
$Host 透露:版本:2.0
但是,在 PowerShell 4
$Host 现在报告:版本:4.0(我希望是 3:0)
问题:有什么方法可以从 4.0 模拟 PowerShell 3.0?