Commit graph

2385 commits

Author SHA1 Message Date
Steve Lee 5f5407595d replace the word hang with something more appropriate (#5358) 2017-11-08 13:47:12 -08:00
James Truher [MSFT] fe3e44f305 Change $OutputEncoding to be utf8 without BOM rather than ASCII (#5369) 2017-11-07 14:49:14 -08:00
Jason Shirk 8391b9e155 Rework passing array literal to native commands (#5301) 2017-11-06 17:05:26 -08:00
Keith Hill c781959232 Display full help with 'help' function (#5195)
Display full help with 'help' function
2017-11-06 10:19:39 -08:00
Dan Travison 2670917981 Redirect ETW logging to Syslog on Linux (#5144)
This PR is divided into the following areas:
1. Add/Rename the PowerShell/Windows ETW manifest to the repo and change both the provider id (guid) and name. See #4939.
The manifest is at tools/resxgen/PowerShell-Core-Instrumentation.man

2. Generate a resx file containing the string resources needed for logging ETW events to syslog.
This is accomplished by tools\resxgen\resxgen.psm1 and resxgen.ps1. The tool generates two files

A resx file containing string resources for each message string from the manifest. This is generated in the System.Management.Automation\gen directory.
A C# class (EventResource) that provides the mapping between the integer event id and the associated string resource name. The file is generated in the System.Management.Automation\CoreCLR directory with a compile-time condition of UNIX
NOTE: The EventResource.cs class generated by resgen is explicitly ignored in the csproj file; it is not used.

3. SMA\utils\tracing\PSSysLogProvider.cs
Implements the abstract LogProvider class and is the syslog equivalent of PSEtwLogProvider. The class contains a number of logical methods for logging lifecycle, health, and normal events.

4. SMA\utils\tracing\SysLogProvider.cs
This is the Syslog equivalent of ETW's log provider class and implements a Log method versus ETW's EventWrite. It is also responsible for resolving event ids to resource names and performing the Syslog call. There is a large comment block in the class XML doc that describes the types of log output it produces.

5. SMA\utils\tracing\PSEtwLog.cs
PowerShell's current implementation is tightly coupled to this class; with code calling it directly for all events. To simplify integration of syslog, I updated the class to create an instance of PSSysLogProvider on Linux and removed the Linux-specific stub file.

6. SMA\engine\PropertyAccessor.cs
This class provides a wrapper around PowerShellProperties.json and has been extended to have Unix-specific assessors for configuring logging. Note that the file is expected to be in the $PSHOME directory to ensure SxS.

Currently, there are four configuration properties:

- LogIdentity - the string identifier for the source application. This defaults to 'powershell' and can be configured to enable distinguishing between side-by-side installations.
- LogLevel - configures the tracing level (log level). Informational is the defauilt.
- LogChannels - used to enable operational and analytic logging. Operational is the default.
- LogKeywords - used to configure enabling tracing by keyword. All keywords other than `UseAlwaysAnalytic` are enabled by default.

NOTE: This will likely change. PowerShell sometimes confuses the analytic channel with this keyword and sends logging to the wrong channel. Once this is cleared up, `UseAlwaysAnalytic` and `UseAlwaysOperational` keywords will likely be removed.

Additional Notes:

1. The current implementation writes directly to syslog and writing to a separate log file is still pending.
2. The generated class and resx are not part of the build; instead, it is expected that Resxgen should be run when events are added to the manifest. To fully automate the process, resxgen will need to be updated to generate the other dependent enums such as 'PSChannel', 'PSEventId', 'PSTask', 'PSOpcode', etc. You will see parsing logic in resxgen.psm1 to prepare for that but it is not enabled at this point.
4. Documentation is pending that documents the format of the syslog output as well as associated configuration.
5. As mentioned at the start, tests are pending
2017-11-06 08:32:29 -08:00
Dongbo Wang ef00088ade
Separate Install-PowerShellRemoting.ps1 from psrp.windows nuget package (#5330) 2017-11-03 14:45:07 -07:00
Ilya 4140bb2ddb Revert the breaking change in AddTypeCommandBase.EndProcessing (#5306) 2017-11-03 12:44:20 -07:00
Chunqing Chen 36b600d1ec Add Jobject serialization support to ConvertTo-Json (#5141) 2017-11-03 11:35:09 -07:00
Dan Travison ed499ced53 Use native os_log APIs on OSX for PowerShell logging (#5310) 2017-11-03 10:56:35 -07:00
Ilya 819f9a3edf Add help strings in PowerShell banner (#5275) 2017-11-03 10:52:06 -07:00
Raphael c9f83fecfc Add Remove-Alias Command (#5143)
* Add Remove-Alias Command. Add Remove-Alias Test. Add Remove-Alias to .psd1.

* Fix code-formatting. Fix ErrorAction on Remove-Alias instead of preference variable. Remove unnecessary Get-Alias calls. Switch Force parameter to auto property. Add ValueFromPipeline to Remove-Alias Name parameter.

* Remove empty lines. Add Remove-Alias to Unix Module .psd1. Add Remove-Alias to approved Commands test. Remove Try/Catch for SessionstateException. Add WriteError for aliasnotfound exception.

* Add ErrorAction Stop to all Get-Alias and Set-Alias Cmdlets in all tests for consistency. Add Should BeNullOrEmpty to "should throw if alias does not exist" test to verify that foo alias really is not there before removing it.

* Changed Remove-Alias parameter Name to String-Array. Changed Cmdlet Process Logic to work with String Array. Added Alias named "ral". Added test case for Alias "ral". Added "ral" Alias to list of approved Aliases. Replaced foo and bar values in all tests with better names.

* Remove "ral"-alias test as this is covered in DefaultCommands.Tests.ps1. Add test for removing multiple alias at once. Fix wrong curly braces positioning.

* Remove $FullCLR in DefaultCommands.Tests.ps1 for Remove-Alias and "ral" alias.

* Add Alias "ral" to Remove-Alias Cmdlet.

* Remove "ral" alias as this is handled by using the [Alias()] attribute on the Remove-Alias Cmdlet.

* Replace alias names used in Remove-Alias Cmdlet tests with GUIDs to avoid collisions
2017-11-03 12:08:37 +04:00
Jason Shirk 51c985495f
Speed up check for suspicious content (#5302)
This replaces the code that scanned a script block for suspicious strings.
The previous implementation:
* Tokenized input (generating many strings for garbage collection)
* Used multiple threads

This approach is based on Rubin-Karp and does not allocate any memory
other than a small array to hold the running hash values.

I tested the new and old approaches on 2200 files in the PowerShell repo.
The old code ran in about 1.8-2.1s (ignoring time spent reading files)
The new code runs in about 0.6s and is more stable due to no garbage.
2017-11-02 17:59:43 -07:00
Chunqing Chen 2ae776ae1f Fix 'ExecutionContext.LoadAssembly' to load with name when file cannot be found (#5161) 2017-11-02 17:13:02 -07:00
Jason Shirk 71d5439bbe
Fix dynamic class assembly name (#5292)
Using the assembly name to hint at the source of the classes was
problematic in multiple ways.

This change stores the actual filename in an attribute on the assembly.

So for a given type, one can get the assembly this way:

[SomeType].Assembly.GetCustomAttributes() |
    ? { $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute] } |
    % { $_.ScriptFile }
2017-11-02 10:29:10 -07:00
Jason Shirk 237ccbdf6d Use wider columns for process id and user (#5303)
I also moved all the formatting code higher up in the tree, it never felt like it belonged where it was.
2017-11-02 07:56:24 -07:00
Mark Kraus 57f3c85469 Add Multiple Link Header Support (#5265) 2017-11-01 14:06:30 -07:00
Jason Shirk c75357b192
Minor perf tweaks (#5289)
* Avoid creating scriptblocks unnecessarily in PSScriptProperty
* Use string.IsNullOrWhiteSpace instead of Trim().Length
2017-11-01 13:32:43 -07:00
James Truher [MSFT] d43b2cf958 Remove DCOM support from *-Computer cmdlets (#5277)
Since DCOM is not supported in corefx there was a great deal of dead code in the computer cmdlets.
This PR removes all vestiges of DCOM support from:

- Rename-Computer
- Restart-Computer
- Stop-Computer

removing about 4500 lines of dead code. Also, tests are updated to provide more complete coverage.
I also removed test-connection completely to make way for @iSazonov upcoming PR to improve coverage in tests, I created some test hook code which will test the cmdlet code without actually calling the WMI method to restart/rename/stop the system
2017-11-01 10:59:41 -07:00
Jason Shirk 6cbcf5dd3e Glob native command args only when not quoted
Also fix some minor issues with exceptions being raised when resolving
the path - falling back to no glob.

Fix: #3931 #4971
2017-10-31 23:34:50 -07:00
Jason Shirk aa2f6fbc2d Use Ast for context in parameter binding
Previously we used IScriptPosition for context (e.g. error reporting)
during parameter binding, but in some cases we want more information, so
we'll use the Ast instead.

This change just adds the Ast, it doesn't make explicit use of it.
2017-10-31 23:34:50 -07:00
Mark Kraus dc01301cea Fix PSUserAgent Generation Exception on Windows 7 (#5256)
* Use Regex to Capture Windows Version
2017-11-01 10:22:18 +04:00
Ilya 1c446c1be4
Fix performance issues in Add-Type (#5243)
* Exclude ReadAllText from OutputError()

* Exclude double ReadAllText() from EndProcessing

* Remove sourceCode initialization

* Add StringBuilder init size and remove unneeded code.

* Set init size StringBuilder in 8192
2017-10-31 19:00:41 +04:00
Jason Shirk b1080860a4 Remove AllScope from most default aliases (#5268)
* Remove AllScope from most default aliases

To speed up scope creation, I removed AllScope from most default
aliases.

This results in a 15-20% speedup for:

    function foo {}
    for ($i = 0; $i -lt 100kb; $i++) { & { foo } }

I left AllScope of a few frequently used aliases because it does
make command lookup faster. If we introduce something like dynamic
sites for command lookup, then we could probably remove the rest
of the AllScope aliases.

This is a low-risk breaking change. One can ask for aliases at
a particular scope:

    Get-Alias -Scope 1 nsn

This could now fail if the scope number doesn't correspond to global
scope.
2017-10-30 20:05:49 -07:00
Steve Lee a384c6ea11 Change to not insert line breaks to output (except for tables) (#5193) 2017-10-30 09:54:44 -07:00
Jason Shirk 8234e3cd19
Remove CommandFactory (#5266)
The class CommandFactory served no real purpose in command lookup
other than to unnecessarily add a few frames to the call stack,
introduce an extra indirection, and add a couple of unnecessary
checks that essential instances like ExecutionContext are not null.
2017-10-28 21:01:47 -07:00
Mathias R. Jessen 9b32c1d039 Add char range overload to DotDot operator (#5026) 2017-10-28 10:47:10 -07:00
Steve Lee 967ed8b664 Fix 'Import-module' to not report a loaded module was not found (#5238)
Missed a 'break' statement after the module was loaded successfully, so the loop continues when it shouldn't.
2017-10-26 14:16:47 -07:00
Steve Lee 7407a9e300 Fix 'get-item -literalpath a*b' to return error if a*b doesn't actually exist (#5197) 2017-10-26 14:14:46 -07:00
Steve Lee 4bc52d2358 Use consistent '(c)' for copyright symbol (#5210)
- Remove the year about copyright
- Fix casing of `All rights reserved`
- Replace Unicode characters representing single quote with a single quote
2017-10-26 14:12:19 -07:00
Steve Lee b1af9ea230 -Verbose should not override $ErrorActionPreference (#5113)
* -Verbose should not override $ErrorActionPreference

* apply same fix to -debug and added test case

* address Aditya's feedback
2017-10-26 13:40:14 -07:00
bergmeister f5f0d3afc5 Add -AsHashtable switch to ConvertFrom-Json for issue #3623 (#5043)
Address #3623.

Implementation symmetric to traditional code path that returns a PSCustomObject. Code is shared on the top level but 2 low level methods were difficult to share, therefore 2 separate but similar methods were created for HashTables.
All existing tests related to this change were adapted to also test against this new switch and were slightly improved.

-AsHashtable is an existing pattern used in Group-Object
2017-10-25 08:57:05 -07:00
Jonas Andersen ca30054761 Added BinPath, Description, UserName and Delayed Auto Start to Get-Service (#4907)
Added the following to the  Get-Service  command:
•BinaryPathName (Was suggested as  ServicePath )
•Description
•UserName (Was suggested as  LogOnAs )
•DelayedAutoStart
•ServiceStartupType

The ServiceStartupType was also added, providing the user access to use services like in  services.msc , having  Automatic ,  Automatic (Delayed Start) ,  Manual  and  Disabled  as options (Also includes  InvalidValue  as an initial value for  ServiceStartupType )
2017-10-24 10:54:07 +04:00
James Truher [MSFT] be700729d6 Unify cmdlets with parameter 'Encoding' to be of type System.Text.Encoding (#5080)
This unifies file encoding across the inbox cmdlets to be UTF-8 without a BOM for all platforms. This is a breaking change as cmdlets on windows have a number of different encodings. This supports better interoperability with tradition Linux shells as we are using the same encoding.

Validate that files are created with UTF-8 encoding without BOM
Update tests to validate Encoding parameter to new type and create new tests for
parameter type validation.

[Breaking Change] The '-Encoding Byte' has been removed from the filesystem provider cmdlets. A new parameter '-AsByteStream' is now added to indicate that a byte stream is required as input, or output will be a stream of bytes.
2017-10-23 19:46:27 -07:00
Steve Lee d85b9a472c Put command discovery before scripts for Unix (#5116)
* put command discovery before scripts for Unix

* remove unnecessary test
2017-10-23 17:54:28 -07:00
Joshua King c98fe394ec Make Get-ChildItem honor Depth parameter with Include/Exclude (#4985)
* Add depth to ProcessPathItems

* Honors capped recursion when using Include or Exclude filters with Get-ChildItem

* Including test cases to test include/exclude recursion

* Swap optional parameter for overload
2017-10-23 12:22:05 -07:00
Aditya Patwardhan df06200be5 Add new Fwlinks for v6 help content (#4978)
Updated fwlinks to pull new help content for PSv6.
Fwlink for Microsoft.PowerShell.Core module is not updated since about_*help.txt is not available yet.
2017-10-23 09:28:17 -07:00
Dongbo Wang 5b2bbcbf89 Update the help text with the new name 'pwsh' (#5182) 2017-10-21 13:50:00 +04:00
Mark Kraus 9fd600448c Make -NoTypeInformation Default on Export-Csv and ConvertTo-Csv (#5164)
•Sets  -NoTypeInformation  as the default behavior for  Export-Csv  and  ConvertTo-Csv 
•Hides the  -NoTypeInformation  parameter switch
•Adds  -IncludeTypeInformation  switch to  Export-Csv  and  ConvertTo-Csv  to enable legacy behavior
•Provides a terminating error when both  -NoTypeInformation  and  -IncludeTypeInformation  are supplied
•adds tests for the new behavior
•fixes existing tests to align with new behavior

The new behavior will need to be documented.
2017-10-21 13:41:46 +04:00
Dan Travison 053d180817 Add exports for syslog APIs in 'libpsl-native'. (#5149) 2017-10-20 09:03:59 -07:00
Dave Wyatt 1c469aaa22 Unwrap 'ValueFromRemainingArguments' if the single element is a collection (#5109)
Unwrapping of 'ValueFromRemainingArguments' was being performed only for 'object[]' arrays (which covers the most common PowerShell binding scenarios) but could be skipped if a collection of any other type were passed to the parameter. This change unwraps 'ValueFromRemainingArguments' if the single element is a collection.
2017-10-19 16:44:26 -07:00
Steve Lee e908b8a607 Enable import-module to be case insensitive (#5097)
Fix #1621 

Enable import-module to be case insensitive as macOS is case insensitive.
2017-10-19 14:44:21 -07:00
Steve Lee 847846d834 [feature] (#4960)
remove -computer support since corefx Process.GetProcesses(computer) returns local processes
2017-10-18 15:49:45 -07:00
Dongbo Wang 2ceec725f6 Fetch resource string correctly (#5114) 2017-10-18 11:36:25 -07:00
Travis Plunk db6aec0850 Add compiler switches replace dangerous function with safer ones. (#5089)
* Add compiler switches replace the dangerous function with safer ones.
* Add -02 and make linker flags per platform
* add -O2 for arm and add -z,now
* remove windows linker flags
2017-10-18 10:08:11 -07:00
Chunqing Chen dd5fba3313 Exclude PSHostProcess cmdlets from Unix platforms (#5105)
- Exclude 'Get-PSHostProcessInfo', 'Enter-PSHostProcess' and 'Exit-PSHostProcess' from Unix platforms.
- Update tests and add additional cmdlets need to be excluded
2017-10-18 09:26:24 -07:00
Steve Lee 6177d28410 removed RunspaceConfiguration support (#4942)
For PSCore 6, we are only supporting InitialSessionState. The RunspaceConfiguration APIs were already made internal. This PR removes all the code related to RunspaceConfiguration. This also means that some public APIs have changed. Was deciding between leaving the RunspaceConfiguration parameters and throwing Unsupported, but thought it was better to have it a compile-time error. This should simplify the code base.
2017-10-18 09:12:23 -07:00
Dominic 81c46c6e51 Fix MatchInfoContext clone implementation (#5121)
The old implementation always set the new object's properties to null.
2017-10-17 20:53:29 -07:00
Mark Kraus 7c9bddfa3d Add Authentication Parameter to Web Cmdlets for Basic and OAuth (#5052)
Closes #4274

Adds an -Authentication parameter to Invoke-RestMethod and Invoke-WebRequest
Adds an -Token parameter to Invoke-RestMethod and Invoke-WebRequest
Adds an -AllowUnencryptedAuthentication parameter to Invoke-RestMethod and Invoke-WebRequest
Adds tests for various -Authorization uses
-Authentication Parameter has 3 options: Basic, OAuth, and Bearer
Basic requires -Credential and provides RFC-7617 Basic Authorization credentials to the remote server
OAuth and Bearer require the -Token which is a SecureString containing the bearer token to send to the remote server
If any authentication is provided for any transport scheme other than HTTPS, the request will result in an error. A user may use the -AllowUnencryptedAuthentication switch to bypass this behavior and send their secrets unencrypted at their own risk.
-Authentication does not work with -UseDefaultCredentials and will result in an error.
The existing behavior with -Credential is left untouched. When not supplying -Authentication, A user will not receive an error when using -Credential over unencrypted connections.

Code design choice is meant to accommodate more Authentication types in the future.

Documentation Needed

The 3 new parameters will need to be added to the Invoke-RestMethod and Invoke-WebRequest documentation along with examples. Syntax will need to be updated.
2017-10-17 19:08:06 -07:00
Steve Lee 2cc091115b Rename powershell.exe to pwsh.exe (#5101)
- Rename powershell.exe to pwsh.exe
- Fixe appveyor.psm1
- Update MSI to include 'pwsh' in path and app paths
- Revert change for hyper-v powershell direct
- Update names in packaging.psm1.
- Fix check for SxS
2017-10-17 17:25:11 -07:00
Ilya f604b0e3f0 Merge pull request #4995 from SteveL-MSFT/remove-apartmentstate
* wrapped STA code sections in `#if STAMODE` for potential future use
removed -importsystemmodules switch from powershell.exe and related code
removed -consolefile parameter from powershell.exe and related code

* removed font and codepage handling code that is only applicable to Windows PowerShell
replaced LengthInBufferCells() method with Unicode adapted code from PSReadline

* removed `#if CORECLR` statements merging code base

* [feature]
removed code to show a GUI prompt for credentials as PSCore6 prompts in console

* Remove unncessary method 'LengthInBufferCellsFE'
2017-10-17 09:31:49 +04:00
Steve Lee 173380b9c7 Remove unncessary method 2017-10-16 16:55:50 -07:00
Steve Lee 88313705bd Change location of ModuleAnalysisCache so it isn't shared with Windows PowerShell (#5133)
Currently, it's using the same location as Windows PowerShell and the two should not be sharing one as the PSModulePaths are different between the two.
2017-10-16 14:31:29 -07:00
Travis Kinney 52f9125aba StopJobCommand: Remove Unreachable Code (#5091)
This code will never get executed, and its logic is
duplicated in the HandleStopJobCompleted() method.
2017-10-16 10:06:32 -07:00
Dongbo Wang f2eaeb8b8e Remove '-ComputerName' from 'Get/Set/Remove-Service' (#5094) 2017-10-13 22:06:46 +04:00
Chunqing Chen 07d3b1806c Get-Content -Raw should not neglects to read the last character, if it is a LF (#5076) 2017-10-13 11:05:51 +04:00
Tadas Medišauskas 844bf11dde Get-Verb: add verb descriptions and alias prefixes (#4746)
* Get-Verb: add descriptions and prefixes

* Add description and alias prefix tests

* Make the new classes internal

* Convert alias prefix to static method

* Move verb descriptions to a resource file

* Shorten function name

* Shorten alias prefix function name

* Change tests to look at counts

* Add uniqueness test

* Add missing alias prefixes

* Fix name collision

* Change alias prefix for Compare

* Rename method

* Remove unnecessary string allocation

* Make tests easier to diagnose
2017-10-12 14:40:06 -07:00
Steve Lee 6ca5d51782 [feature]
removed code to show a GUI prompt for credentials as PSCore6 prompts in console
2017-10-12 10:19:18 -07:00
Steve Lee 5bd8dd351f removed #if CORECLR statements merging code base 2017-10-12 10:18:24 -07:00
Steve Lee 46cdd7ec13 removed font and codepage handling code that is only applicable to Windows PowerShell
replaced LengthInBufferCells() method with Unicode adapted code from PSReadline
2017-10-12 10:17:13 -07:00
Steve Lee 856c2af3fe wrapped STA code sections in #if STAMODE for potential future use
removed -importsystemmodules switch from powershell.exe and related code
removed -consolefile parameter from powershell.exe and related code
2017-10-12 10:14:45 -07:00
Dave Wyatt 94a71b05d4 Fix ValueFromRemainingArguments to have consistent behavior between script and C# (#2038) 2017-10-11 17:09:59 -07:00
Mark Kraus f6864c3def Change to Read/Write Neutral Progress Messages for Web Cmdlets WriteToStream() (#5078)
* Create read/write neutral progress messages
2017-10-11 18:05:55 +04:00
Steve Lee 59311d03e1 Properly escape trailing backslash so that it doesn't end up escaping the quotes (#4965)
The native command receives the arg ".\test 1" as  .\test 1"  as the last  \"  is treated as escaping the quotes. Fix is to add an extra backslash to escape the last enclosing quote.
2017-10-11 18:01:09 +04:00
Raghav S 7dd36c9e34 Add NoNewLine switch for Out-String cmdlet (#5056) 2017-10-11 17:44:57 +04:00
Dongbo Wang 983409f80e Remove PSMI (#5075) 2017-10-10 11:31:59 -07:00
David Weber aea561f08d Add better error message for empty and null -UFormat arg (#5055)
Add better error message for empty and null -UFormat arg
2017-10-10 07:19:02 +04:00
Jason Shirk 22662c8c56 Remove dead code (#5066)
Code guarded by the following defines is ancient and has never been
used, so removing.
* RELATIONSHIP_SUPPORTED
* SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
* SUPPORTS_CMDLETPROVIDER_FILE
Also removed some unused platform dependent unsafe code.
2017-10-09 17:28:10 -07:00
Dongbo Wang 55ce5dc86e Update script to get PSVersion from $PSVersionTable (#5045)
* Update script to get PSVersion from $PSVersionTable

* Address feedback

* Address cleanup comments

* Add back 'Remove-Item .\$fileName'

* Add the comment back too
2017-10-09 16:13:15 -07:00
Steve Lee 90165fc17c enable using filesystem from a UNC location (#4998)
* enable using filesystem from a UNC location

* [feature]
address PR feedback

* [feature]
removed changed in NavigationProviderBase and made change in FileSystemProvider where it should belong

* added variations of tests for set-location and push-location
no need to run [feature] anymore since it passed previously and the test case added is CI

* [feature]
move code to reproduce UNC path to GetParentPath()
2017-10-09 14:05:16 -07:00
Steve Lee ff59be3c61 fix detection of whether -LiteralPath was used to suppress wildcardexpansion for navigation cmdlets (#5038)
* [feature]
fix detection of whether `-LiteralPath` was used to suppress wildcardexpansion

* [feature]
skip -literalpath test with asterisk in filename as that's not valid on Windows

* [feature]
added more variations of tests
2017-10-09 09:33:22 -07:00
Travis Kinney 1d5c310897 SetServiceCommand: Add positional parameter attribute (#5017)
* SetServiceCommand: Add positional parameter attribute

Added a positional parameter attribute to the InputObject parameter,
giving Set-Service behavior similar to the other *-Service cmdlets.

* Add test for positional InputObjects [Feature]

Added a test to Set-Service validating InputObjects passed positionally.
2017-10-09 09:30:50 -07:00
Lucas Spits e1a0cafee8 User Agent now reports the OS platform (#4937)
Also include '<major>.<minor>' in UserAgent on windows platform.
2017-10-06 13:59:31 -07:00
Steve Lee 50607b9751 Enable support of folders and files with colon in name on Unix (#4959)
* [feature]
support folders and files with colon in name

* [feature]
only check separator in relation to colon if a colon is found

* [feature]
added comment to clarify algorithm

* added more tests
2017-10-06 11:27:15 -07:00
Mark Kraus 9843ef1ce5 Correct comma position in SecureStringCommands.resx (#5033)
The comma and the space needed to be swapped.
2017-10-06 11:01:45 -07:00
Ilya 50f6667bdb Cleanup Json cmdlets (#5001) 2017-10-06 09:03:53 -07:00
Steve Lee ba7dfcc0d0 Fix powershell to update the PATH environment variable only if PATH exists (#5021) 2017-10-05 14:23:52 -07:00
Ilya 87b34fe8cb Reformat command line help for powershell -Help (#4989) 2017-10-05 12:49:29 -07:00
Steve Lee 7f94412170 removed leading whitespace (#4991)
Add an optional extended description…
2017-10-04 08:14:26 +04:00
Paul Higinbotham 5b54e4d30f Fix for Linux platform PowerShell exit on error during SSH remoting connection (#4993)
* Fix for Linux platform PowerShell exit on error during SSH remoting connection

* Added comment for clarification per code review request
2017-10-03 18:19:45 -07:00
Indhu Sivaramakrishnan 417e988939 Merge pull request #4979 from Indhukrishna/insivara/UpdatePSDesiredStateConfiguration/1710
Update version of PSDesiredStateConfiguration in project files
2017-10-02 21:05:20 -07:00
Indhu Sivaramakrishnan 801f21bec3 Update version of PSDesiredStateConfiguration in project files 2017-10-02 16:06:22 -07:00
Aditya Patwardhan 1e271ea187 Add Remoting and Job tests (#4928) 2017-10-02 13:43:43 -07:00
Steve Lee d73e97464c Fix incorrect position of a parameter which resulted in the args passed as input instead of as args (#4963) 2017-10-02 12:15:42 -07:00
Jeffrey Snover d8a075e484 Provide the correct form for foreach when there is an error. (#4950)
* Update ParserStrings.resx

* Provide the proper form for foreach

* added "{...}"
2017-10-02 10:12:52 -07:00
Steve Lee 2e901e53c3 fix powershell -version and help (#4958)
PowerShell -v  behavior updated to align with other tools like git, curl, and bash where args after  -v  are silently ignored.

Built-in help updated to reflect changes we've made to the console host in PSCore6 removing unsupported parameters.

* [feature]
removed test that is no longer valid due to change in -version behavior to return error

* [feature]
fixed `-v X` so that it errors out correctly with proper exit code
updated test to catch this

* [feature]
address PR feedback

* [feature]
make -v have behavior consistent with other tools like git, curl, bash where args after -v are ignored
removed duplicate but not exactly help text that wasn't being used in the resource file
removed parameters from help that are not support in PSCore6
2017-10-01 07:39:18 +04:00
Steve Lee a82f6376ab Change CRLF to LF for files that are already in repository (#4956) 2017-09-29 17:43:57 -07:00
Dongbo Wang a4b8dd0a23 Remove Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll (#4868)
The code in `AssemblyLoadContext.dll` doesn't need to be in a separate DLL anymore.
S.M.A.dll depends on `AssemblyLoadContext.dll`, so keeping that code out of S.M.A.dll doesn't help make S.M.A smaller size or less dependent. So the code in `AssemblyLoadContext.dll` is moved to `S.M.A.dll` and then we remove `AssemblyLoadContext.dll`.

The changes are:
- Move `CorePsAssemblyLoadContext.cs` to `src\S.M.A\CoreCLR\`
- Update `CorePsAssemblyLoadContext.cs` to get the test took moved to `Utils.InternalTestHooks` and update tests
- Update `build.psm1` and `.csproj` accrodingly
- Update `pwrshcommon.cpp` to remove `AssemblyLoadContext.dll` from the TPA list.
- `S.M.A.AssemblyExtensions` is removed as `PackageManagement` has finished their move to .NET Core 2.0. (I will work with Bryan to get the latest version uploaded to powershell-core)
2017-09-29 17:26:55 -07:00
Steve Lee 2639cd89ce Autocorrected CRLF to LF (#4943)
Also, fix `Parser.Tests.ps1` after correcting CRLF.
2017-09-29 16:28:15 -07:00
Ilya 757c6b5f39 Write an error for powershell -version 2 (#4931)
Write an error for powershell -version <any value>
2017-09-29 23:20:28 +04:00
Jeffrey Snover b9845d5ec1 Add a new line to 'CommandNotFoundException' error string (#4934)
We're here at PowerShell Unplugged at Ignite, and this error message could *really* use a new line!
2017-09-29 12:16:05 -07:00
Chunqing Chen e3a004c036 Change PS to load the assembly with 'Assembly.LoadFrom' before 'Assembly.Load' when the file path is given (#4196)
It's to solve a side-by-side problem we have with powershell core. If a .NET Core version assembly has the same name as it's .NET ancestor in GAC, then even if you specify the file path to `Import-Module`, powershell core will still load the one in GAC because it tries 'Assembly.Load' first.
Now we change it to use `Assembly.LoadFrom` first when a file path is given, so it works for modules that have side-by-side assemblies.
2017-09-29 11:58:56 -07:00
Ilya b07f24e3c9 Exclude '-Comobject' parameter of 'New-Object' on unsupported platforms (#4922) 2017-09-28 17:29:33 -07:00
Steve Lee 99e3fe586e Enable transcription of native commands on non-Windows (#4871)
Transcription was relying on reading the screen buffer to record output from native commands.
This resulted in an unhandled exception calling an unimplemented API on non-Windows.
The fix is to use redirected output/error if reading the screen buffer is not supported.
We check whether screen scraping is supported or not only when the application is running standalone.
2017-09-28 17:15:37 -07:00
Ilya 6e77537181 Get 'PSVersion' and 'GitCommitId' from the 'ProductVersion' attribute of assembly (#4863) 2017-09-28 09:27:43 -07:00
Steve Lee ffa0701200 remove unsupported -showwindow switch (#4903) 2017-09-27 17:51:56 -07:00
Travis Plunk df1993aad0 Enable security flags in native compiler (#4933)
* Enable strong stack protection
Enable  address space layout randomization (ASLR) or PIE

* Enable strong stack protection
Enable  address space layout randomization (ASLR) or PIE
2017-09-27 15:35:23 -07:00
Mark Kraus a8e8b1f8e4 Change UserAgent App WindowsPowerShell -> PowerShell (#4914)
* Change UserAgent App WindowsPowerShell -> PowerShell

* [Feature] Run Feature tests

* [feature] Address PR Feedback with more precise assertion

* [feature] Address PR Feedback and add PSUserAgent Test

* [feature] add tag to describe block

* [feature] Remove describe block Add pattern to User-Agent specific tests

* [feature] Address PF Feedback

Remove all assertions for User-Agent that are not specifically about the User-Agent header.

* [feature] Match -> MatchExactly
2017-09-27 07:44:20 -07:00
Steve Lee efbdea5cfe Fix importing remote module using version filters and added tests (#4900)
- Add tests for remote import-module
- Fix issue with remotely importing module where it was checking the version filter incorrectly against the proxy module
   - The filters are applied when importing the module remotely
   - After proxy module is generated it always has a module version of 1.0, so the filters will always fail when importing the proxy locally
2017-09-25 21:37:56 -07:00
Steve Lee 901a61bcc1 Enable auto EOL on git repo side, fix some character encoding issues (#4912)
- add ending newline to files missing it using:
`awk -F: '$2 ~ / no line terminators/ {print $1}' ~/text-files.txt | xargs -I{} sh -c 'printf "\n" >> "$1"' - {}`
- update .gitattributes to enforce autocrlf on all text files
- added <copyright> opening element where it was missing
removed file attribute pointing to wrong filename
- fix mis-encoded character to apostrophe
- replace incorrect encoding of copyright symbol with (c)
- updated file hashes in the test
2017-09-25 15:14:39 -07:00
Dongbo Wang bb3a840e76 Create generic Linux-x64 packages that are portable to all supported Linux distros (#4902) 2017-09-25 12:49:43 -07:00
Steve Lee 65415c3b9e allow * to be used in registry path for remove-item (#4866)
* [feature]
allow * to be used in registry path for remove-item

* [feature]
address PR feedback
have remove-item return error if -literalpath doesn't resolve to path

* [feature]
fix in navigation exposed an issue with WSMan Config Provider tests
that require -Recurse to be used otherwise a confirmation prompt shows
up
2017-09-25 10:15:38 -07:00
Mark Kraus 3237d43b26 Add ResponseHeadersVariable Parameter to Invoke-RestMethod (#4888)
* Add ResponseHeadersVariable to Invoke-RestMethod

* Add Tests for -ResponseHeadersVariable

* [Feature] Run Feature Tests

* Remove test to address PR feedback

* Alais HV -> RHV per request

* [Feature] Rerun CI

* [Feature] Remove Superfluous Assertion
2017-09-25 10:11:12 -07:00
Ilya 93dc591025 Add 'ArgumentCompletionsAttribute' to support more argument completion scenarios (#4835)
- Add 'ArgumentCompletionsAttribute' to support argument completion for parameters that cannot have a ValidateSetAttribute.
- Use 'ArgumentCompletionsAttribute' for the '-Format' parameter of 'Get-Date' to enable useful argument compeltions.
2017-09-21 10:52:21 -07:00
Mark Kraus 5e24352177 Initialize Headers Dictionary Only Once (#4853)
Switch the  WebResponseObject.Headers Dictionary to initialize once instead of creating a new dictionary on every get. Moved logic to  WebResponseHelper.GetHeadersDictionary()  as this code will be reused outside of  WebResponseObject .

* [Feature] Create Headers Only Once and Only If Called

* {feature] headers -> _headers

* [Feature] Move logic to WebResponseObject for reuse

This code has potential reuse in InvokeRestMethodCommand. Moving it to WebResponseHelper

* Add comment to address PR Feedback.
2017-09-21 12:41:57 +04:00
Dongbo Wang b81aeb4b64 Remove remainder of Utility.Activities (#4880) 2017-09-20 17:27:08 -07:00
Jonas Andersen f281671375 [Feature]Added Remove-service to Management module (#4858)
* [Feature]Remove-Service added to Management module

* [Feature]Capitalization

* [Feature]Added test cases for Remove-Service, Removed return value

* [Feature]Documentation from copy-paste code corrected to reflect the new function

* [Feature]Erroraction to be sure that an error is thrown in testcase

* [Feature]Removed direct reference to module in Pester test

* [Feature]Removed extra line in test

* [Feature]Use FullyQualifiedErrorId in Remove-Service test without a valid servicename

* [Feature]Exposed Remove-Service

* [Feature]Consistent casing, Named Arguments & Remove incorrect exception on cleanup

* [Feature]Remove-Service test should fail if the service was not removed

* [Feature]Cleanup comments & add Remove-Service for CI

* [Feature]Remove-Service in CI set in alphabetic order

* [Feature]Use ParameterSetName instead of _ParameterSetName and rewrite test which used the function class directly

* Revert "[Feature]Use ParameterSetName instead of _ParameterSetName and rewrite test which used the function class directly"

This reverts commit da41f7deb8.

* [Feature]Remove _ParameterSetName check & added test for pipeline input in
Set-Service
2017-09-20 17:24:39 -07:00
Travis Plunk 4c6ad4a133 Revert the changes to Pester from merged PR #4184 (#4881)
That PR incorrectly included Pester changes. Most likely because that individual did not update his submodules.
2017-09-20 16:08:29 -07:00
Dongbo Wang 4c29f5768d Fix bugs with expression redirected to file (#4847)
When handling file redirection for CommandExpression, we don't call 'DoComplete' on the underlying PipelineProcessor of the FileRedirection object, and thus the EndProcessing method is not called on Out-File, which causes different behaviors between <expr> > out.txt and <expr> | Out-File out.txt.

The fix is to make sure 'DoComplete' is called after the stream output has been written to the redirection pipe.

Also fix another issue

This PR also fixes an issue that could mess up restoring the original pipes. Here is the repro:

PS> 1 *> b.txt > a.txt; 123
Cannot perform operation because object "PipelineProcessor" has already been disposed
The root cause is that we don't always restore pipes in the correct order. Please see the code changes in Compiler.cs for more details.

Fix #4812
2017-09-20 14:39:02 -07:00
Staffan Gustafsson 916ef56eeb Call to CodeMethod returning void should work (#4850)
Fixes #4826
2017-09-20 14:37:43 -07:00
Jason Shirk de70969f4e Add VS 2017 solution file for powershell-win-core (#4748) 2017-09-18 17:13:29 -07:00
Steve Lee 23420643e3 Added WSMan Config provider tests (#4756)
* [Feature]
fixed issues in WSMan Config Provider
added tests for get-item, get-childitem, set-item, new-item remove-item, clear-item, dynamic parameters
merged CoreClr and FullClr code

* [feature]
address PR feedback

* [feature]
revert to using microsoft.powershell plugin as base for test
keeps it simple rather than relying on additional scripts or cmdlets since these tests don't require remoting

* [feature]
address Aditya's feedback

* [feature]
address some cosmetic feedback

* [feature]
based on discussion with Jim, we should skip resx checks on non-Windows
2017-09-18 15:44:09 -07:00
Dongbo Wang 192803bfcf Build powershell core using the generic RID 'linux-x64' (#4841) 2017-09-18 09:31:07 -07:00
James Truher [MSFT] 0229451148 Validate product resource strings against resx files (#4811) 2017-09-18 09:20:46 -07:00
Jonas Andersen b7ec5da216 Added functionality to set credientials on Set-Service command (#4844)
Now we can specifiy the -Credential parameter on Set-Service cmdlet to change a service's logon account.
2017-09-18 14:23:17 +04:00
Lucas Spits 03e3257b0a Updated default ModuleVersion in ModuleManifest (#4842)
* Updated default ModuleVersion in ModuleManifest to 0.0.1

* updates tests where manifests default versions where still matched agianst the old 1.0 version
2017-09-15 11:44:07 -07:00
Steve Lee b723d6b7f2 fix set-service failing test (#4802)
* Add '-ErrorAction Stop' in Set-Service.Tests.ps1 to correctly test exceptions.
* Refactor StartupType service code and add a throw for disabled startup types (System, Boot).
* Made StartupType(-1) equivalent to Win32 SERVICE_NO_CHANGE.
2017-09-15 12:24:40 +04:00
Ilya a4cdb806f4 Exclude directories discovered from '-Path' in Select-String (#4829)
Select-String can search in files only so we should skip directories.
2017-09-14 14:57:17 -07:00
Mark Kraus fd3a003765 Add Multipart Support to Web Cmdlets (#4782)
Partially implements  #2112
- Adds `System.Net.Http.MultipartFormDataContent` as a possible type for `-Body`
- Adds `/Multipart/` test to WebListener 

This allows for the user to create their own `Http.MultipartFormDataContent` object and submit it. Since `multipart/form-data` submissions are highly flexible, adding direct support for it to the CmdLets may over-complicate the command parameters and a limited implementation would not address the broad scope of use cases. This at least allows the user to submit multipart forms using the Web Cmdlets and not have to manage their own `HttpClient`. Once this is introduced, limited multipart implementations can be expanded to use the code in this PR.
2017-09-12 09:41:36 -07:00
Paul Higinbotham f95b8aca86 [Regression] Fix for error on Enter-PSSession exit (#4693)
* Fix for error on Enter-PSSession exit

* Added comments per code review feedback

* Updated comment
2017-09-11 17:49:28 -07:00
Littlejohn bbc180a918 Added Meta, Charset, and Transitional parameters to ConvertTo-HTML (#4184) 2017-09-11 12:22:10 -07:00
Steve Lee 6f1c7a05c6 Enable cross compiling for raspberry-pi arm32 (#4742) 2017-09-11 12:16:58 -07:00
Dongbo Wang db33d90479 First round of workflow cleanup (#4777)
This round of cleanup focuses on the following areas
- Tab completion code
- InitialSessionState
- Compiler/MiscOps
- Utils/SessionStateFunctionAPIs
Changes in the rest affected files are mainly some corresponding changes due to the cleanup work in the above areas.
2017-09-11 08:55:13 -07:00
Ilya fc9d798b77 Enable use 'Singleline,Multiline' option in split operator (#4721)
Fix #4712
2017-09-08 09:23:38 -07:00
Sarith Sutha f4b075c856 Add -WhatIf switch to Start-Process cmdlet (#4735)
* Add -WhatIf switch to Start-Process cmdlet
* Add test for the -WhatIf switch 

* Added a test to ensure that using a whatif switch prevents the action from being performed.

* Incorporated code review comments

* merged two tests into one as suggested

* Included the error action at the end of the cmdlet

* Remove extra space before `StringUtil` and new line

* Renamed the resource string id ProcessStartInfo to StartProcessTarget
2017-09-08 09:18:13 +04:00
Ilya 3c597367ba Replace 'Windows PowerShell' with 'PowerShell' in resx files (#4758)
Replace 'Windows PowerShell' with 'PowerShell' in '.resx' files where appropriate.
2017-09-07 12:33:56 -07:00
Steve Lee 7c9b188c13 Rename $IsOSX to $IsMacOS (#4757) 2017-09-07 10:34:40 -07:00
Dongbo Wang 41f12b1d2c Push locals of automatic variables to 'DottedScopes' when dotting script cmdlets (#4709)
When dotting a script cmdlet, the locals of automatic variables from the `PSScriptCmdlet` is not set up in the current scope before parameter binding. The fix is to push the locals in `CommandProcessor.OnSetCurrentScope` and pop them in `CommandProcessor.OnRestorePreviousScope`, which will be called from `SetCurrentScopeToExecutionScope` and `RestorePreviousScope` respectively.

Summary of changes:
1. When a new local scope is used, currently we set the locals for `CommandProcessor` right before parameter binding (in `BindCommandLineParametersNoValidation`); we set the locals for `ScriptCommandProcessor` in `Prepare`. I moved both to the constructor, right after the new scope is created so that the code is more consistent.

2. In `CmdletParameterBinderController.cs`, we set up the `PSBoundParameters` and `MyInvocation` variables in `HandleCommandLineDynamicParameters` again, which I think is unnecessary because this method is only called from `BindCommandLineParametersNoValidation`, where the setup is done for the first time.

3. Currently, the locals will be set for dotted script cmdlet in `EnterScope()` and `ExitScope()`. Now, that logic is moved to `OnSetCurrentScope` and `OnRestorePreviousScope` of `CommandProcessor`. This not only makes sure that locals are set before parameter binding, but also is consistent with the `ScriptCommandProcessor`.
2017-09-06 10:25:33 -07:00
Steve Lee fb286e6cf8 Removed double spaces from .cs and .ps1 files (#4743) 2017-09-04 19:45:51 -07:00
Ilya fb67072479 Fix error message in ValidateSetAttribute ValidateElement() (#4722) 2017-09-04 09:11:47 -07:00
Kory Gill c14648e7a8 Remove double spaces between words in resx files (#4741) 2017-09-03 20:48:08 +04:00
Steve Lee 2f34009328 added new approved Build and Deploy verbs (#4725)
- Added Build and Deploy verbs, updated suggestions
- Reorganized verbs to be in alphabetical order making it easier to compare against https://msdn.microsoft.com/en-us/library/ms714428(VS.85).aspx
2017-09-01 17:41:07 -07:00
Michael Klement 1de749fbaa Fix for Get-Content -Delimiter including the delimiter in the array elements returned (#3706) - functional changes 2017-09-01 13:01:43 -07:00
Ilya 58a296ed49 Ensure GetNetworkCredential() returns null if PSCredential has null or empty user name (#4697)
* GetNetworkCredential() returns null if PSCredential has empty user name

* Fix test
2017-09-01 11:50:15 -07:00
Dongbo Wang 795de73d31 Fix 'using module' when module has non-terminating errors handled with 'SilentlyContinue' (#4711)
`Compiler.LoadModule` assumes that when `ps.HadErrors == true` the error stream is not empty. However, when `SilentlyContinue` is specified as the error action, the non-terminating error is not kept in `ErrorOutputPipe` of the cmdlet and thus does not appear in `ps.Streams.Error`. So when `ps.HadErrors == true` while `ps.Streams.Error` is empty, it suggests it's OK to ignore the errors because they are explicitly suppressed with `SilentlyContinue` error action.

So in my opinion, the expected behavior of `"using module .\mod.psm1"` in this case should be successful as if `ps.HaddErrors` is false.
2017-09-01 08:54:08 -07:00
Dan Travison 96a90f8985 Add explicit ContentType detection to Invoke-RestMethod (#4692)
This change removes the call to `ContentHelper.GetEncoding` since it's logic for returning a default encoding when a ContentType header is not found disables subsequent checks for meta charset definitions.
All variations of the Invoke-WebRequest tests have been mirrored for Invoke-RestMethod. Verbose output is used to verify the encoding since Invoke-RestMethod returns the JSON content directly instead of a response object. (See ExecuteRestMethod)
2017-08-31 10:47:54 -07:00
Steve Lee dc399a121b clean up coreclr/fullclr statements in tracesource (#4684) 2017-08-29 09:09:24 -07:00
Steve Lee deb8c4485d Remove alternate file stream code from non-Windows (#4567)
* AlternateStreams support relies on pinvoke to win32 APIs which don't work on non-Windows and produces errors about not loading a DLL in the case of copy-item
* Address PR feedback, remove -Stream parameter for Unix added new -stream tests
* if/def out alternate stream syntax checks not applicable to Unix
2017-08-28 15:39:42 -07:00
Chunqing Chen fe51fb7f60 Make 'Test-ModuleManifest' not load unnecessary modules (#4541) 2017-08-28 15:36:46 -07:00
Dongbo Wang 12002e7f2d Use stricter rule to unwrap a PSObject that wraps a COM object (#4614)
GetMember/SetMember/InvokeMember operations on a COM object will generate code to unwrap the COM object if it's wrapped in PSObject. Due to a loose restriction, if you have a string wrapped to a PSObject with an ETS member of the same name, then the string PSObject will be unwrapped too and the ETS member will be lost. The fix is to use a more restricted rule by checking if the base object is a COM object.
2017-08-28 13:19:02 -07:00
Steve Lee 1e0acfac5e removed appending WindowsPowerShell PSModulePath (#4656) 2017-08-25 11:05:23 -07:00
Dongbo Wang cfe173ac0e Replace extension method 'IsComObject(this Type)' with Type.IsCOMObject (#4646) 2017-08-22 17:44:48 -07:00
Ilya cdbbb7a4bb Minor formatting commits for Build.psm1 and csproj files (#4630) 2017-08-21 15:23:52 -07:00
Mark Kraus 297bba3fa1 Add support for Content Headers to BasicHtmlWebResponseObject and HtmlWebResponseObject (#4494) 2017-08-21 10:48:25 -07:00
Mark Kraus 1b23a62ae1 [Feature] Add Certificate Authentication Support for WebCmdlets (#4546)
* [Feature] Add Certificate Authentication Support for WebCmdlets

PowerShell/PowerShell#4544

* Add Certificate  Comments

* Set Certificate Options

* [feature] Post-rebase White-space correction

* [feature] mark certauth tests pending
2017-08-18 13:56:31 -07:00
Dongbo Wang befc5f8ae1 Make PowerShell Core enumerate COM collections (#4553)
Make PowerShell Core enumerate COM collections
2017-08-17 20:23:36 +04:00
Ilya 45d1d20500 Merge pull request #4573 from SteveL-MSFT/console-no
* Make invalid arg to -File consistent with -Command
Improve error message if ambiguous arg is passed to -File

* Update powershell console exit codes to match Unix standards

* Enable -WindowStyle to work
2017-08-17 07:34:02 +04:00
Dongbo Wang c47ebea9ec Remove workflow related modules (#4581) 2017-08-16 17:36:05 -07:00
Dongbo Wang 580fb7baf5 Remove src\Microsoft.PowerShell.Activities (#4582) 2017-08-16 17:35:36 -07:00
Dongbo Wang 55fe5263e4 Remove src\Microsoft.PowerShell.Core.Activities (#4583) 2017-08-16 17:35:24 -07:00
Dongbo Wang d75065c874 Remove src\Microsoft.PowerShell.Diagnostics.Activities (#4584) 2017-08-16 17:35:10 -07:00