标签: powershell-ise

用于显示通知气球并采取行动的 PowerShell 脚本仅适用于 ISE gui,而不适用于命令行

我看过一堆密切相关的帖子,所以我知道我并不孤单,但没有人给我我正在寻找的答案。如果有人问过并回答过这个问题而我找不到它,我深表歉意。

此脚本创建一个自定义通知区域气球,如果单击该气球,将打开一个指向某个 URL 的新 IE 窗口。在我一直在使用它的 PowerShell ISE GUI 中效果很好。无法使用我在其他帖子中看到的任何选项从命令行运行。具体来说,无法打开 IE 窗口。通知出现没有问题,但是没有IE窗口...??尝试过:

  • 电源外壳 。脚本.ps1
  • powershell -file script.ps1
  • 命令
  • &

等等。

想法?

我的脚本:

#Load the required assemblies
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
#Remove any registered events related to notifications
Remove-Event BalloonClicked_event -ea SilentlyContinue
Unregister-Event -SourceIdentifier BalloonClicked_event -ea silentlycontinue
Remove-Event BalloonClosed_event -ea SilentlyContinue
Unregister-Event -SourceIdentifier BalloonClosed_event -ea silentlycontinue
Remove-Event Disposed -ea SilentlyContinue
Unregister-Event -SourceIdentifier Disposed -ea silentlycontinue

#Create the notification object
$notification = New-Object System.Windows.Forms.NotifyIcon 
#Define various parts of the notification
$notification.Icon = …
Run Code Online (Sandbox Code Playgroud)

powershell notifications powershell-ise powershell-2.0 windows-7

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

为什么PowerShell ISE会挂起这个C#程序?

如果我将这个c#代码编译成EXE文件并在Windows命令shell中运行它运行正常:输出提示,在同一行等待一些用户输入,然后输入,回显该输入.在PowerShell v3 shell中运行它也运行良好.但是,如果我在PowerShell ISE V3中运行相同的EXE文件,它永远不会从中发出输出Write并挂起ReadLine.(顺便说一下,Write如果后来跟着a ,它会发出输出WriteLine.)

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.Write("invisible prompt: ");
            var s = System.Console.ReadLine();
            System.Console.WriteLine("echo " + s);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一个ISE错误还是有一些属性可以调整以使其工作......?

c# powershell hang powershell-ise

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

如何在 PowerShell 中使用 Set-NetConnectionProfile 更改 NetConnectionProfile 的名称

我尝试使用如何使用 Set-NetConnectionProfile 更改 NetConnectionProfile 的名称

$Profile=Get-NetConnectionProfile -InterfaceIndex 35
$Profile.Name = "Network1"            
Run Code Online (Sandbox Code Playgroud)

错误是

"Name" is a ReadOnly property.
 At line:1 char:1
+ $Profile.Name = "Network1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) []
+ FullyQualifiedErrorId : ReadOnlyCIMProperty
Run Code Online (Sandbox Code Playgroud)

如何更改名称的只读属性??帮我

powershell powershell-ise powershell-2.0 powershell-3.0

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

Powershell ISE缓存变量值?

我在Windows Server 2008r2上运行64位Powershell ISE.

在调试时我设置了一个变量:

$dbName = "db1"
Run Code Online (Sandbox Code Playgroud)

然后,我做了以下更改

$dbName = "db2"
Run Code Online (Sandbox Code Playgroud)

我再次单步执行脚本,即使调试器跨过修改后的行,当我将鼠标悬停在$ dbName变量上时,它仍显示值"db1".我似乎可以解决这个问题的唯一方法是重启那个ISE - 这很痛苦!

谁能告诉我哪里出错了?

*更新*

我在模块中有以下功能:

Function SampleFunction()
{
    $dbName = "db1"
    write-host $dbName
}
Run Code Online (Sandbox Code Playgroud)

我有一个powershell脚本导入moduleL

Import-Module -Name ".\BadPsm.psm1"
Run Code Online (Sandbox Code Playgroud)

从powershell ISE我在执行函数之前在$ dbName ="db1"上放置一个断点,方法是在执行窗口中输入"SampleFunction".一切都很好,值"db1"被写入输出窗口.

然后我更改函数,以便$ dbName ="db2".我通过再次执行Import-Module -Name".\ BadPsm.psm1"重新导入模块.

当我再次执行该函数时,我点击断点,跳过并看到$ dbName仍等于"db1","db1"也写入输出窗口.

为了帮助说明我已经在youtube上发布了一个简短的截屏视频:youtube链接

powershell powershell-ise

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

如何在PowerShell ISE中的注释中键入选项卡(缩进)?

这很奇怪.

我知道tab是PowerShell ISE中的命令完成,所以很好.但是,它也会破坏编辑窗格.

做这个:

  1. 文件>新建(Untitled1.ps1打开)

  2. 按标签(一切正常,你得到一个缩进)

  3. 键入enter,#(注释)并按预期后按Tab键:在哈希实际后,将获得缩进:一个获取哈希替换为$PSVersionTable或者命令提示符在其历史记录中的任何内容!(标签和Shift-tab圈选那些)

