标签: powershell

是否可以在 Windows Server 2003 或 2003 R2 上安装 PowerShell 3?

在年底前到期的Windows Server 2003装备(已经有 .NET 4 但没有 4.5)上,我想在预定的基础上运行一些PowerShell 3脚本,因为脚本取决于PowerShell 3 中引入的功能。

还有的不是很多有用的结果我想搜索,因为他们给混合信息:有的表示是可能的,但其他人表示是不可能的,它肯定是不是在官方下载

所以:

  1. 是否有在 Windows Server 2003 上安装 PowerShell 3 的解决方法?
  2. 如果没有,我应该在哪里寻找PowerShell 3 独有的替代Cmdlet,如Invoke-RestMethodConvertTo-JsonConvertFrom-JsonInvoke-WebRequest

windows powershell windows-server-2003 powershell-3.0

5
推荐指数
1
解决办法
2万
查看次数

通过 PowerShell 获取外部 IP

我只想通过 Powershell 获取外部 IP 只是 IP 地址,没有标头或任何东西。

我尝试了很多事情,例如

(Invoke-WebRequest ifconfig.me/ip).Content
Run Code Online (Sandbox Code Playgroud)

但它有这个额外的第二行,这对我没有好处。

我也试过了。

(Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE) | %{$_.ipaddress[0]}
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用,因为我在路由器后面。

谢谢。

Function IPV()
{
$IPCHK = ((Invoke-WebRequest ifconfig.me/ip).Content.Trim())
$IPCHK | Out-FIle 'CHKIP.txt'
}
$CurrentIP = ((Invoke-WebRequest ifconfig.me/ip).Content.Trim())
$PreviousIP = Get-Content 'CHKIP.txt'

IF($PreviousIP -eq ((Invoke-WebRequest ifconfig.me/ip).Content.Trim()))
    {
        $PreviousIP
        }
ELSE {
       ##SEND EMAIL SCRIPT
        IPV #RUN CHECK IP COMMAND AGAIN.
}
Run Code Online (Sandbox Code Playgroud)

networking powershell ip-address

5
推荐指数
2
解决办法
2万
查看次数

Taskill 与 Tskill

我已经看到这两个用于结束进程。据我了解,tskill 是较旧的 taskkill,因为它的文档位于Microsoft Windows 的 XP 文档中,而较新的 taskkill 能够根据Microsoft Technet Taskkill 的文档一次关闭多个程序。使用两者的优点或缺点是什么?

windows powershell cmd.exe

5
推荐指数
1
解决办法
5185
查看次数

如何从 PowerShell 中的可执行文件调用操作?

我在 Windows 7 SP1 上使用 Powershell 2.0,但任何涵盖 1.0-4.0 版本的答案都会很好。

我知道这个命令是Paint通过 PowerShell打开的:

& "C:\Windows\system32\mspaint.exe"  
Run Code Online (Sandbox Code Playgroud)

我知道此命令Paint通过 PowerShell 以特定图像打开:

& "C:\Windows\system32\mspaint.exe" "C:\Images\RHZv84o - Imgur.jpg" 
Run Code Online (Sandbox Code Playgroud)

我想知道在PowerShell中,如果是我可以调用这个可执行类似的命令printsavesave as?我可以对任何具有自己特定命令的程序执行相同的操作吗?

例如,如果我wmplayer.exe用视频打开(Windows Media Player)(与带图像的绘画格式相同),它会立即打开并播放。我想打开视频并使用其中的任何命令Ctrl + P来暂停视频或Ctrl + N创建新的播放列表?

目标是从Powershell中确定,因为某些可执行文件可以用对象打开,是否可以打开部分或所有可执行文件并调用操作(至少是带有快捷键的)?

script powershell

5
推荐指数
1
解决办法
2672
查看次数

变量中的 Powershell 搜索字符串(不是文本文件)

我试图从存储“systeminfo”命令输出但遇到问题的变量“$a”中搜索名为“Hostname”的字符串。我正在使用“系统信息”来收集更大的数据集。

代码:

$a= (get-systeminfo -computername localhost | select-object hostname, OSNAME, osversion, model, type)  
write-output $a 
select-string $a -pattern "hostname"
Run Code Online (Sandbox Code Playgroud)

错误:

