问题标签 [powershell-3.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.

0 投票
2 回答
24551 浏览

powershell - 导出到excel的脚本

我有以下脚本:--寻求将输出转换为 excel 格式的帮助

当执行以下格式的输出时。

我的要求是我想将此输出转换为 excel 格式以提交给管理层。下面是我想...从上面的脚本中获得的 excel 格式...

在此处输入图像描述

0 投票
1 回答
10933 浏览

powershell - PowerShell v3 中的 Get-ChildItem 出现 PathTooLong 错误,但不是 v2

Windows Server 2008 R2 VM 上,我将 PowerShell 升级到 v3,希望利用Get-ChildItem (gci) 性能改进。此行在 v2 中运行没有错误:

升级到v3后,为什么同一行会出现这个错误?$dir值不变。

gci : 指定的路径、文件名或两者都太长。完全限定的文件名必须少于 260 个字符,目录名必须少于 248 个字符。在 line:1 char:11 + $search = gci $dir -recurse -exclude "*.mdf" | 其中 {$_.length -gt 100mb} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\server.domain...DETAILS 1.0.prt:String) [Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

应用 Windows 更新并重新启动后没有任何变化。我在升级 PowerShell 之前拍摄了 VM 的快照,因此我可以轻松地来回切换。

$errorActionPreferenceContinuev2 和 v3 中。

$search.count在 v2 和 v3 中都是 8,所以我不太担心丢失的东西,但想了解行为的变化。

我尝试-force在 v2 中添加,看到类似的 PathTooLong 错误,.count为 10。在添加-forcev3 后,.count为 9。然后我恢复到 v2,再次找到 10 个带有-force. 尽管如此,更改数据$dir可能会解释.count差异,但在我们的环境中,更改数据并不能实际解释 v3 中 PathTooLong 错误的一致存在,而 v2 则不然。既然我的好奇心已经战胜了我,我希望有人能对这个谜团有所了解,并让我免于错误处理,我承认,这可能会提供更多线索。

FWIW,TechNet 上的使用文档说它适用于 v2 和 v3。该-Force参数的默认值为 False。

关于 PowerShell 和MAX_PATHv1 的一些背景知识。

Windows Server 2008 R2 VM 上,我将 PowerShell 升级到 v3,希望利用Get-ChildItem (gci) 性能改进。此行在 v2 中运行没有错误:

升级到v3后,为什么同一行会出现这个错误?$dir值不变。

gci : 指定的路径、文件名或两者都太长。完全限定的文件名必须少于 260 个字符,目录名必须少于 248 个字符。在 line:1 char:11 + $search = gci $dir -recurse -exclude "*.mdf" | 其中 {$_.length -gt 100mb} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\server.domain...DETAILS 1.0.prt:String) [Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

应用 Windows 更新并重新启动后没有任何变化。我在升级 PowerShell 之前拍摄了 VM 的快照,因此我可以轻松地来回切换。

$errorActionPreferenceContinuev2 和 v3 中。

$search.count在 v2 和 v3 中都是 8,所以我不太担心丢失的东西,但想了解行为的变化。

我尝试-force在 v2 中添加,看到类似的 PathTooLong 错误,.count为 10。在添加-forcev3 后,.count为 9。然后我恢复到 v2,再次找到 10 个带有-force. 尽管如此,更改数据$dir可能会解释.count差异,但在我们的环境中,更改数据并不能实际解释 v3 中 PathTooLong 错误的一致存在,而 v2 则不然。既然我的好奇心已经战胜了我,我希望有人能对这个谜团有所了解,并让我免于错误处理,我承认,这可能会提供更多线索。

FWIW,TechNet 上的使用文档说它适用于 v2 和 v3。该-Force参数的默认值为 False。

关于 PowerShell 和MAX_PATHv1 的一些背景知识。

0 投票
1 回答
674 浏览

powershell - 升级到 PS3,System.Net.WebClient 无法在某些机器上运行

我在实验室环境中运行,需要自动化大约 50 台机器。我正在尝试从服务器恢复 .xml 无线网络配置文件,然后安装它。此命令从 1 个服务器发送到 50 个客户端。

我最近重新映像了我的一些客户端并从 PS2 升级到 PS3,现在我的下载脚本不再工作了。

它在我的 PS2 工作站上运行良好。我假设这可能是一个许可的事情,但我不确定。ThrustedHosts 设置为 *,脚本执行策略设置为 Unrestricted。

这是一个片段和错误:

#

和错误:

使用“2”参数调用“DownloadFile”的异常:“WebClient 请求期间发生异常。” + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException + PSComputerName : 192.168.2.110

0 投票
1 回答
972 浏览

powershell - Powershell v3 中的 Export-csv - 输出不同于 PS v2

这是一个奇怪的问题。每当我尝试使用 export-csv 将某些内容导出到 csv 时,.csv 中的唯一数据就是长度属性。这是为什么?例如:

现在输出将如下所示:

是什么赋予了?也许这只是我,但我似乎无法在谷歌机器上找到关于这个 cmdlet 的非常好的信息。按照 Microsoft 的传统,get-help 文件没有多大帮助。

你们能给我的任何建议将不胜感激。

0 投票
2 回答
2291 浏览

powershell - 奇怪的 PowerShell Exec 输出捕获行为

我正在编写一个简单的 PowerShell 脚本来处理 mkvinfo 的输出。它捕获 mkvinfo 的输出,存储在变量 $s 中并对 $s 进行一些后处理。奇怪的是,虽然 $s 有内容,但我无法从中提取子字符串。

我收到的错误消息是:

使用“1”参数调用“子字符串”的异常:“startIndex 不能大于字符串的长度。参数名称:startIndex”

这是一个示例代码:

0 投票
1 回答
81 浏览

powershell - 模块范围的变量在没有显式赋值的情况下被更改

我对我遇到的一些可变范围行为感到很困惑。采取以下示例模块:

现在导入该模块正在运行getvar生成:

getvar 的进一步运行继续向 $xmlTemplate 添加越来越多的子元素,而 $intTemplate 保持不变。我不明白为什么 $myXml 并不总是从简单的测试/元素结构开始,更重要的是,脚本本地 $xmlTemplate 变量似乎正在发生变化,而 intTemplate 却没有。

任何有关弄清楚这里发生了什么的帮助将不胜感激。

大卫

0 投票
0 回答
991 浏览

powershell-remoting - 是否可以从远程主机使用 SSH 运行 powershell?

是否可以使用“ssh”或远程主机(Linux)的任何协议运行powershell脚本?

遵循以下步骤:

  1. 安装运行 ssh/telnet 服务的“freeSHd”。
  2. 能够通过 SSH 连接 Windows 2008R2 主机。
  3. 能够运行(powershell.exe)并进入powershell环境。
  4. 在运行 powershell 脚本之前,将执行策略设置为“受限”(Set-ExecutionPolicy Unrestricted)。
  5. 运行脚本和“C:\Scripts\setUp.ps1”
  6. 收到以下错误:

术语“Add-ADFSRelyingPartyTrust”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。t C:\Scripts\setUp.ps1:1 char:26 + Add-ADFSRelyingPartyTrust <<<< -Name 'RP' -MetadataURL 'https://rphost:443/fed/sp/metadata'; + CategoryInfo : ObjectNotFound: (Add-ADFSRelyingPartyTrust:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

也尝试像这样运行并导致相同的错误: C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy ByPass -command ".'C:\Scripts\setUp.ps1'"

请让我知道如何解决这个问题。

谢谢 GKS

0 投票
2 回答
2241 浏览

powershell - PowerShell 3 脚本会在 Windows 7 上运行吗?

包含 PowerShell 3 cmdlet 的 PowerShell 3 脚本能否在 Windows 7 Professional 或 Enterprise 的 vanilla 安装上运行?如果不是,需要的最低先决条件是什么?

(对不起,Powershell新手)

0 投票
2 回答
6718 浏览

.net-4.0 - 使用 CurrentDomain.SetData("APP_CONFIG_FILE") 在 PowerShell ISE 中不起作用

我正在尝试在 PowerShell ISE 中使用 .NET 4.0 程序集,并尝试更改通过以下方式使用的配置文件:

[Configuration.ConfigurationManager]::ConnectionStrings.Count 总是返回“1”,
而“[Configuration.ConfigurationManager]::ConnectionStrings[0].Name”总是返回“LocalSqlServer”,并且那个 ConnectionString 名称不在我的“.config”中文件。

请注意,从 PowerShell 命令提示符执行 PowerShell 脚本会按预期运行。只是当我从 PowerShell ISE 中执行它时,它没有按预期工作。

0 投票
2 回答
5691 浏览

powershell - Powershell Copy-item not working for unc paths

I am trying to sync two directories over the network between servers using UNC paths. The files are 20+ GB. I wrote a Powershell script to compare two directories and then copy any files missing from one to the other. However this doesn't appear to work. Once the script is run it finds the files properly but when it tries to copy them it appears that the files are instantly copied (which is impossible). Even though the files take up 20+ GB of space on the hard drive they don't contain any data.

Typically the file copy (if done manually) takes about 15 minutes. I let the script run for 90 minutes and it never finished. Can someone help me figure out why the files are not coping properly?