powershell-ise

Send mail via gmail with PowerShell V4

我们两清 提交于 2020-01-02 19:26:33
问题 I have been using this PowerShell script to send my an email to me when opened. $EmailFrom = "notifications@somedomain.com" $EmailTo = "anything@gmail.com" $Subject = "sample subject" $Body = "sample body" $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("YOURUSERNAME", "YOURPASSWORD"); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body) I changed

How to cleanup resources in a DLL when Powershell ISE exits - like New-PSSession and New-PSJob

醉酒当歌 提交于 2019-12-24 12:33:44
问题 I'm trying to implement a set of cmdlets in C# which create and manage external resources, with a similar pattern to New-PSSession, Get-PSSession, Remove-PSSession. The objects created need to do work on their own threads, which is cancellable. It works fine if I explicitly Dispose() each object. But if I create some objects, and then exit Powershell ISE without Disposing, the powershell_ise.exe process hangs around until I kill it in task manager. I can fix this by calling Register

PowerShell ISE and PowerShell.Exiting event

℡╲_俬逩灬. 提交于 2019-12-24 06:01:08
问题 I'm using the PowerShell.Exiting engine event to save my command history and do some other tidying up when I close a PowerShell session, registering it in my profile thus: # Set up automatic functionality on engine exit. Register-EngineEvent PowerShell.Exiting -SupportEvent -Action ` { #stuff ... } This works perfectly when I use PowerShell in a console window, but when I'm running PowerShell in ISE, it appears that the PowerShell.Exiting event somehow never fires, since nothing I put in

The PowerShell ISE sometimes behaves unpredictably after code changes are made

牧云@^-^@ 提交于 2019-12-22 07:13:27
问题 I'm using the PowerShell ISE (PS version 5.0). If I run this code: Write-Host "This" It outputs: This If I modify the script like this: Write-Host "That" It outputs: That Great. As expected. Now, if I have this code: $Form = New-Object System.Windows.Forms.Form $Timer = New-Object System.Windows.Forms.Timer $Timer.Add_Tick( { &{ Write-Output "Here" $Form.Close()} | Write-Host }) $Timer.Interval = 3000 $Timer.start() $result = $Form.ShowDialog() It outputs: Here If I change anything in the

Using CurrentDomain.SetData(“APP_CONFIG_FILE”) doesn't work in PowerShell ISE

吃可爱长大的小学妹 提交于 2019-12-18 13:24:12
问题 I'm attempting to use a .NET 4.0 assembly in PowerShell ISE, and trying to change the config file which is used via: [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $PathToConfig); [Configuration.ConfigurationManager]::ConnectionStrings.Count always returns "1", and "[Configuration.ConfigurationManager]::ConnectionStrings[0].Name" always returns "LocalSqlServer", and that ConnectionString name is not in my ".config" file. Note that executing the PowerShell script from a

PowerShell ISE throws an error on git checkout

别等时光非礼了梦想. 提交于 2019-12-17 16:45:38
问题 In PowerShell, git checkout runs without any error message. In the ISE, while git checkout stills works, the ISE gives an error message. > git checkout master Your branch is ahead of 'origin/master' by 3 commits. (use "git push" to publish your local commits) git : Switched to branch 'master' At line:1 char:1 + git checkout master + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Switched to branch 'master':String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError This isn

PowerShell changes return object's type

霸气de小男生 提交于 2019-12-17 16:32:47
问题 I am using PowerShell v3 and the Windows PowerShell ISE. I have the following function that works fine: function Get-XmlNode([xml]$XmlDocument, [string]$NodePath, [string]$NamespaceURI = "", [string]$NodeSeparatorCharacter = '.') { # If a Namespace URI was not given, use the Xml document's default namespace. if ([string]::IsNullOrEmpty($NamespaceURI)) { $NamespaceURI = $XmlDocument.DocumentElement.NamespaceURI } # In order for SelectSingleNode() to actually work, we need to use the fully

Reload the path in PowerShell

家住魔仙堡 提交于 2019-12-17 10:14:44
问题 If I have an instance of PowerShell ISE running and I install something that modifies the PATH or I modify it in any way outside of PowerShell then I need to restart PowerShell for it to see the updated PATH variable. Is there a way to reload the path from within PowerShell without restarting it? 回答1: Just to bring Rob's comment to light: $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 回答2: Try

Security Warning when running scripts - Unblock-File not unblocking file

旧巷老猫 提交于 2019-12-14 03:50:04
问题 I suddenly started to recceive this warning when running any script on my computer: Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer... Screenshot: The files are not blocked. I have checked in File Explorer > Properties. used the Unblock-File cmdlet to unblock as well. checked streams using cmdlet: Get-Content -Path '\\Path\Script.ps1' -Stream Zone.Identifier . No Streams found. used Streams.exe from Sysinternals:

How to Replace Description Text for All Users in an Organizational Unit using Powershell

半腔热情 提交于 2019-12-13 19:47:26
问题 I have added about 1700+ users to Active Directory using a CSV file. I accidentially tried to use \n to seperate some attributes between them. But it did not escape new line. Instead typed it as is. $Users = Import-Csv -Path "C:\UsersList.csv" foreach ($User in $Users) { $Name = $User.Name $AccountPassword = $User.AccountPassword $City = $User.City $Company = $User.Company $GivenName = $User.GivenName $SamAccountName = $User.SamAccountName $Surname = $User.Surname $UserPrincipalName = $User