powershell-4.0

Send mail via gmail with PowerShell V4

无人久伴 提交于 2019-12-06 06:24:19
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 the $EmailTo to my email address, and the YOURUSERNAME / YOURPASSWORD to my correct login information. I

Attach Debugger to multiple processes via powershell

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 06:05:12
I have several processes running that I'd like to attach to the VS debugger via powershell. Currently, I can do this: Get-Process NServiceBus.Host | Debug-Process If there is only one process, then I am prompted to select the correct debugger and I can continue. However, if there are more than one processes, when I'm prompted to select a debugger for the second process, I am unable to select the currently running instance of Visual Studio. How can I use powershell to attach multiple processes to a running instance of visual studio for debuggin? To get hold of the active visual studio instance

powershell script reading parameters from txt

醉酒当歌 提交于 2019-12-05 22:51:40
I have a script that takes 2 parameters (name and location). I put the name and location into a txt file as per this post here Powershell parameters from file . I got prompted to put in value for the 2nd parameter: Import-Csv 'C:\temp\paramtest.txt' | % { C:\temp\script\paramtest.ps1 @_ } cmdlet paramtest.ps1 at command pipeline position 1 Supply values for the following parameters: param2:** This is what my .txt look like: "param","param2" "foo","c:\temp" "bar","c:\temp" "foobar","c:\temp" and the Powershell script is just plain: Param ( [Parameter(mandatory=$true,Position=1)] [string]$param,

How to run the .reg file using PowerShell?

ぐ巨炮叔叔 提交于 2019-12-05 21:06:49
I want to run the .reg file (registry file) using PowerShell Script but I am not able to run it. When i run it manually it creates the respective nodes in registry but i want it execute using powershell script. Below is the code which i tried using but got no results - $PathofRegFile="c:\file.reg" regedit /s $PathofRegFile Another code which i tried was this - Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s c:\file.reg" Please Help..! Below is the Content of my .reg file Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\SePI] [HKEY_LOCAL_MACHINE\SOFTWARE\SePI

Zip and Unzip File in Powershell 4

女生的网名这么多〃 提交于 2019-12-05 21:01:47
问题 I am using Windows Server 2012 R2 (64 bit). I have powershell version 4 available in it. I am trying to zip and unzip files. When I try Write-Zip command, it throws me following error: Write-Zip : The term 'Write-Zip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. What should I do to fix it? Do I need to install zip/winrar in the server? Or is there

Error PSRemoting using Session and CredSSP

不问归期 提交于 2019-12-05 14:37:48
I use Windows 8.1 Enterprise 64 bit and Powershell 4.0. I want execute powershell remoting and using authentication CredSSP. I open Console Powershell, run as Administrator, and execute Enter-PSSession command to connect to remote computer. But I get error about connection. PS C:\Documents and Settings\kiquenet> Enter-PSSession -ComputerName DC -credential devrsg.com\Administrator Anyways, I test command from Windows XP and Windows 7, and connection is OK. PS C:\Documents and Settings\kiquenet> Enter-PSSession -ComputerName DC -credential devrsg.com\Administrator [dc]: PS C:\Users

Powershell v4 not importing module automatically

梦想与她 提交于 2019-12-05 14:29:04
I am using Microsoft PowerShell v4 : PS C:\> get-host Name : ConsoleHost Version : 4.0 InstanceId : 3b4b6b8d-70ec-46dd-942a-bfecf5fb6f31 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : de-CH CurrentUICulture : en-US PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace I have developed a C# project in Visual Studio 2012 targeting .NET Framework 4 which contains some Cmdlet and the Snapin . I can debug them and everything works just fine. I've created

In PowerShell why does “casting” to FileInfo set the wrong FullName, Directory, and DirectoryName

旧街凉风 提交于 2019-12-05 12:53:04
I'm noticing a VERY odd behavior in both my PS ISE and PS when I'm getting a FileInfo object by calling $FileInfo = [System.IO.FileInfo](".\SomeFile.ext") When I look at its properties the DirectoryName and its related properties all default to the ORIGINAL path that PS opens in. Here's a copy from my ISE which launches as an administrator with c:\Windows\System32 as the default path If I run the following code: $Fileinfo = [System.IO.FileInfo](".\@OpenWithToastLogo.png") cd c:\temp $Fileinfo2 = [System.IO.FileInfo](".\activation.txt") z: $Fileinfo3 = [System.IO.FileInfo](".\7za.exe")

PowerShell string default parameter value does not work as expected

我是研究僧i 提交于 2019-12-05 09:07:07
问题 #Requires -Version 2.0 [CmdletBinding()] Param( [Parameter()] [string] $MyParam = $null ) if($MyParam -eq $null) { Write-Host 'works' } else { Write-Host 'does not work' } Outputs "does not work" => looks like strings are converted from null to empty string implicitly? Why? And how to test if a string is empty or really $null? This should be two different values! 回答1: Okay, found the answer @ https://www.codykonior.com/2013/10/17/checking-for-null-in-powershell/ Assuming: Param( [string]

How do you apply multiple DSC configurations?

爷,独闯天下 提交于 2019-12-05 06:37:04
Here's my example: $Config = @{ AllNodes = @( @{ NodeName = 'localhost'; PSDscAllowPlainTextPassword = $True } ) } Configuration LocalAdmin { Param([String[]]$Node='localhost',[PSCredential]$Cred) Import-DscResource -ModuleName 'PSDscResources' Node $Node { User 'LocalAdmin' { Username = 'Admin' Description = 'DSC configuration test' Ensure = 'Present' FullName = 'Administrator Extraordinaire' Password = $Cred PasswordChangeRequired = $False PasswordNeverExpires = $True } Group 'AddToAdmin' { GroupName = 'Administrators' DependsOn = '[User]LocalAdmin' Ensure = 'Present' MembersToInclude =