Commit graph

2385 commits

Author SHA1 Message Date
Dan Travison 5488131931 remoting: Handle DLLImport failure of libpsrpclient (#5622)
Issue #4029 exposed two problems when failing to load libpsrpclient.

WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport; hindering diagnosability
PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.
This change addresses both of the above:

Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.

Diagnosability: Log the DllNotFoundException in WSManAPIDataCommon ctor and also include it as the internal exception when throwing PSRemotingTransportException.
2018-01-04 13:08:33 -08:00
Dongbo Wang ad231a8a7f
Make minor fixes in Compiler to properly handle void type expression (#5764) 2018-01-02 09:25:29 -08:00
Ilya 7257404929
Add Count and Length properties to [PSCustomobject] (#5745)
Related #3671
•Add Count and Length properties to [PSCustomobject].
 Now following returns 1:
 ([pscustomobject] @{ foo = 'bar' }).Count
 ([pscustomobject] @{ foo = 'bar' }).Length
•Add tests
2017-12-28 10:15:06 +04:00
Steve Lee e2dc0eafbc build: Enable building for win-arm and win-arm64 (#5524)
* enable win-arm and win-arm64 builds

* fix using arm64 tools for build
fix finding vs2017 dynamically

* change install-powershellremoting.ps1 script to use reg provider rather than reg.exe so that error doesn't show on success
fix formatting issue in cmake.defs

* add check that path being read from config file is valid
address PR feedback

* fix copying of PowerShell.Core.Instrumentation as VS2017 puts it in $HOME/source
address PR feedback
2017-12-10 10:29:53 -08:00
Steve Lee eb254280fb build: Enable building for win-arm and win-arm64 (#5524)
* enable win-arm and win-arm64 builds

* fix using arm64 tools for build
fix finding vs2017 dynamically

* change install-powershellremoting.ps1 script to use reg provider rather than reg.exe so that error doesn't show on success
fix formatting issue in cmake.defs

* add check that path being read from config file is valid
address PR feedback

* fix copying of PowerShell.Core.Instrumentation as VS2017 puts it in $HOME/source
address PR feedback
2017-12-08 15:43:53 -08:00
Dongbo Wang d4e802148c Remove 'oldPowershellExeName' and 'oldPowershellDepsName' (#5408) 2017-12-07 10:28:16 -08:00
Travis Plunk c44ddfd6fe build: unbundle pester (#5623)
# Conflicts:
#	tools/appveyor.psm1
#	tools/travis.ps1
2017-12-06 16:13:26 -08:00
Dongbo Wang 4f4d7797f7 Remove 'oldPowershellExeName' and 'oldPowershellDepsName' 2017-12-06 14:11:07 -08:00
Mark Kraus c3ac21bbaf Combine Web Cmdlet Partial Class Files (#5612)
Reference #5610

This moves the partial class into a single file each. This code is purposely not sorted and the formatting is left alone to make this easier to review. There are cleanup actions planned in the referenced Issue.
2017-12-04 17:49:33 -08:00
Travis Plunk 25617f15c2 build: unbundle pester (#5623)
* remove pester module

* restore Pester as a module only in CI build from the git repo

* mark appveyor builds as CI builds

* remove pester exclusions

* mark travis builds as ci

* exclude publish folder from spell check

* do not run spell check on publish folder
2017-12-04 17:16:53 -08:00
Staffan Gustafsson a9c6292903 Enable conversions from PSMethod to Delegate (#5287)
Underpinnings to make calling of Extension methods /Linq easier from PowerShell.
Enables the following that previously had to be done via reflection.

class M {
  [int] Twice([int] $value) { return 2 * $value }

  [int] DoubleSum([int[]] $values) {
     return [Linq.Enumerable]::Sum($values, [M]::Twice)
  }
}

Each PSMethod is created as with a unique type for the combinations of method signatures in the MethodInfos it represents.

PSMethod<T> where T is a MethodGroup<>, potentially recursive in the last template argument.

This way, we can determine by just looking at the type of a PSMethod if there exists a conversion from the PSMethod to a delegate.
2017-12-01 18:40:35 -08:00
Steve Lee 2b7c22335f Remove unncessary check for Paths.count > 0 as there is code later to use the current (#5596)
Remove unnecessary check for Paths.count > 0 as there is code later to use the current working directory since -Path is not a mandatory parameter.
Updated ShouldProcess to output the internal action on adding paths rather than the user action (which is the cmdlet name).

Updated tests to not specify -Path

Fix #5594
2017-12-01 17:34:30 -08:00
Dongbo Wang 130ec8bb81 Skip null-element check for collections with a value-type element type (#5432)
* Fix NotNullOrEmpty check logic

* Fix a test issue on Unix
2017-12-01 17:34:30 -08:00
Dan Travison fef44277ee Use explicit libpsl-native binary name for dllimport. (#5580) 2017-12-01 17:34:30 -08:00
Steve Lee b69ff717ab Remove unncessary check for Paths.count > 0 as there is code later to use the current (#5596)
Remove unnecessary check for Paths.count > 0 as there is code later to use the current working directory since -Path is not a mandatory parameter.
Updated ShouldProcess to output the internal action on adding paths rather than the user action (which is the cmdlet name).

Updated tests to not specify -Path

Fix #5594
2017-12-01 10:57:00 -08:00
Dongbo Wang b5f84c2b39 Skip null-element check for collections with a value-type element type (#5432)
* Fix NotNullOrEmpty check logic

* Fix a test issue on Unix
2017-11-30 14:46:09 -08:00
Dan Travison 47f8467e49 Use explicit libpsl-native binary name for dllimport. (#5580) 2017-11-30 08:17:16 -08:00
Jonathan Muller a12bd1768e Clean up use of 'Runspaceconfiguration' from comments and xunit test code (#5569) 2017-11-29 17:27:47 -08:00
Travis Plunk 3f9ff3f06d Make 'AllSigned' execution policy require modules under $PSHome to be signed (#5511) 2017-11-29 17:27:47 -08:00
Jonathan Muller ad17640d48 Clean up use of 'Runspaceconfiguration' from comments and xunit test code (#5569) 2017-11-29 09:38:04 -08:00
Chris 724095e39f Remove PerformWSManPluginReportCompletion from pwrshplugin.dll (#5498)
This resolves issue #5391, which is tagged with 6.0.0-GA, therefore this should help with getting pwsh out of the door in January.

It removes PerformWSManPluginReportCompletion as stated in the issue and its associated class member g_pPluginContext, which is now unused as well.

The best reviewer is probably @mirichmo , who raised the initial issue with very helpful descriptions or @dantraMSFT who is currently assigned to the issue.
2017-11-28 17:53:57 -08:00
Chris b0996e728f XML documentation fix for CompletionResult (#5550)
* XML documentation fix for CompletionResult: 1 typo, make text start with upper case and add periods at the end.
This typo showed up on the official docs site: https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.completionresult.-ctor?view=powershellsdk-1.1.0#System_Management_Automation_CompletionResult__ctor_System_String_

* Add periods to private members as well as suggested in PR.
2017-11-28 17:53:57 -08:00
PRASOON KARUNAN V 6d72ec300a Added more helpful message for AmbiguousParameterSet exception (#5537) 2017-11-28 17:53:57 -08:00
Travis Plunk 827f154bf5 Replace strlen with strnlen in native code (#5510)
* fix expected vs actual for easier troubleshooting
* replace strlen calls with strnlen
2017-11-28 17:53:57 -08:00
Travis Plunk f67844e4cd Make 'AllSigned' execution policy require modules under $PSHome to be signed (#5511) 2017-11-28 17:34:37 -08:00
Chris cc0e74a7ae Remove PerformWSManPluginReportCompletion from pwrshplugin.dll (#5498)
This resolves issue #5391, which is tagged with 6.0.0-GA, therefore this should help with getting pwsh out of the door in January.

It removes PerformWSManPluginReportCompletion as stated in the issue and its associated class member g_pPluginContext, which is now unused as well.

The best reviewer is probably @mirichmo , who raised the initial issue with very helpful descriptions or @dantraMSFT who is currently assigned to the issue.
2017-11-28 11:34:42 -08:00
Chris 2c4257eeb6 XML documentation fix for CompletionResult (#5550)
* XML documentation fix for CompletionResult: 1 typo, make text start with upper case and add periods at the end.
This typo showed up on the official docs site: https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.completionresult.-ctor?view=powershellsdk-1.1.0#System_Management_Automation_CompletionResult__ctor_System_String_

* Add periods to private members as well as suggested in PR.
2017-11-28 09:53:46 +04:00
PRASOON KARUNAN V 32286ed22a Added more helpful message for AmbiguousParameterSet exception (#5537) 2017-11-24 18:37:20 +04:00
Travis Plunk 9559694191
Replace strlen with strnlen in native code (#5510)
* fix expected vs actual for easier troubleshooting
* replace strlen calls with strnlen
2017-11-21 16:20:25 -08:00
Ilya 7e3a2a23e4
Remove AddTypeCommandBase class (#5407)
It is technically a breaking change but it is only a public api surface of a cmdlet _implementation_ and don't  documented class.
2017-11-17 07:49:32 +04:00
Aditya Patwardhan 381134ba59 Updated csproj to use the latest help package (#5454) 2017-11-15 16:29:04 -08:00
Dan Travison f7206690f1 Update PSRP version dependency (#5469) 2017-11-15 14:43:04 -08:00
bergmeister 019cfee82c Fix Start-PSBuild on WSL if repository was already built on Windows (#5346)
Replace the static `powershell.inc` filename with a name based on the current RID, so that the build doesn't confuse when running in the same local repository on WSL.
2017-11-15 10:52:06 -08:00
Paul Higinbotham 1962c273c6 Fix for PowerShell hang on exit (#5356)
CoreCLR doesn't call finalizer on process exit. PowerShell relies on the CLR finalizer to clean up state on exit. In this case, a Runspace pool was not closed or disposed and any pipeline worker threads created to run concurrent scripts won't end, causing the hang. The same thing can happen if any individual Runspace is created to run a concurrent script and is not closed.

We cannot use the `AppDomain.DomainUnload` event because it's not supported by the default load context. The `AppDomain.ProcessExit` event is also not helpful since it is only called during application exit which means threads already have to be cleaned up.

The fix introduces a static property called `PrimaryRunspace` to `Runspace`. When the PrimaryRunspace is closing it means that the PowerShell session is ending and on exit clean should be performed. The static property `PrimaryRunspace` can only be set once per process.
2017-11-14 14:01:11 -08:00
Mark Kraus c832e1687d Add PSTypeName Support for Import-Csv and ConvertFrom-Csv (#5389)
closes #5134

Adds PSTypeName preservation on Import-Csv and ConvertFrom-Csv
2017-11-14 11:15:18 -08:00
Mark Kraus 87bcd4132a Fix Single Value JSON null in Invoke-RestMethod (#5338)
* [Feature] Fix Single Value JSON null in Invoke-WebRequest

* [Feature] Switch from Regex to JToken.Parse()

* [Feature] Address PR Feedback: use `n
2017-11-14 07:53:43 +04:00
Mark Kraus ecf0f8c151 Add SslProtocol Support to WebCmdlets (#5329)
closes #2662

This feature adds the ability to restrict the SSL/TLS protocol used when making the web request. In 5.1 the user could make use of .NET API's to enforce this on the Web Cmdlets. With the move to HttpClient in PowerShell Core, those APIs have no impact. The user still has requirements to ensure specific protocols are used.

The public enum WebSslProtocol is added as a wrapper to the underlying SslProtocols enum. Neither it nor SecurityProtocolType can be used because Ssl3 and Ssl2 are not supported by HttpClientHandler.SslProtocols. While it may not be intuitive to a PowerShell user to use -bor or "Tls, Tls11" to set multiple options, the general use case for this will be a single protocol.

Adds -SslProtocol parameter to Web Cmdlets
Adds WebSslProtocol Enum to support limited subset of SslProtocol enum supported by HttpClientHandler
Adds TLS 1.1 and TLS 1.0 listening ports to WebListener
2017-11-13 10:45:46 -08:00
Dan Travison d5a974ffd4 Add dependency nuget instructions for PowerShell.Core.Instrumentation resource binary (#5396)
* Add dependency nuget packaging instructions for PowerShell.Core.Instrumentation ETW resource binary.

* Fix markdown MD031 Fenced code blocks errors.

* Fix MD022 Headers should be surrounded by blank lines

* Add a note about Authenticode Dual-signing requirement.

* PR Feedback.

* Set version to Beta.10
2017-11-13 10:40:31 -08:00
Mark Kraus 592cd384e8 Fix spelling in web cmdlet errors (#5427) 2017-11-12 17:48:40 -08:00
Ilya c86f243ca0 Make Import-Csv support CR, LF and CRLF as line delimiters (#5363)
With the fix, `Import-Csv` support CR (\r), LF (\n), CRLF (\r\n) as line delimiters.
2017-11-10 14:02:45 -08:00
Chunqing Chen 2be13a623e Disable cmdlets that are not supported under unix system (#5083)
* permanently remove cmdlets that are not supported under Unix and move tests to defaultcommands.tests.ps1
2017-11-10 10:36:08 -08:00
Mark Kraus f5f3fab1ea Clean Up Full CLR Code From Web Cmdlets (#5376) 2017-11-10 22:00:11 +04:00
Himura Kazuto 6530b779d9 Multiple improvements by CodeRush Static Analysis (#5132) 2017-11-10 09:03:34 -08:00
Mark Kraus ee7edb7427 Add error on Legacy Credential over non-HTTPS for Web Cmdlets (#5402)
- Add an error when a user tries to use `-Credential` (legacy usage without `-Authentication`) or `-UseDefaultCredentials` over a non-HTTPS URI
- User can bypass error with `-AllowUnencryptedAuthentication`
- `-UseDefaultCredentials` can only be reliably tested on Windows as support on other platforms depends on a Kerberos infrastructure. 
- Add `/Auth/` tests to WebListener for challenge authentication Basic, Negotiate, and NTLM

Incidentally, this increases test coverage for the web cmdlets as `-Credential` and `-UseDefaultCredentials` were not being tested.
2017-11-10 08:11:57 -08:00
Ilya 5fd1b4759c
Don't write an error if file already unblocked (Unblock-File) (#5362) 2017-11-10 18:14:08 +04:00
Paul Higinbotham 73188ce27a Porting random hang fixes (#5258) 2017-11-09 16:22:39 -08:00
Steve Lee e0ee555ad6 fix help function to not pipe to more if objects are returned instead of help text (#5395) 2017-11-09 16:21:49 -08:00
Dan Travison 3bfae4f1dd Rename/Update PowerShell ETW manifest to remove the Windows PowerShell dependency. (#5360)
- Build PowerShell.Core.Instrumentation.dll - Resource-only binary for the ETW resources.
- Create a registration script for registering/unregistering the ETW provider.
2017-11-09 09:23:00 -08:00
Steve Lee b1947313c1 Revert refactoring changes that broke remoting to Windows PowerShell 5.1 (#5321)
- Revert refactoring changes so that it doesn't break remoting to Windows PowerShell 5.1
- Fix the rest of the supported types for remoting
- Put remoting sensitive private members in a descriptive region
2017-11-09 09:13:34 -08:00
Ilya c4269cb6be Make SemanticVersion compatible with SemVer 2.0 (#5037)
Made 'SemanticVersion' compatible with SymVer 2.0 http://semver.org/ (p.10)
- Fix comparisons
- Refactor and add more tests
2017-11-09 07:44:58 -08:00
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