这是否意味着没有人在PowerShell脚本中的注释中使用选项卡,或者没有人在PowerShell脚本中使用注释?

我可以在任何地方关闭此行为吗?

此外,行为似乎不一致.如果我输入##,有时标签不会完成(它也不会输入标签).

其他人可以重现这个吗?

截图

系统:Windows 8.1 Pro PowerShell ISE

powershell powershell-ise

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

(Powershell) 捕获“Get-WinEvent : 未找到事件” Get-WinEvent

当我运行以下命令按 ID 列出日志时,它说 Get-WinEvent : No events were found that match the specified selection criteria.

如何捕获此异常并显示一条简单的消息“未找到事件”。

我运行的命令-

Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}
Run Code Online (Sandbox Code Playgroud)

我在下面尝试过,但无法使其工作-

try { Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}
    }

catch [Exception] {
        if ($_.Exception -match "No events were found that match the specified selection criteria") {
        Write-Host "No events found";
                 }
    }
Run Code Online (Sandbox Code Playgroud)

请帮忙。谢谢

powershell powershell-ise powershell-2.0 powershell-3.0

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

PowerShell:导入模块:程序集名称或代码库无效(HRESULT:0x80131047)

我刚刚安装了新的ISE 模块浏览器,想尝试第一个模块,我选择了该Bing模块(需要另一个名为 的模块BetterCredentials,但处理得很好,所以没问题)。

因此,如 Bing 模块脚本开头所述,我必须这样做:

在此处输入图片说明

我也是如此,我注册并获得了我的 ApiKey,当我尝试“ Import-Module”Bing 时,使用那个 ApiKey,我得到了这个“著名的”错误:

在此处输入图片说明

据我所知,模块名称没有问题,有什么问题?我该怎么办 ?

更新

然而,PowerShell 可以识别 cmdlet 但无法执行它们:

在此处输入图片说明

powershell powershell-ise bing nuget powershell-5.0

5
推荐指数
0
解决办法
1674
查看次数

Powershell 4.0 Transcript不捕获Write-Host语句的输出

我创建了以下脚本(test.ps1),我从命令行执行它作为"powershell.\ test.ps1"

Write-Host(Start-Transcript -Path "D:\logs.txt")
$remoteScript = {
    Write-Host "Remote Log"
}
Invoke-Command -ConnectionUri $uri -Credential $creds -ScriptBlock $remoteScript
Write-Host "Local Log"
Write-Host(Stop-Transcript)
Run Code Online (Sandbox Code Playgroud)

但是在执行脚本后生成的日志文件中,我没有看到远程或本地的日志语句.这曾经与Powershell 3.0一起使用,但最近我升级到Powershell 4.0并且它停止工作.

有没有人遇到类似的问题或者是否知道从远程和本地命令捕获输出的任何其他方法?

谢谢,

拉夫

powershell powershell-ise powershell-remoting powershell-3.0 powershell-4.0

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

在命令行中找不到但在 ISE 中可用的 Cmdlet

我正在尝试在 Windows Server 2008 R2 VM 上使用 PowerShell 创建 IIS 应用程序和应用程序池。powershell脚本如下:

Param(
    [string] $branchName,
    [string] $sourceFolder
)

if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator"))
{ 
    Write-Warning "You do not have Administrator rights to run this script.     `nPlease re-run this script as an Administrator."
    Exit
}

$appPool = $branchName
$site = "Default Web Site"

#Add APPPool
New-WebAppPool -Name $appPool -Force 

#Create Applications
New-WebApplication -Name $branchName -Site $site -PhysicalPath $sourceFolder -   ApplicationPool $appPool -Force    
Run Code Online (Sandbox Code Playgroud)

如果我在 PowerShell ISE 中运行脚本,它运行良好,但如果我从命令行(或使用命令行的批处理文件)运行它,我会收到错误

术语 New-WebAppPool 不被识别为 cmdlet 的名称...等。 …

iis powershell cmdlets batch-file powershell-ise

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

为什么 PowerShell ISE 中的控制台不使用最新安装的 PowerShell 版本?

我最近安装了 PowerShell 6.2。

如果我启动 PowerShell 6 (x64) 命令提示符并运行$PSVersionTable.PSVersion这是结果

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
6      2      0
Run Code Online (Sandbox Code Playgroud)

在相同的提示下,我运行 ISEpowershell_ise.exe并启动 PowerShell ISE。但是,在 ISE 中的控制台中,如果我运行$PSVersionTable.PSVersion它会报告:

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1  
Run Code Online (Sandbox Code Playgroud)

是否有设置来控制 ISE 查找 PowerShell 的位置?或者有什么方法可以确保它使用安装的最新版本?


更新:作为安装 PowerShell Core(即 6.2 版)的一部分,我必须安装 Windows Management Framework 5.1。我从这个文档中了解到,这也应该将 ISE 控制台的 PowerShell 版本升级到 5.1。如上所述,我仍然看到 4.0 版。我错过了什么?

powershell powershell-ise powershell-4.0 powershell-v6.0 powershell-core

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