powershell-3.0

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

Wrong encoding on PowerShell Invoke-WebRequest POST

a 夏天 提交于 2019-12-18 12:19:36
问题 I'm using Invoke-WebRequest POST method to send an text data. After sending the text in a wrong encoding. Script: $postData = "žluťoučký kůň úpěl ďábelské ódy" Invoke-WebRequest -Uri 'http://www.mydomain.com/' -Method Post -Body $postData -ContentType "text/plain; charset=utf-8" Fiddler: POST http://www.mydomain.com/ HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.2; cs-CZ) WindowsPowerShell/4.0 Content-Type: text/plain; charset=utf-8 Host: www.mydomain.com Content-Length: 31

Display all sites and bindings in PowerShell

北慕城南 提交于 2019-12-18 10:22:06
问题 I am documenting all the sites and binding related to the site from the IIS. Is there an easy way to get this list through a PowerShell script rather than manually typing looking at IIS? I want the output to be something like this: Site Bindings TestSite www.hello.com www.test.com JonDoeSite www.johndoe.site 回答1: Try something like this to get the format you wanted: Get-WebBinding | % { $name = $_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1' New-Object psobject -Property @{ Name =

PowerShell equivalent of cmd “IF %ERRORLEVEL% NEQ 0”

坚强是说给别人听的谎言 提交于 2019-12-18 09:31:21
问题 Looking for the PowerShell equivalent of this cmd error-check: IF %ERRORLEVEL% NEQ 0 Here is the PowerShell code I am trying to write: Write-Information "Installing .NET 3 from DVD:" $NetFX3_Source = "D:\Sources\SxS" dism /online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:$NetFX3_Source /NoRestart IF (****TheCommandYouTellMe****) { Write-Information "DVD not found, installing from online sources, the Win default method" DISM.EXE /Online /Add-Capability /CapabilityName

Powershell: Download or Save source code for whole ie page

北战南征 提交于 2019-12-18 09:04:55
问题 I have this PS script it logins to a site and then it navigate's to another page. I want to save whole source for that page. but for some reason. some parts of source code is not coming across. $username = "myuser" $password = "mypass" $ie = New-Object -com InternetExplorer.Application $ie.visible=$true $ie.navigate("http://www.example.com/login.shtml") while($ie.ReadyState -ne 4) {start-sleep -m 100} $ie.document.getElementById("username").value = "$username" $ie.document.getElementById(

Get-ADUser for not exact username

孤者浪人 提交于 2019-12-18 07:22:31
问题 The script below lists some user details, it works only in case I've entered the EXACT user name. Is there a method I could use to get results if I type a partial username? I mean if for example I enter "elibukin" or "eli.buk" instaed of "eli.bukin" witch is the correct username. do { Write-Host "Who r we looking for ? (type EXIT when u done)" $User = Read-Host Get-ADUser $User -Properties * | fl empl*,title, sam*, disp*, mail*, manager*, depa*, giv*, l, last*, logon*, when* } until ($user

how to filter name/value pairs under a registry key by name and value in PowerShell?

Deadly 提交于 2019-12-18 05:12:50
问题 I'm trying to get a feel for the idioms to use in PowerShell. Given this script: $path = 'hkcu:\Software\Microsoft\Windows\CurrentVersion\Extensions' $key = Get-Item $path $key I get the output at the bottom of this question. I'd like to get output of the properties (the name/value pairs under the $key ) where I can filter on both name and value. For instance, filter to list all the Extensions that have: name like xls* or value like *\MSACCESS.EXE Or an exclude filter: exclude all names like

How does Select-Object stop the pipeline in PowerShell v3?

不想你离开。 提交于 2019-12-18 02:46:48
问题 In PowerShell v2, the following line: 1..3| foreach { Write-Host "Value : $_"; $_ }| select -First 1 Would display: Value : 1 1 Value : 2 Value : 3 Since all elements were pushed down the pipeline. However, in v3 the above line displays only: Value : 1 1 The pipeline is stopped before 2 and 3 are sent to Foreach-Object (Note: the -Wait switch for Select-Object allows all elements to reach the foreach block). How does Select-Object stop the pipeline, and can I now stop the pipeline from a

Is there a way to enter the debugger on an error?

◇◆丶佛笑我妖孽 提交于 2019-12-17 22:15:20
问题 Is there a way to enter the PowerShell debugger in response to an error? The ErrorAction parameter has several values but I don't see anything like Debug . What I would like is to open the debugger like it would open if I had set a breakpoint, but only when an error occurs (from, say, Write-Error ). Edit I should clarify a bit: I am primarily a C# developer and somewhat new to PowerShell, what I am expecting is behavior similar to what the Visual Studio debugger gives you for "unhandled

Powershell Using Start-Process in PSSession to Open Notepad

夙愿已清 提交于 2019-12-17 19:53:40
问题 I've created a pssession on a remote computer and entered that possession. From within that session I use start-process to start notepad. I can confirm that notepad is running with the get-process command, and also with taskmgr in the remote computer. However, the GUI side of the process isn't showing. This is the sequence I've been using: $server = New-PSSession -ComputerName myserver -Credential mycreds Enter-PSSession $server [$server]: PS C:\>Start-Process notepad -Wait -WindowStyle