Commit graph

935 commits

Author SHA1 Message Date
Dongbo Wang 10334220e8 Address Feedback: functional changes and method/variable renaming 2018-07-09 17:14:34 -07:00
Dongbo Wang d2e9151fff [Feature] Add tests for experimental feature work 2018-07-06 13:28:20 -07:00
Dongbo Wang 3c3ddeb127 Alter the analysis cache file name properly 2018-07-06 13:28:20 -07:00
Dongbo Wang d8d3344e98 Generate logging resources for Unix platforms 2018-07-06 13:28:20 -07:00
Dongbo Wang dc2d741791 Add logging, formatting, and '$EnabledExperimentalFeatures' 2018-07-06 13:28:19 -07:00
Dongbo Wang 7770aa547e Add 'Get-ExperimentalFeature' cmdlet 2018-07-06 13:28:19 -07:00
Dongbo Wang 8a5ddbb231 Support experimental feature in modules 2018-07-06 13:28:19 -07:00
Dongbo Wang 930350e2ee Update code that creates attributes to support the new attribute changes 2018-07-06 13:28:19 -07:00
Dongbo Wang eed9842534 First batch: Basic experimental feature flag and attributes enforced 2018-07-06 13:28:18 -07:00
Meir Blachman 58e9b4969a Update docs for ArgumentCompleterAttribute class (#7227) 2018-07-06 08:34:45 +05:00
Robert Holt de41ca519c Refactor module specification logic (#7126)
* Use `nameof` where appropriate
* Factor out a repeated `entry.Key.ToString()` call
* Use a `StringBuilder` in the `ToString()` method
* Dissect a trick comparison method into something simpler
* Use HashCode.Combine() method
2018-07-03 11:18:12 +05:00
Staffan Gustafsson 3c079b9d42 Add type inference for Select-Object command (#7171)
Add type inference for Select-Object command

Fixes #7170
2018-07-02 13:23:30 -07:00
Bruce Payette dbaa1add3a Methods with return type [object] should return null for an empty result (#7138) 2018-07-02 12:58:42 -07:00
Steve Lee 06960346a1 Enable UseShellExecute on all platforms (#7198)
Previously, we limited use of UseShellExecute when starting a new process to only Windows Desktop.  However, CoreFx now supports UseShellExecute (appropriately calling `open` on macOS and `xdg-open` on Linux) so we can have a consistent code and remove some of the existing redundant code or unnecessary limiting code.
2018-07-02 12:50:19 -07:00
Dongbo Wang 0d9a3ac832
Refactor module code related to 'Get-Module -ListAvailable' (#7145)
* The major refactoring changes are:
- In `ModuleIntrisic.cs`, remove unneeded Windows-PowerShell-only code.
- In `ModuleUtils.cs`
   - use the new API `Directory.GetDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions)` and `Directory.GetFiles(string path, string searchPattern, EnumerationOptions enumerationOptions)` to enumerate files and sub-directories within a directory path.
   - remove the unused parameter `bool force` from `GetDefaultAvailableModuleFiles(bool force, bool isForAutoDiscovery, ExecutionContext context)`
   - refactor the method `GetModuleVersionsFromAbsolutePath`. Add more comments and rename the method name.
- In `ModuleCmdletBase.cs`, refactor the method `GetModuleForNonRootedPaths` to `GetModuleForNames` to simply its implementation.
- In `PSModuleInfo.cs`
   - group the declarations of `Declared*Exports` fields together
   - rename `_detected*Exports` fields to `Detected*Exports` to group them together. They are internal fields and used outside `PSModuleInfo`.

* There is some perf improvement after this refactoring change:
- For `Get-Module -ListAvailable`, there is about 36% speed improvement for 94 default modules.
- For `Get-Module -ListAvailable -All`, there is about 14% speed improvement for totally 600 module files.
- For `Get-Module <name> -ListAvailable -List`, there is over 17x speed improvement for finding 13 modules from 600 modules. This is because we now filter names using the module file before creating a `PSMdouleInfo` object.
2018-07-02 11:00:27 -07:00
Ilya 0a3555064a Use .Net Core File.Delete() method to remove symbolic links and alternate streams (#7017)
.Net Core support processing symbolic links and alternate streams, and thus we can remove our P/Invoke code.
2018-07-01 00:08:28 -07:00
Steve Lee 3cc9d26bc2 Fix class searcher to ignore hidden properties (#7188) 2018-06-28 23:29:12 -07:00
Steve Lee 057eeddbd6 when using PSRP, if we receive text instead of xml, output it as error to help troubleshoot (#7168)
PSRP currently relies on XML for the transport messages.  When using PSRP over SSH, if the target side fails, it sends back a text message.  PSRP sees this and doesn't know what to do so it throws
a generic message which makes troubleshooting the issue more difficult.  Change here is to throw
the text message which now looks like:

>new-pssession : [test-machine] There is an error processing data from the background process. Error reported: Invalid argument '-np', did you mean:.

Previously:

>new-pssession : [test-machine] There is an error processing data from the background process. Error reported: Cannot process an element with node type "Text". Only Element and EndElement node types are supported..

Since it's processing one line at a time, not able to get the whole message.
2018-06-27 15:42:06 -07:00
Dan Travison 5e8b23e127 Allow Basic Auth over HTTPS (#6890)
* [FEATURE] Allow Basic Auth over HTTPS

* WSManTransportManager.cs: Simplify HTTPS check
Update comment in test to refer to the right exception type.

* Disable test until limi crash fo selected connection error paths is fixed

* Use Hex format for defining the expected HRESULT
2018-06-27 15:27:41 -07:00
Steve Lee 5f47fc0e8c Fix tab expansion for Get-Process on macOS (#7176)
* fix tab exapnsion for get-process on macOS

* add comment to address PR feedback
2018-06-27 12:48:42 -07:00
Steve Lee 8829c01fa2 [feature] (#7101)
Revert "Set-Location should use path with wildcard characters if it exists instead of globbing (#5839)"

This reverts commit 7459b54639.
2018-06-27 10:26:37 +05:00
Steve Lee b1fbcee6d2 Fix trimming of whitespace when table is wrapped (#7184) 2018-06-27 10:24:03 +05:00
Bruce Payette bacda46941 Fix the pref regression to the '-replace' operator after adding ScriptBlock support (#7135) 2018-06-26 12:27:16 -07:00
Dongbo Wang 13e925e13e
Revert "Make switch statement report correct error position when it fails to evaluate the condition" (#7182)
The fix causes a problem in debugging. When stepping over the scripts in debugging mode, the debugger will stop at the switch statement condition expression twice at the very beginning -- one for evaluating the condition, and one for iterating the condition.
2018-06-26 12:24:11 -07:00
Steve Lee e8d2a6b278 Fix adding padding when right justified (#7136)
Table formatter was overly aggressive in removing padding so even right justified output (default of numbers) gets incorrectly stripped of padding. Fix is when right justified, always add padding (because it's right justified, there's never trailing whitespace).
2018-06-26 12:35:22 +05:00
Christoph Bergmeister bbd48f60e0 Add location history for Set-Location to enable 'cd -' scenario (issue #2188) (#5051)
* Implement location history feature for Set-Location.
This makes it possible to go back to the last directory using 'cd -',
which is exactly the same syntax as on Linux shells.

* Use an existing stack implementation instead of relying on an environment variable and move logic for 'cd -' into the internal class of SessionState.Path.SetLocation
Keep the (additional) setting of an environment for Unix system in case of mixed usage of cd and Set-Location to provide consistency.

* Use a bounded stack with a limit of 1000 and adapt tests.
Remove setting environment variable on Linux as discussed in PR.

* Fix test: use get-location explicitly to avoid subtle difference in the path string (e.g. an additional slash at the end)
Make syntax to .net call of environment consistent with surrounding code

* Move initialization of _workingLocationHistoryStack into constructor of SessionStateInternal and set the limit to 20 as discussed in PR 5051.

* Make new BoundedStack class in engine utils internal
2018-06-26 12:21:38 +05:00
Ilya 4fc784e840 Bulk update code base to put 'null' on the right-hand-side of a comparison expression (#6949) 2018-06-25 14:37:09 -07:00
Dongbo Wang c77d0ceff2
Make switch statement report correct error position when it fails to evaluate the condition (#7151) 2018-06-25 14:07:42 -07:00
Sergey Vasin ffca008726 Fix error when using Get-ChildItem c: (#7033)
* Fix error when using Get-ChildItem c:

* Fix New-Item test issue.

* Add tests for Get-ChildItem cmdlet.

* Add tests for New-Item cmdlet.

* Fix tests for New-Item cmdlet.
2018-06-25 10:15:57 -07:00
Robert Holt 9413fd3802 Remove MapSecurityZoneWithUrlmon method and related code (#7103) 2018-06-24 23:46:12 -07:00
Steve Lee 6c9eea6390 Add back ADSI and WMI type accelerators (#7085) 2018-06-21 09:57:14 -07:00
Dongbo Wang f591f4d61f
Comment about dynamic members for the DotNetAdapter 'GetMember' and 'GetMembers' (#7087) 2018-06-20 00:23:55 -07:00
Bruce Payette 3a4c410499 Fix for #6855 - Measure-Object should handle scriptblock properties. (#6934)
Measure-Object should handle `ScriptBlock` properties. Fixed by renaming `MshExpression` to `PSPropertyExpression` and making it public. Then in `MeasureObjectCommand`, lifting it up to the parameter level. Previously the implementation exposed the Property as a string and
wrapped it internally as a `PSPropertyExpression`. Now the parameter type is `PSPropertyExpression` directly allowing for both wildcard strings and `ScriptBlock`.

`PSPropertyExpression` now lives in a public namespace where it can be used by cmdlet and script authors to easily add the same type of functionality to their commands. I also modified `PSPropertyExpression` to handle hashtables properly as objects so
         @{prop = 3} | measure-object prop
and
         @{prop = 3} | measure-object {$_.prop}
will work the same. (Previously the example using just the property name would fail.)
2018-06-20 00:23:11 -07:00
Steve Lee abcdce4e3e Don't fail if SaferPolicy API is not available on Win10 IoT or NanoServer (#7075)
* don't fail if SaferApi is not available
* fix install-powershellremoting to work on Windows PowerShell 5.1
2018-06-19 17:53:32 -07:00
Dongbo Wang d6250e8086
Revert the PR #7023 "Set the cursor to the place where a user hits tab key" (#7117)
Reverts PowerShell/PowerShell#7023 due to a regression introduced by it.
2018-06-19 17:40:29 -07:00
Hubert Bukowski 9ac701dbee Fix conditions for transcription of Write-Information command. (#6917)
Makes a transcription of Write-Information command consistent with $InfomrationPreference variable.
2018-06-16 21:11:21 +05:00
Paul Higinbotham 6fa1e86f2d Added copy env vars from ProcessStartInfo to key/pair array used in creating ssh process (#7070)
This addresses issue #6207. During SSH remoting on Linux machines, when PowerShell on the client creates the SSH process to connect to the target machine, it was not passing in environment variables from the parent process, and this was preventing ssh-agent key management from working.

This change adds a helper function to create environment variable key/value pairs for the created SSH process, based on the passed in ProcessStartInfo object.
2018-06-15 11:06:38 -07:00
Jianyun 8805ca20aa Set the cursor to the place where a user hits tab key (#7023) 2018-06-14 23:04:31 -07:00
Ilya 81244fb907 Avoid calling native APIs to check for existence of FileSystem items (#6929)
- Use File.GetAttributes() instead of p/invokes to check for existence of FileSystem items. The method throws access exceptions which we use for better error messages.
- Remove the word 'Native' from method names.
2018-06-14 11:35:44 -07:00
Dongbo Wang 87bec49b27 Cleanup: remove the unneeded type 'RemotingCommandUtils' (#7029) 2018-06-14 08:35:55 +05:00
Dongbo Wang 9804ae5f97
Merge the v6.1.0-preview.3 release branch to master (#7060) 2018-06-13 15:59:27 -07:00
Paul Higinbotham 3eec0c42b2 Removed unneeded code that forces ARM platforms to run PowerShell in CL mode (#7046) 2018-06-13 12:01:32 -07:00
Dan Thompson ce3cb68551 Make Select-Object/ForEach-Object/Where-Object see dynamic properties (#6898)
Dynamic (DLR) objects work in some places today, but not others.  This change expands that support to ForEach-Object, Where-Object and the family of cmdlets that use 'MshExpression' (Select-Object, etc.).

This change addresses both wildcard and non-wildcard cases. In wildcard cases, it uses the existing support of generating PSDynamicMember objects for names returned by GetDynamicMemberNames.

In non-wildcard cases, a dynamic property access is attempted whether or not the name shows up in GetDynamicMemberNames, but a truly "blind" access is only attempted if we see that the base object is an IDMOP. If the dynamic access fails, you'll get the same or a similar error experience as before ("The property 'Blarg' cannot be found", or no error at all, depending on the cmdlet and the strict mode setting).

The included test coverage includes a stub for the.ForEach operator--once people are happy with this change, I can continue by adding support there.

This change should allegedly also have positive perf impact, though in actual perf testing, although it does seem ever-so-slightly faster, I found it difficult to measure much difference at all.
2018-06-12 23:48:34 -07:00
Ilya e177fcaef6 CodeFactor code style cleanup: replace literal empty strings with 'string.Empty' (#6950) 2018-06-12 12:30:10 -07:00
Aditya Patwardhan 0d67d4dc3a Merged PR 3115: Use Directory.CreateDirectory instead of DirectoryInfo.CreateSubDirectory
Change to use Directory.CreateDirectory because of regression introduced by https://github.com/dotnet/corefx/pull/27810 in creating a subdirectory under root path.
2018-06-11 23:06:08 +00:00
Steve Lee 50d061148d Remove 'SemanticVersion' from 'knowntypes' list in serialization code to enable interop between WinPS and PSCore (#7016)
PowerShell serialization has a list of known PowerShell types. When an object is deserialized containing a known type it tries to deserialize the object to that specific type and throws an exception if it can't succeed. SemanticVersion only exists in PSCore6 so when remoting from Windows PowerShell or importing clixml generated from PSCore6 that contains SemanticVersion, it fails.

With this fix, it will be rehydrated as a "PSObject" with "Deseriealized.System.Management.Automation.SemanticVersion" in the 'TypeNames' in both Windows PowerShell and PowerShell Core.
2018-06-08 11:38:14 -07:00
Christoph Bergmeister fa544c33db Update links that contain 'en-us' culture (#7013)
Update links that contain 'en-us' culture to remove 'en-us' culture (if possible) and in some cases update to newer re-directed link to docs.microsoft.com
2018-06-08 10:49:03 +05:00
Dongbo Wang b20dd31398
Fix parser to continue parsing key-value pairs after an If-Statement value in a HashExpression (#7002)
After parsing `if () { }`, new lines are skipped in order to see if either `elseif` or `else` is present. When neither is present, we should resync back to the pointer before skipping those possibly available new lines, so that the new line tokens can be utilized by the subsequent parsing.
2018-06-06 09:38:05 -07:00
Dongbo Wang 2429b43181 Skip compiling the non-supported cmdlets on Unix in System.Management.Automation.dll (#6939)
This is to keep the cache in InitialSessionState in sync with the actual available cmdlet types in System.Management.Automation.dll
2018-06-06 08:08:49 +05:00
Dongbo Wang 0b32d0c04b [Feature] Minor update on 'GetFileSystemItem' (#6984) 2018-06-05 09:51:04 +05:00