Commit graph

935 commits

Author SHA1 Message Date
Dongbo Wang 3b941735d2 [Feature] Change two methods to use 'private' modifier. 2018-01-05 16:34:13 -08:00
Dongbo Wang 3b5badca04 Rename 'PowerShellProperties.json' to 'powershell.config.json' 2018-01-05 16:06:36 -08:00
Dongbo Wang b4b864f5da Re-enable group policy settings from registry
On windows, group policy settings from registry takes precedence over the configuration file.
If a policy is not defined in GP, then we query from configuration file.
2018-01-05 14:33:37 -08:00
Ilya 6825182a6a
Add ForEach and Where methods to [PSCustomobject] (#5756) 2018-01-05 22:54:31 +04:00
Dongbo Wang 167bbad1d1 Address one of Dan's comments 2018-01-04 21:00:13 -08:00
Dan Travison 63b80945a1 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 17:17:34 -08:00
Dongbo Wang a6c62bfc58 [Feature] Minor changes to make ScriptBlock logging work with SysLog 2018-01-04 13:40:51 -08:00
Dongbo Wang 41c66dbc26 Refactor GroupPolicy setting related code to use the configuration file 2018-01-04 13:40:50 -08:00
Dongbo Wang 6ab1ad7ea8 Rename file PropertyAccessor.cs to PSConfiguration.cs 2018-01-04 13:40:50 -08:00
Dongbo Wang 263ec24ae3 Rename 'PropertyScope' to 'ConfigScope' 2018-01-04 13:40:50 -08:00
Dongbo Wang 3dd86f5148 Refactor 'PropertyAccessor.cs'
- Remove the unneeded base type;
- Rename 'ConfigPropertyAccessor' to 'PowerShellConfig';
- Move 'PowerShellConfig' to the namespace 'System.Management.Automation.Configuration'
2018-01-04 13:40:50 -08:00
Dongbo Wang 39af334f9f Enable logging on Linux through MshLog 2018-01-04 13:40:34 -08:00
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
Dongbo Wang d4e802148c Remove 'oldPowershellExeName' and 'oldPowershellDepsName' (#5408) 2017-12-07 10:28:16 -08:00
Dongbo Wang 4f4d7797f7 Remove 'oldPowershellExeName' and 'oldPowershellDepsName' 2017-12-06 14:11:07 -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
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
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 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 f67844e4cd Make 'AllSigned' execution policy require modules under $PSHome to be signed (#5511) 2017-11-28 17:34:37 -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
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
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
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
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
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
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
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
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
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
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
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
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 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
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 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
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
Dongbo Wang 983409f80e Remove PSMI (#5075) 2017-10-10 11:31:59 -07: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
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 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
Ilya 50f6667bdb Cleanup Json cmdlets (#5001) 2017-10-06 09:03:53 -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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
Dongbo Wang befc5f8ae1 Make PowerShell Core enumerate COM collections (#4553)
Make PowerShell Core enumerate COM collections
2017-08-17 20:23:36 +04:00
Dongbo Wang b3e7fd374f Move to the official .NET Core 2.0 (#4603)
* Migrate to official .NET Core 2.0

* [Feature] Remove chmod code as the issue has been fixed in dotnet
2017-08-16 17:32:46 -07:00
Chunqing Chen ede3aec52e Redefine the unicode output condition for nanoserver/IoT for more function (#4074) 2017-08-15 17:41:49 -07:00
Paul Higinbotham 6b8d86ff60 Fixes KeyFilePath parameter for Linux systems (#4529) 2017-08-15 09:42:29 -07:00
Ilya 813e4a661a Fix unblock read only file (#4395)
Adds a new non-terminating error when a file is read-only
2017-08-14 08:49:38 -07:00
Dongbo Wang 384a9fe3fc Clean up ShellExecute code to use the .NET Core implementation (#4523)
* Clean up ShellExecuteHelper and enable ShellExecute in NativeCommandProcessor

* Minor fix

* [Feature] Fix NativeCommandProcessor to clean up in case an exception is thron

* [Feature] Update tests

* [Feature] Address comments

* address one more comment

* Address some more comments
2017-08-10 13:32:57 -07:00
Dongbo Wang 7762d7bf49 clean up map.json related files and scripts (#4532)
* clean up map.json related files and scripts

* Update .spelling
2017-08-10 13:32:19 -07:00
Ilya 47a5a4d8ba Clean up '#if CORE' in PSUtils.cs (#4453)
* Cleanup '#if CORE' in PSUtils.cs

* Fix IsRunningOnProcessorArchitectureARM
2017-08-09 09:42:42 -07:00
Mike Richmond 515a999e1c Porting Enable-PSRemoting and its Tests (#2671)
Fixes #1193 for most scenarios. The remaining scenario to be addressed is the Nano Server bring-up scenario. To continue supporting that scenario, I left the Install-PowerShellRemoting script in place.

This change 
1. Ports Enable-PSRemoting and Disable-PSRemoting to PowerShell Core
2. Adds side-by-side PowerShell Core remoting support to the PSSessionConfiguration cmdlets and PSRemoting cmdlets.
3. Ports PSSessionConfiguration tests

This change also introduces a behavioral difference. The PSRemoting and PSSessionConfiguration cmdlets are now context-sensitive and only work for endpoints that match the PowerShell type. For example, Get-PSSessionConfiguration, when running in PowerShell Core, will only return PowerShell Core WinRM endpoints. It will only modify PowerShell Core WinRM endpoints and cannot be used to configure Windows PowerShell endpoints.
2017-08-08 09:36:22 -07:00
Ilya 649ff285ee Clean up '#if CORE' in ProcessCodeMethods.cs and 'ClrFacade.GetSafeProcessHandle' (#4428) 2017-08-08 09:20:57 -07:00
Ilya 0150f65d0c Clean up '#if CORE' in PSPrincipal.cs (#4433)
* Use TimeZoneInfo in PSPrincipal.cs

* Use TimeZoneInfo in serverremotesession.cs

* Use TimeZoneInfo in RemoteSessionCapability.cs

* Use TimeZoneInfo in serialization.cs

* Remove private fiield  'clientTimeZone'

* Remove extra line
2017-08-07 14:27:14 -07:00
Ilya 984b85f34d Clean up '#if CORE' in RunspaceConfiguration*.cs files (#4448)
* Cleanup '#if CORE' in RunspaceConfigurationTypeException.cs

* Cleanup '#if CORE' in RunspaceConfiguration.cs

* Cleanup '#if CORE' in RunspaceConfigurationEntry.cs

* Cleanup '#if CORE' in RunspaceConfigurationTypeAttribute.cs
2017-08-07 14:25:09 -07:00
Andrew 99236b18bb Make ResourceManagerCache check for alternative resource paths (#4139) 2017-08-04 15:39:26 -07:00
Travis Plunk 7a03b0c7b9 Use supported API to set CAPID in the SACL (#4496) 2017-08-04 12:29:00 -07:00
Ilya 35a3ecd27b Cleanup '#if CORE' in Utils.cs (#4443) 2017-08-03 15:29:54 -07:00
Ilya 8aa028eae9 Cleanup '#if CORE' in TypeTable.cs (#4442) 2017-08-03 15:29:14 -07:00
Dongbo Wang 6d32293437 Add more tab completion tests (#4356)
* Add more TabCompletion tests

* Minor changes

* Add some more tests

* Add more tab completion tests

* Fix errors

* Add more test coverage

* Add 'AfterEach { Pop-Location }'

* Enable DSC resource name completion and address comments

* use both '/' and '\' in the path for completion

* Use a separate test for '\' and '/'
2017-08-03 15:26:20 -07:00
Ilya 8034dd6dd1 Clean up '#if CORE' in PropertyAccessor.cs (#4429)
* Cleanup '#if CORE' in PropertyAccessor.cs

* Remove RegistryAccessor class
2017-08-03 08:34:21 -07:00
David Christian 1a003a8af3 Support Positive/Negative ValidateRange (#4084)
To improve code clarity and give better error messages when using ValidateRange, you can now specify:

```
[ValidateRange(ValidateRangeKind.Positive)]
```

instead of

```
[ValidateRange(1, 2147483647)]
```

Valid kinds are:

Positive
Negative
NonPostiive
NonNegative
2017-08-02 11:24:06 -07:00
Ilya 65643e1b5d Cleanup '#if CORE' in EtwActivity.cs (#4455) 2017-08-02 09:59:39 -07:00
Ilya 82ad9da3a7 Cleanup '#if CORE' in SessionStateExceptions.cs (#4454) 2017-08-02 09:58:59 -07:00
Ilya 1a835f3382 Cleanup '#if CORE' in ExtensionMethods.cs (#4451) 2017-08-01 17:25:51 -07:00
Ilya f4a13e2e40 Cleanup '#if CORE' in PSTelemetryMethods.cs (#4452) 2017-08-01 17:25:37 -07:00
Ilya a7bfde5794 Cleanup '#if CORE' in PInvokeDllNames.cs (#4456) 2017-08-01 17:25:05 -07:00
Steve Lee e38f0e7149 Make ShellExecuteEx use STA (#4362) 2017-08-01 11:27:40 -07:00
Steve Lee cf9f8c8574 Give error instead of crashing if WSMan client lib not available (#4387) 2017-07-31 16:26:24 -07:00
Ilya f2d507cb0a Cleanup '#if CORE' in cmdlets-over-objects.objectModel.autogen.cs (#4411) 2017-07-31 13:04:12 -07:00
Ilya 3e14daab3b Cleanup '#if CORE' in ILineOutput.cs (#4412) 2017-07-31 13:03:56 -07:00
Ilya 504aac522d Cleanup '#if CORE' in MshParameter.cs (#4413) 2017-07-31 13:03:12 -07:00
Ilya af6ccd4737 Cleanup '#if CORE' in CorePsExtensions.cs (#4414) 2017-07-31 13:02:56 -07:00
Ilya 5890c51e20 Cleanup '#if CORE' in CorePsPlatform.cs (#4415) 2017-07-31 13:02:14 -07:00
Steve Lee ab764eeac1 Length script property for List View didn't include a name for the property so it defaulted to using the script as the property name (#4437) 2017-07-31 12:56:41 -07:00
Ilya baa56f9c71 Cleanup '#if CORE' in CorePsStub.cs (#4416) 2017-07-31 12:55:28 -07:00
Ilya 86573cf926 Cleanup '#if CORE' in ComAdapter.cs (#4418) 2017-07-31 12:55:08 -07:00
Ilya 5bc204f26d Cleanup '#if CORE' in CompletionCompleters.cs (#4419) 2017-07-31 12:54:50 -07:00
Ilya 97e3cc2c35 Cleanup '#if CORE' in ExtensibleCompletion.cs (#4420) 2017-07-31 12:54:26 -07:00
Ilya 684ff97e79 Cleanup '#if CORE' in CommandProcessor.cs (#4421) 2017-07-31 12:54:13 -07:00
Ilya 5cfbf83447 Clean up '#if CORE' in ConnectionFactory.cs (#4422) 2017-07-31 12:54:01 -07:00
Ilya ea81506232 Cleanup '#if CORE' in DynamicInstructionN.cs (#4423) 2017-07-31 12:53:37 -07:00
Ilya 91df98f565 Cleanup '#if CORE' in InstructionFactory.cs (#4424) 2017-07-31 12:51:05 -07:00
Ilya 1841682c08 Clean up '#if CORE' in Utilities.cs (#4425) 2017-07-31 12:50:44 -07:00
Ilya ea3c207636 Cleanup '#if CORE' in ModuleIntrinsics.cs (#4426) 2017-07-31 12:50:15 -07:00
Ilya 5ce4e03ca5 Cleanup '#if CORE' ParameterBinderBase.cs (#4427) 2017-07-31 12:49:32 -07:00
Ilya 2bfe094b12 Cleanup '#if CORE' in PSVersionInfo.cs (#4430) 2017-07-31 12:49:11 -07:00
Ilya 927266225f Clean up '#if CORE' in remoterunspace.cs (#4431) 2017-07-31 12:48:38 -07:00
Dongbo Wang 1462ac300b Clean up ClrFacade.cs - remove ClrFacade.PtrToStructure (#4379) 2017-07-29 22:34:31 -07:00
Dongbo Wang 2c43140276 Clean up ClrFacade.cs - remove ClrFacade.SizeOf<T>() (#4377) 2017-07-29 17:40:19 -07:00
Dongbo Wang 4eeeb4552c Remove ClrFacade.GetUninitializedObject and 'if CORECLR' cleanup (#4375) 2017-07-29 17:16:23 -07:00
Dongbo Wang dce0bab626 Clean up ClrFacade.cs - remove ClrFacade.DestroyStructure (#4378) 2017-07-29 17:04:38 -07:00
Dongbo Wang 16f408c2f7 Clean up ClrFacade.cs - remove ClrFacade.StructureToPtr (#4380) 2017-07-29 16:44:44 -07:00
Ilya 184a9bc85e Clean up '#if CORE' - use SecurityZone from CoreFX (#4368)
Make `System.Management.Automation references` to package `System.Security.Permissions`, which brings back `SecurityZone` and `System.Security.Policy.Zone`.
2017-07-28 12:13:15 -07:00
Ilya 2dd371952d Clean up '#if CORECLR' in ClrFacade.cs (#4366) 2017-07-28 11:37:25 -07:00
Steve Lee 03d4e9120b Support Invoke-Item -Path <folder> (#4262)
On CoreFx, UseShellExecute for Process start is false by default to be cross platform compatible.
In the case of a folder, Process.Start() returns Access Denied as it's not an executable.
On Windows, we can use the ShellExecute path to have explorer open the folder. On Unix, we use `xdg-open` and `open` for Linux and macOS respectively.
2017-07-27 22:17:38 -07:00
Steve Lee cf7b9f3de1 Fix Implicit Remoting test failure on nightly run (#4323)
Retry setting winrm config if it fails with MaxConcurrentUsers > 100
2017-07-26 10:08:52 -07:00
Steve Lee 0cd7a4a0c9 Fix error message when 'HelpMessage' property of 'ParameterAttribute' is set to empty string (#4334)
- Fix invalid value error message on some properties of ParameterAttribute to point to the specific properties.
- Avoid wrapping argument exception into not a useful 'requires' exception.
2017-07-26 09:20:43 -07:00
Dongbo Wang 0d8eff6446 Fix array expression to not return null or throw error (#4296)
This change fixes 3 issues:
- According to [PowerShell Language Specification Version 3.0](https://www.microsoft.com/en-us/download/details.aspx?id=36389), as quoted: "_The result is the (possibly empty) unconstrained 1-dimensional array_", `@(...)` should only return `object[]` array.
- `@([object[]]$null).GetType()` fails with error `"You cannot call a method on a null-valued expression."`
- `@([System.Collections.Generic.List[object]]$null)` fails with error `"Object reference not set to an instance of an object."`
2017-07-24 21:52:30 -07:00
bergmeister ffd39b2853 PSScriptAnalyzer fixes by category (#4261)
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'ForEach-Object' (alias is '%' or 'foreach')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Where-Object' (alias is '?' or 'where')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Select-Object' (alias is 'select')
- Fix PSScriptAnalyzer warnings of type PSPossibleIncorrectComparisonWithNull. Essentially, $null has to be on the left-hand side when using it for comparison.
- A Test in ParameterBinding.Tests.ps1 needed adapting as this test used to rely on the wrong null comparison
- Replace a subset of tests of kind '($object -eq $null) | Should Be $true' with '$object | Should Be $null'
2017-07-21 21:03:49 -07:00
Steve Lee 44e377525b Register-PSSessionConfiguration fails if SesionConfig folder doesn't exist (#4271) 2017-07-18 10:07:05 -07:00
Dongbo Wang 069c7a4b6f Enable DataRow/DataRowView adapters in PowerShell Core (#4258) 2017-07-17 11:27:01 -07:00
James Truher [MSFT] 71392a2666 Disable UTC and SQM telemetry by enclosing the code in '#if LEGACYTELEMETRY' (#4190) 2017-07-17 09:44:54 -07:00
Dongbo Wang c5f3a19caf Run PowerShell class static methods in the correct Runspace/SessionState (#4209)
Summary
----------
When the same script file gets executed in multiple Runspaces, the RuntimeType generated from the powershell class defined in the file will be shared among those Runspaces. For different Runspaces, different SessionState should be used to run the static methods.

Fix
---
We use the `SessionStateKeeper` to query for the correct `SessionState` to use for a static method call.
We already use `SessionStateKeeper` to track the `Runspace/SessionState` where a PowerShell class is defined, and thus we can leverage this for the static method invocation.
2017-07-14 18:05:48 -07:00
Paul Higinbotham 7fa0dd0549 Fix for implicit remote regression in restricted session (#4222) 2017-07-14 12:28:22 -07:00
Paul Higinbotham 02737e2fe4 Fixes CIM deserialization bug (#4234) 2017-07-14 09:52:24 -07:00
Ilya dc76c86f7a ValidateSetAttribute enhancement: support set values to be dynamically generated from a custom ValidateSetValueGenerator (#3784)
Currently `ValidateSetAttribute` accepts only explicit constants as valid values. This is a significant limitation. Sometimes we need to get valid values dynamically, ex., Azure VMs, logged-on users and so on. The PR add follow possibilities:
- pass a _custom type_ (a valid values generator) implementing `IValidateSetValuesGenerator` interface to get valid values dynamically.
- pass a _custom type_ (a valid values generator) derived from `CachedValidValuesGeneratorBase` abstract class to get valid values dynamically and _cache_ the list to share with other ValidateSetAttribute attributes.
2017-07-13 21:28:32 -07:00
Travis Plunk 1278c8948c make sure we don't return null for share module path (#4219)
* make sure we don't return null for share module path
fall back to environment if call to get special path doesn't work

* address PR comments
2017-07-11 11:23:43 -07:00
Oisin Grehan d9828fe937 Add 'semver' as core (contrained-safe) accelerator for S.M.A.SemanticVersion (#4142) 2017-07-11 10:56:28 -07:00
jeffbi a9b8e98449 Remove unneeded test hooks and tests due to behavior change in .NET Core (#4200) 2017-07-08 15:18:48 -07:00
jeffbi 1688703caf Make Get-ChildItem follow symlinks on demand, with checks for link loops (#4020)
Add the dynamic parameter `-FollowSymlink` to `Get-ChildItem`.
Add a mechanism for tracking visited directories.
Add native code to get device/inode information on Unix/Windows.
Add warning when refusing to enter an already-visited directory.
2017-07-06 12:28:27 -07:00
Tim Curwick d1e05efbf1 Added comma to the list of replaced characters in assemblyname (#4136) 2017-07-06 11:32:54 -07:00
Steve Lee 36eaab2809 Static analysis: Fix usage of XmlReader to ensure XmlResolver is null (#4108)
* the default XmlResolver will attempt to resolve external resources, recommendation is to explicitly set to null which
will raise exception if malicious xml attempts to cause xmlreader to access external resources

* added DTDProcessing and related to XmlReaderSettings
2017-07-06 09:09:57 -07:00
Bruce Payette ece27ff687 Fix spurious error generated when importing cmdlets from an in-memory assembly (#4117) 2017-06-30 15:36:38 -07:00
Dongbo Wang 3e35fb9918 Move powershell to 2.0.0-preview3-25426-01 using the .NET CLI 2.0.0-preview2-006502 (#4144) 2017-06-30 13:07:14 -07:00
Paul Higinbotham a2922d6ac4 Fix for SSH remoting when SSH client abruptly terminates (#4123)
* Fix for SSH remoting when SSH client abruptly terminates

* Put error message in localizable string resource

* Renamed error string per code review request

* Removed extra error==null check
2017-06-29 11:14:33 -07:00
Ilya a8e3d8968f Refactor MSBuild project files by adding the common property file 'PowerShell.Common.props' (#4106)
`AssemblyVersion` and `FileVersion` are now inferred from the `Version` property, which is inferred by `VersionPrefix`. So now both `AssemblyVersion` and `FileVersion` are 6.0.0.0 for each of PowerShell assemblies, and the `ProductVersion` and `InformationalVersion` are 6.0.0.
2017-06-29 10:25:49 -07:00
Andrew ecefb50d0d Fixing Import-Module on Linux for special cases of NestedModules/RootModule path format (#4010)
* IPMO fix for some cases of NestedModules/RootModule path syntax

* Added tests for #3693 fix

* Updated tests
2017-06-28 16:35:33 -07:00
Steve Lee 40c479d071 Address static analysis issues in SSH remoting (#4083)
* address static analysis issues
- remoteRunspaces is not used TFS:10618323
- not checking return value of ResumeThread() TFS:10618344

* fixed magic number use

* changed magic number to Uint.MaxValue
2017-06-28 16:27:54 -07:00
Keith Hill 27e47f9ee1 Implement Unicode escape parsing (#3958)
* Implement Unicode variable width `u{xxxxxx} escape sequences.
2017-06-27 22:55:57 -07:00