Select-String : Cannot find path 'C:\Users\john001c\@{Hostname=PACCPL-FTN1TM1; OSName=Microsoft Windows 7 Enterprise ; OSVersion=6.1.7601 Service Pack 1 Build 7601; Model=Latitude E
4310; Type=x64-based PC}' because it does not exist.

At line:5 char:14
+ select-string <<<<  $a -pattern "hostname"
    + CategoryInfo          : ObjectNotFound: (C:\Users\john...e=x64-based PC}:String) [Select-String], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SelectStringCommand
Run Code Online (Sandbox Code Playgroud)

在变量中搜索字符串的正确方法是什么?

windows powershell

5
推荐指数
1
解决办法
6万
查看次数

PowerShell脚本查找进程并杀死进程

我是 PowerShell 脚本的初学者,并尝试制作一个小的 PowerShell 脚本来通过搜索文件名来查找 PID,如果显示多个 PID,则取 TOP 一个并杀死该 PID。

我可以通过Get-Process找到 PID ,但是如何将顶部的值存储在变量中然后终止它?

powershell

5
推荐指数
1
解决办法
3万
查看次数

我在哪里可以找到我的 oneget Windows 包管理安装的应用程序?

我刚刚安装了最新的 Windows 10 ctp,想尝试使用 oneget 来安装我需要的一切。例如find-package vlc | install-package -verbose -force,当使用它时,它给了我以下输出:

VERBOSE: NuGet: Installing 'vlc 2.1.5.20140811'.
VERBOSE: NuGet: Successfully installed 'vlc 2.1.5.20140811'.

Name                                     Version      Status       ProviderName     Source           Summary
----                                     -------      ------       ------------     ------           -------
vlc                                      2.1.5.201... Installed    Chocolatey       chocolatey       VLC Media Player
Run Code Online (Sandbox Code Playgroud)

虽然它告诉我它安装了 vlc,但我在我的系统上找不到它。无论是在有一个新的文件夹,C:\Program Files\或者C:\Program Files (x86)\也可以在开始菜单的搜索发现,我也不能从PowerShell的开始VLC。

我在哪里可以找到我的 oneget 安装的应用程序?

编辑(其他可能的解决方案):如果您遇到此问题,甚至无法在按照 mikemaccana 的解决方案获得的目录中找到您的应用程序,那么您可能遇到了与我遇到的相同问题:
您需要通过set-executionpolicy remotesigned以管理员身份运行,将执行策略设置为至少远程签名!

powershell windows-packagemanagement

5
推荐指数
1
解决办法
1609
查看次数

从批处理脚本中静默更改 Powershell 执行策略

我想要一些关于为 powershell 设置注册表值的帮助。路径是

[hkey_local_machine\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell] "Path"="c:\windows\system32\windowspowershell\v1.0\powershell.exe" "ExecutionPolicy"="无限制"

因为我是从一台已知的好机器导入的,所以当我运行 .reg 文件时它工作正常。但我想在批处理文件中使用它。

当我手动调用命令提示符时,放入路径,例如c:\powershell.reg,这将导入值并根据需要覆盖注册表设置。
但是,如果我调用在批处理文件中执行相同的操作,则注册表中的值不会更改 在批处理文件中使用 reg add 命令,这些值不起作用。

powershell command-line

5
推荐指数
2
解决办法
2万
查看次数

Microsoft 的 Powershell 2.0 文档存档?

在 Microsoft Technet 上查找有关内置于 Powershell 的特定 cmdlet 的信息时,您可以在 Powershell 3.0、4.0 和 5.0 版本之间进行选择。有关示例,请参阅此页面 - https://technet.microsoft.com/en-us/library/mt156967.aspx

是否有页面或其他站点可以找到有关2.0版的信息?

powershell documentation msdn powershell-2.0 microsoft-technet

5
推荐指数
1
解决办法
2176
查看次数

如何为 PowerShell 5.0 设置自定义语法着色?

我最近将一台 Windows 8.1 计算机升级到了 Windows 10,默认情况下它带有 PowerShell 5.0。我注意到PowerShell 现在对关键字、cmdlet、字符串等进行了语法着色

在此处输入图片说明

我想知道是否有任何方法可以设置自定义配色方案?例如,评论目前是绿色的,我想让它们变灰。这可能吗?

windows powershell windows-10

5
推荐指数
1
解决办法
5107
查看次数