MegaBites-AI/Windows-powershell
0308
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections.ObjectModel;5 6using Dbg = System.Management.Automation;7 8namespace System.Management.Automation9{10 /// <summary>11 /// Exposes the Property noun of the Cmdlet Providers to the Cmdlet base class. The methods of this class12 /// use the providers to perform operations.13 /// </summary>14 public sealed class PropertyCmdletProviderIntrinsics15 {16 #region Constructors17 18 /// <summary>19 /// Hide the default constructor since we always require an instance of SessionState.20 /// </summary>21 private PropertyCmdletProviderIntrinsics()22 {23 Dbg.Diagnostics.Assert(24 false,25 "This constructor should never be called. Only the constructor that takes an instance of SessionState should be called.");26 }27 28 /// <summary>29 /// Constructs a facade over the "real" session state API.30 /// </summary>31 /// <param name="cmdlet">32 /// An instance of the cmdlet.33 /// </param>34 /// <exception cref="ArgumentNullException">35 /// If <paramref name="cmdlet"/> is null.36 /// </exception>37 internal PropertyCmdletProviderIntrinsics(Cmdlet cmdlet)38 {39 if (cmdlet == null)40 {41 throw PSTraceSource.NewArgumentNullException(nameof(cmdlet));42 }43 44 _cmdlet = cmdlet;45 _sessionState = cmdlet.Context.EngineSessionState;46 }47 48 /// <summary>49 /// Constructs a facade over the "real" session state API.50 /// </summary>51 /// <param name="sessionState">52 /// An instance of the "real" session state.53 /// </param>54 /// <exception cref="ArgumentNullException">55 /// If <paramref name="sessionState"/> is null.56 /// </exception>57 internal PropertyCmdletProviderIntrinsics(SessionStateInternal sessionState)58 {59 if (sessionState == null)60 {61 throw PSTraceSource.NewArgumentNullException(nameof(sessionState));62 }63 64 _sessionState = sessionState;65 }66 67 #endregion Constructors68 69 #region Public methods70 71 #region GetProperty72 73 /// <summary>74 /// Gets the specified properties from the specified item(s)75 /// </summary>76 /// <param name="path">77 /// The path to the item to get the properties from.78 /// </param>79 /// <param name="providerSpecificPickList">80 /// The properties to get from the item(s). If this is empty, null, or "*" all81 /// properties should be returned.82 /// </param>83 /// <returns>84 /// A PSObject for each item that the path represents. Each PSObject should85 /// contain a property for those in the providerSpecificPickList.86 /// </returns>87 /// <exception cref="ArgumentNullException">88 /// If <paramref name="path"/> is null.89 /// </exception>90 /// <exception cref="ProviderNotFoundException">91 /// If the <paramref name="path"/> refers to a provider that could not be found.92 /// </exception>93 /// <exception cref="DriveNotFoundException">94 /// If the <paramref name="path"/> refers to a drive that could not be found.95 /// </exception>96 /// <exception cref="ItemNotFoundException">97 /// If <paramref name="path"/> does not contain glob characters and98 /// could not be found.99 /// </exception>100 /// <exception cref="NotSupportedException">101 /// If the provider that the <paramref name="path"/> refers to does102 /// not support this operation.103 /// </exception>104 /// <exception cref="ProviderInvocationException">105 /// If the provider threw an exception.106 /// </exception>107 public Collection<PSObject> Get(108 string path,109 Collection<string> providerSpecificPickList)110 {111 Dbg.Diagnostics.Assert(112 _sessionState != null,113 "The only constructor for this class should always set the sessionState field");114 115 // Parameter validation is done in the session state object116 117 return _sessionState.GetProperty(new string[] { path }, providerSpecificPickList, false);118 }119 120 /// <summary>121 /// Gets the specified properties from the specified item(s)122 /// </summary>123 /// <param name="path">124 /// The path(s) to the item(s) to get the properties from.125 /// </param>126 /// <param name="literalPath">127 /// If true, globbing is not done on paths.128 /// </param>129 /// <param name="providerSpecificPickList">130 /// The properties to get from the item(s). If this is empty, null, or "*" all131 /// properties should be returned.132 /// </param>133 /// <returns>134 /// A PSObject for each item that the path represents. Each PSObject should135 /// contain a property for those in the providerSpecificPickList.136 /// </returns>137 /// <exception cref="ArgumentNullException">138 /// If <paramref name="path"/> is null.139 /// </exception>140 /// <exception cref="ProviderNotFoundException">141 /// If the <paramref name="path"/> refers to a provider that could not be found.142 /// </exception>143 /// <exception cref="DriveNotFoundException">144 /// If the <paramref name="path"/> refers to a drive that could not be found.145 /// </exception>146 /// <exception cref="ItemNotFoundException">147 /// If <paramref name="path"/> does not contain glob characters and148 /// could not be found.149 /// </exception>150 /// <exception cref="NotSupportedException">151 /// If the provider that the <paramref name="path"/> refers to does152 /// not support this operation.153 /// </exception>154 /// <exception cref="ProviderInvocationException">155 /// If the provider threw an exception.156 /// </exception>157 public Collection<PSObject> Get(158 string[] path,159 Collection<string> providerSpecificPickList,160 bool literalPath)161 {162 Dbg.Diagnostics.Assert(163 _sessionState != null,164 "The only constructor for this class should always set the sessionState field");165 166 // Parameter validation is done in the session state object167 168 return _sessionState.GetProperty(path, providerSpecificPickList, literalPath);169 }170 171 /// <summary>172 /// Gets the specified properties from the specified item(s)173 /// </summary>174 /// <param name="path">175 /// The path to the item to get the properties from.176 /// </param>177 /// <param name="providerSpecificPickList">178 /// The properties to get from the item(s). If this is empty, null, or "*" all179 /// properties should be returned.180 /// </param>181 /// <param name="context">182 /// The context under which the command is running.183 /// </param>184 /// <returns>185 /// Nothing. A PSObject for each item that the path represents is written186 /// to the context. Each PSObject should187 /// contain a property for those in the providerSpecificPickList.188 /// </returns>189 /// <exception cref="ArgumentNullException">190 /// If <paramref name="path"/> is null.191 /// </exception>192 /// <exception cref="ProviderNotFoundException">193 /// If the <paramref name="path"/> refers to a provider that could not be found.194 /// </exception>195 /// <exception cref="DriveNotFoundException">196 /// If the <paramref name="path"/> refers to a drive that could not be found.197 /// </exception>198 /// <exception cref="ItemNotFoundException">199 /// If <paramref name="path"/> does not contain glob characters and200 /// could not be found.201 /// </exception>202 /// <exception cref="NotSupportedException">203 /// If the provider that the <paramref name="path"/> refers to does204 /// not support this operation.205 /// </exception>206 /// <exception cref="ProviderInvocationException">207 /// If the provider threw an exception.208 /// </exception>209 internal void Get(210 string path,211 Collection<string> providerSpecificPickList,212 CmdletProviderContext context)213 {214 Dbg.Diagnostics.Assert(215 _sessionState != null,216 "The only constructor for this class should always set the sessionState field");217 218 // Parameter validation is done in the session state object219 220 _sessionState.GetProperty(new string[] { path }, providerSpecificPickList, context);221 }222 223 /// <summary>224 /// Gets the dynamic parameters for the get-itemproperty cmdlet.225 /// </summary>226 /// <param name="path">227 /// The path to the item if it was specified on the command line.228 /// </param>229 /// <param name="providerSpecificPickList">230 /// The properties to get from the item(s). If this is empty, null, or "*" all231 /// properties should be returned.232 /// </param>233 /// <param name="context">234 /// The context which the core command is running.235 /// </param>236 /// <returns>237 /// An object that has properties and fields decorated with238 /// parsing attributes similar to a cmdlet class.239 /// </returns>240 /// <exception cref="ProviderNotFoundException">241 /// If the <paramref name="path"/> refers to a provider that could not be found.242 /// </exception>243 /// <exception cref="DriveNotFoundException">244 /// If the <paramref name="path"/> refers to a drive that could not be found.245 /// </exception>246 /// <exception cref="ItemNotFoundException">247 /// If <paramref name="path"/> does not contain glob characters and248 /// could not be found.249 /// </exception>250 /// <exception cref="NotSupportedException">251 /// If the provider that the <paramref name="path"/> refers to does252 /// not support this operation.253 /// </exception>254 /// <exception cref="ProviderInvocationException">255 /// If the provider threw an exception.256 /// </exception>257 internal object GetPropertyDynamicParameters(258 string path,259 Collection<string> providerSpecificPickList,260 CmdletProviderContext context)261 {262 Dbg.Diagnostics.Assert(263 _sessionState != null,264 "The only constructor for this class should always set the sessionState field");265 266 // Parameter validation is done in the session state object267 268 return _sessionState.GetPropertyDynamicParameters(path, providerSpecificPickList, context);269 }270 271 #endregion GetProperty272 273 #region SetProperty274 275 /// <summary>276 /// Sets the specified properties on the specified item(s)277 /// </summary>278 /// <param name="path">279 /// The path to the item to set the properties on.280 /// </param>281 /// <param name="propertyValue">282 /// The properties that are to be set on the item283 /// </param>284 /// <returns>285 /// A PSObject for each item that had the property set on it.286 /// </returns>287 /// <exception cref="ArgumentNullException">288 /// If <paramref name="path"/> or <paramref name="property"/> is null.289 /// </exception>290 /// <exception cref="ProviderNotFoundException">291 /// If the <paramref name="path"/> refers to a provider that could not be found.292 /// </exception>293 /// <exception cref="DriveNotFoundException">294 /// If the <paramref name="path"/> refers to a drive that could not be found.295 /// </exception>296 /// <exception cref="ItemNotFoundException">297 /// If <paramref name="path"/> does not contain glob characters and298 /// could not be found.299 /// </exception>300 /// <exception cref="NotSupportedException">301 /// If the provider that the <paramref name="path"/> refers to does302 /// not support this operation.303 /// </exception>304 /// <exception cref="ProviderInvocationException">305 /// If the provider threw an exception.306 /// </exception>307 public Collection<PSObject> Set(308 string path,309 PSObject propertyValue)310 {311 Dbg.Diagnostics.Assert(312 _sessionState != null,313 "The only constructor for this class should always set the sessionState field");314 315 // Parameter validation is done in the session state object316 317 return _sessionState.SetProperty(new string[] { path }, propertyValue, false, false);318 }319 320 /// <summary>321 /// Sets the specified properties on the specified item(s)322 /// </summary>323 /// <param name="path">324 /// The path(s) to the item(s) to set the properties on.325 /// </param>326 /// <param name="propertyValue">327 /// The properties that are to be set on the item328 /// </param>329 /// <param name="force">330 /// Passed on to providers to force operations.331 /// </param>332 /// <param name="literalPath">333 /// If true, globbing is not done on paths.334 /// </param>335 /// <returns>336 /// A PSObject for each item that had the property set on it.337 /// </returns>338 /// <exception cref="ArgumentNullException">339 /// If <paramref name="path"/> or <paramref name="property"/> is null.340 /// </exception>341 /// <exception cref="ProviderNotFoundException">342 /// If the <paramref name="path"/> refers to a provider that could not be found.343 /// </exception>344 /// <exception cref="DriveNotFoundException">345 /// If the <paramref name="path"/> refers to a drive that could not be found.346 /// </exception>347 /// <exception cref="ItemNotFoundException">348 /// If <paramref name="path"/> does not contain glob characters and349 /// could not be found.350 /// </exception>351 /// <exception cref="NotSupportedException">352 /// If the provider that the <paramref name="path"/> refers to does353 /// not support this operation.354 /// </exception>355 /// <exception cref="ProviderInvocationException">356 /// If the provider threw an exception.357 /// </exception>358 public Collection<PSObject> Set(359 string[] path,360 PSObject propertyValue,361 bool force,362 bool literalPath)363 {364 Dbg.Diagnostics.Assert(365 _sessionState != null,366 "The only constructor for this class should always set the sessionState field");367 368 // Parameter validation is done in the session state object369 370 return _sessionState.SetProperty(path, propertyValue, force, literalPath);371 }372 373 /// <summary>374 /// Sets the specified properties on the specified item(s)375 /// </summary>376 /// <param name="path">377 /// The path to the item to set the properties on.378 /// </param>379 /// <param name="propertyValue">380 /// The properties that are to be set on the item381 /// </param>382 /// <param name="context">383 /// The context under which the command is running.384 /// </param>385 /// <returns>386 /// Nothing. A PSObject for the property that was set is written to the context.387 /// </returns>388 /// <exception cref="ArgumentNullException">389 /// If <paramref name="path"/> or <paramref name="property"/> is null.390 /// </exception>391 /// <exception cref="ProviderNotFoundException">392 /// If the <paramref name="path"/> refers to a provider that could not be found.393 /// </exception>394 /// <exception cref="DriveNotFoundException">395 /// If the <paramref name="path"/> refers to a drive that could not be found.396 /// </exception>397 /// <exception cref="ItemNotFoundException">398 /// If <paramref name="path"/> does not contain glob characters and399 /// could not be found.400 /// </exception>401 /// <exception cref="NotSupportedException">402 /// If the provider that the <paramref name="path"/> refers to does403 /// not support this operation.404 /// </exception>405 /// <exception cref="ProviderInvocationException">406 /// If the provider threw an exception.407 /// </exception>408 internal void Set(409 string path,410 PSObject propertyValue,411 CmdletProviderContext context)412 {413 Dbg.Diagnostics.Assert(414 _sessionState != null,415 "The only constructor for this class should always set the sessionState field");416 417 // Parameter validation is done in the session state object418 419 _sessionState.SetProperty(new string[] { path }, propertyValue, context);420 }421 422 /// <summary>423 /// Gets the dynamic parameters for the set-itemproperty cmdlet.424 /// </summary>425 /// <param name="path">426 /// The path to the item if it was specified on the command line.427 /// </param>428 /// <param name="propertyValue">429 /// The properties that are to be set on the item430 /// </param>431 /// <param name="context">432 /// The context which the core command is running.433 /// </param>434 /// <returns>435 /// An object that has properties and fields decorated with436 /// parsing attributes similar to a cmdlet class.437 /// </returns>438 /// <exception cref="ProviderNotFoundException">439 /// If the <paramref name="path"/> refers to a provider that could not be found.440 /// </exception>441 /// <exception cref="DriveNotFoundException">442 /// If the <paramref name="path"/> refers to a drive that could not be found.443 /// </exception>444 /// <exception cref="ItemNotFoundException">445 /// If <paramref name="path"/> does not contain glob characters and446 /// could not be found.447 /// </exception>448 /// <exception cref="NotSupportedException">449 /// If the provider that the <paramref name="path"/> refers to does450 /// not support this operation.451 /// </exception>452 /// <exception cref="ProviderInvocationException">453 /// If the provider threw an exception.454 /// </exception>455 internal object SetPropertyDynamicParameters(456 string path,457 PSObject propertyValue,458 CmdletProviderContext context)459 {460 Dbg.Diagnostics.Assert(461 _sessionState != null,462 "The only constructor for this class should always set the sessionState field");463 464 // Parameter validation is done in the session state object465 466 return _sessionState.SetPropertyDynamicParameters(path, propertyValue, context);467 }468 469 #endregion SetProperty470 471 #region ClearProperty472 473 /// <summary>474 /// Clear the specified properties from the specified item(s)475 /// </summary>476 /// <param name="path">477 /// The path to the item to clear the properties from.478 /// </param>479 /// <param name="propertyToClear">480 /// The properties to clear from the item(s).481 /// </param>482 /// <exception cref="ArgumentNullException">483 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.484 /// </exception>485 /// <exception cref="ProviderNotFoundException">486 /// If the <paramref name="path"/> refers to a provider that could not be found.487 /// </exception>488 /// <exception cref="DriveNotFoundException">489 /// If the <paramref name="path"/> refers to a drive that could not be found.490 /// </exception>491 /// <exception cref="ItemNotFoundException">492 /// If <paramref name="path"/> does not contain glob characters and493 /// could not be found.494 /// </exception>495 /// <exception cref="NotSupportedException">496 /// If the provider that the <paramref name="path"/> refers to does497 /// not support this operation.498 /// </exception>499 /// <exception cref="ProviderInvocationException">500 /// If the provider threw an exception.501 /// </exception>502 public void Clear(503 string path,504 Collection<string> propertyToClear)505 {506 Dbg.Diagnostics.Assert(507 _sessionState != null,508 "The only constructor for this class should always set the sessionState field");509 510 // Parameter validation is done in the session state object511 512 _sessionState.ClearProperty(new string[] { path }, propertyToClear, false, false);513 }514 515 /// <summary>516 /// Clear the specified properties from the specified item(s)517 /// </summary>518 /// <param name="path">519 /// The path(s) to the item(s) to clear the properties from.520 /// </param>521 /// <param name="propertyToClear">522 /// The properties to clear from the item(s).523 /// </param>524 /// <param name="force">525 /// Passed on to providers to force operations.526 /// </param>527 /// <param name="literalPath">528 /// If true, globbing is not done on paths.529 /// </param>530 /// <exception cref="ArgumentNullException">531 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.532 /// </exception>533 /// <exception cref="ProviderNotFoundException">534 /// If the <paramref name="path"/> refers to a provider that could not be found.535 /// </exception>536 /// <exception cref="DriveNotFoundException">537 /// If the <paramref name="path"/> refers to a drive that could not be found.538 /// </exception>539 /// <exception cref="ItemNotFoundException">540 /// If <paramref name="path"/> does not contain glob characters and541 /// could not be found.542 /// </exception>543 /// <exception cref="NotSupportedException">544 /// If the provider that the <paramref name="path"/> refers to does545 /// not support this operation.546 /// </exception>547 /// <exception cref="ProviderInvocationException">548 /// If the provider threw an exception.549 /// </exception>550 public void Clear(551 string[] path,552 Collection<string> propertyToClear,553 bool force,554 bool literalPath)555 {556 Dbg.Diagnostics.Assert(557 _sessionState != null,558 "The only constructor for this class should always set the sessionState field");559 560 // Parameter validation is done in the session state object561 562 _sessionState.ClearProperty(path, propertyToClear, force, literalPath);563 }564 565 /// <summary>566 /// Clears the specified properties from the specified item(s)567 /// </summary>568 /// <param name="path">569 /// The path to the item to clear the properties from.570 /// </param>571 /// <param name="propertyToClear">572 /// The properties to clear from the item(s).573 /// </param>574 /// <param name="context">575 /// The context under which the command is running.576 /// </param>577 /// <exception cref="ArgumentNullException">578 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.579 /// </exception>580 /// <exception cref="ProviderNotFoundException">581 /// If the <paramref name="path"/> refers to a provider that could not be found.582 /// </exception>583 /// <exception cref="DriveNotFoundException">584 /// If the <paramref name="path"/> refers to a drive that could not be found.585 /// </exception>586 /// <exception cref="ItemNotFoundException">587 /// If <paramref name="path"/> does not contain glob characters and588 /// could not be found.589 /// </exception>590 /// <exception cref="NotSupportedException">591 /// If the provider that the <paramref name="path"/> refers to does592 /// not support this operation.593 /// </exception>594 /// <exception cref="ProviderInvocationException">595 /// If the provider threw an exception.596 /// </exception>597 internal void Clear(598 string path,599 Collection<string> propertyToClear,600 CmdletProviderContext context)601 {602 Dbg.Diagnostics.Assert(603 _sessionState != null,604 "The only constructor for this class should always set the sessionState field");605 606 // Parameter validation is done in the session state object607 608 _sessionState.ClearProperty(new string[] { path }, propertyToClear, context);609 }610 611 /// <summary>612 /// Gets the dynamic parameters for the clear-itemproperty cmdlet.613 /// </summary>614 /// <param name="path">615 /// The path to the item if it was specified on the command line.616 /// </param>617 /// <param name="propertyToClear">618 /// The properties to clear from the item(s).619 /// </param>620 /// <param name="context">621 /// The context which the core command is running.622 /// </param>623 /// <returns>624 /// An object that has properties and fields decorated with625 /// parsing attributes similar to a cmdlet class.626 /// </returns>627 /// <exception cref="ProviderNotFoundException">628 /// If the <paramref name="path"/> refers to a provider that could not be found.629 /// </exception>630 /// <exception cref="DriveNotFoundException">631 /// If the <paramref name="path"/> refers to a drive that could not be found.632 /// </exception>633 /// <exception cref="ItemNotFoundException">634 /// If <paramref name="path"/> does not contain glob characters and635 /// could not be found.636 /// </exception>637 /// <exception cref="NotSupportedException">638 /// If the provider that the <paramref name="path"/> refers to does639 /// not support this operation.640 /// </exception>641 /// <exception cref="ProviderInvocationException">642 /// If the provider threw an exception.643 /// </exception>644 internal object ClearPropertyDynamicParameters(645 string path,646 Collection<string> propertyToClear,647 CmdletProviderContext context)648 {649 Dbg.Diagnostics.Assert(650 _sessionState != null,651 "The only constructor for this class should always set the sessionState field");652 653 // Parameter validation is done in the session state object654 655 return _sessionState.ClearPropertyDynamicParameters(path, propertyToClear, context);656 }657 658 #endregion ClearProperty659 660 #region NewProperty661 662 /// <summary>663 /// Creates a new property on the specified item.664 /// </summary>665 /// <param name="path">666 /// The path to the item on which the new property should be created.667 /// </param>668 /// <param name="propertyName">669 /// The name of the property that should be created.670 /// </param>671 /// <param name="propertyTypeName">672 /// The type of the property that should be created.673 /// </param>674 /// <param name="value">675 /// The new value of the property that should be created.676 /// </param>677 /// <returns>678 /// A PSObject for each item that the property was created on. The PSObject679 /// contains the properties that were created.680 /// </returns>681 /// <exception cref="ArgumentNullException">682 /// If <paramref name="path"/> is null.683 /// </exception>684 /// <exception cref="ProviderNotFoundException">685 /// If the <paramref name="path"/> refers to a provider that could not be found.686 /// </exception>687 /// <exception cref="DriveNotFoundException">688 /// If the <paramref name="path"/> refers to a drive that could not be found.689 /// </exception>690 /// <exception cref="ItemNotFoundException">691 /// If <paramref name="path"/> does not contain glob characters and692 /// could not be found.693 /// </exception>694 /// <exception cref="NotSupportedException">695 /// If the provider that the <paramref name="path"/> refers to does696 /// not support this operation.697 /// </exception>698 /// <exception cref="ProviderInvocationException">699 /// If the provider threw an exception.700 /// </exception>701 public Collection<PSObject> New(702 string path,703 string propertyName,704 string propertyTypeName,705 object value)706 {707 Dbg.Diagnostics.Assert(708 _sessionState != null,709 "The only constructor for this class should always set the sessionState field");710 711 // Parameter validation is done in the session state object712 713 return _sessionState.NewProperty(new string[] { path }, propertyName, propertyTypeName, value, false, false);714 }715 716 /// <summary>717 /// Creates a new property on the specified item.718 /// </summary>719 /// <param name="path">720 /// The path(s) to the item(s0 on which the new property should be created.721 /// </param>722 /// <param name="propertyName">723 /// The name of the property that should be created.724 /// </param>725 /// <param name="propertyTypeName">726 /// The type of the property that should be created.727 /// </param>728 /// <param name="value">729 /// The new value of the property that should be created.730 /// </param>731 /// <param name="force">732 /// Passed on to providers to force operations.733 /// </param>734 /// <param name="literalPath">735 /// If true, globbing is not done on paths.736 /// </param>737 /// <returns>738 /// A PSObject for each item that the property was created on. The PSObject739 /// contains the properties that were created.740 /// </returns>741 /// <exception cref="ArgumentNullException">742 /// If <paramref name="path"/> is null.743 /// </exception>744 /// <exception cref="ProviderNotFoundException">745 /// If the <paramref name="path"/> refers to a provider that could not be found.746 /// </exception>747 /// <exception cref="DriveNotFoundException">748 /// If the <paramref name="path"/> refers to a drive that could not be found.749 /// </exception>750 /// <exception cref="ItemNotFoundException">751 /// If <paramref name="path"/> does not contain glob characters and752 /// could not be found.753 /// </exception>754 /// <exception cref="NotSupportedException">755 /// If the provider that the <paramref name="path"/> refers to does756 /// not support this operation.757 /// </exception>758 /// <exception cref="ProviderInvocationException">759 /// If the provider threw an exception.760 /// </exception>761 public Collection<PSObject> New(762 string[] path,763 string propertyName,764 string propertyTypeName,765 object value,766 bool force,767 bool literalPath)768 {769 Dbg.Diagnostics.Assert(770 _sessionState != null,771 "The only constructor for this class should always set the sessionState field");772 773 // Parameter validation is done in the session state object774 775 return _sessionState.NewProperty(path, propertyName, propertyTypeName, value, force, literalPath);776 }777 778 /// <summary>779 /// Creates a new property on the specified item.780 /// </summary>781 /// <param name="path">782 /// The path to the item on which the new property should be created.783 /// </param>784 /// <param name="propertyName">785 /// The name of the property that should be created.786 /// </param>787 /// <param name="type">788 /// The type of the property that should be created.789 /// </param>790 /// <param name="value">791 /// The new value of the property that should be created.792 /// </param>793 /// <param name="context">794 /// The context under which the command is running.795 /// </param>796 /// <returns>797 /// Nothing. A PSObject for each item that the property was created on798 /// is written to the context. Each PSObject799 /// contains the properties that were created.800 /// </returns>801 /// <exception cref="ArgumentNullException">802 /// If <paramref name="path"/> is null.803 /// </exception>804 /// <exception cref="ProviderNotFoundException">805 /// If the <paramref name="path"/> refers to a provider that could not be found.806 /// </exception>807 /// <exception cref="DriveNotFoundException">808 /// If the <paramref name="path"/> refers to a drive that could not be found.809 /// </exception>810 /// <exception cref="ItemNotFoundException">811 /// If <paramref name="path"/> does not contain glob characters and812 /// could not be found.813 /// </exception>814 /// <exception cref="NotSupportedException">815 /// If the provider that the <paramref name="path"/> refers to does816 /// not support this operation.817 /// </exception>818 /// <exception cref="ProviderInvocationException">819 /// If the provider threw an exception.820 /// </exception>821 internal void New(822 string path,823 string propertyName,824 string type,825 object value,826 CmdletProviderContext context)827 {828 Dbg.Diagnostics.Assert(829 _sessionState != null,830 "The only constructor for this class should always set the sessionState field");831 832 // Parameter validation is done in the session state object833 834 _sessionState.NewProperty(new string[] { path }, propertyName, type, value, context);835 }836 837 /// <summary>838 /// Gets the dynamic parameters for the new-itemproperty cmdlet.839 /// </summary>840 /// <param name="path">841 /// The path to the item if it was specified on the command line.842 /// </param>843 /// <param name="propertyName">844 /// The name of the property that should be created.845 /// </param>846 /// <param name="type">847 /// The type of the property that should be created.848 /// </param>849 /// <param name="value">850 /// The new value of the property that should be created.851 /// </param>852 /// <param name="context">853 /// The context which the core command is running.854 /// </param>855 /// <returns>856 /// An object that has properties and fields decorated with857 /// parsing attributes similar to a cmdlet class.858 /// </returns>859 /// <exception cref="ProviderNotFoundException">860 /// If the <paramref name="path"/> refers to a provider that could not be found.861 /// </exception>862 /// <exception cref="DriveNotFoundException">863 /// If the <paramref name="path"/> refers to a drive that could not be found.864 /// </exception>865 /// <exception cref="ItemNotFoundException">866 /// If <paramref name="path"/> does not contain glob characters and867 /// could not be found.868 /// </exception>869 /// <exception cref="NotSupportedException">870 /// If the provider that the <paramref name="path"/> refers to does871 /// not support this operation.872 /// </exception>873 /// <exception cref="ProviderInvocationException">874 /// If the provider threw an exception.875 /// </exception>876 internal object NewPropertyDynamicParameters(877 string path,878 string propertyName,879 string type,880 object value,881 CmdletProviderContext context)882 {883 Dbg.Diagnostics.Assert(884 _sessionState != null,885 "The only constructor for this class should always set the sessionState field");886 887 // Parameter validation is done in the session state object888 889 return _sessionState.NewPropertyDynamicParameters(path, propertyName, type, value, context);890 }891 892 #endregion NewProperty893 894 #region RemoveProperty895 896 /// <summary>897 /// Removes a property from the specified item(s)898 /// </summary>899 /// <param name="path">900 /// The path to the item(s) on which the property should be removed.901 /// </param>902 /// <param name="propertyName">903 /// The property name that should be removed.904 /// </param>905 /// <exception cref="ArgumentNullException">906 /// If <paramref name="path"/> or <paramref name="property"/> is null.907 /// </exception>908 /// <exception cref="ProviderNotFoundException">909 /// If the <paramref name="path"/> refers to a provider that could not be found.910 /// </exception>911 /// <exception cref="DriveNotFoundException">912 /// If the <paramref name="path"/> refers to a drive that could not be found.913 /// </exception>914 /// <exception cref="ItemNotFoundException">915 /// If <paramref name="path"/> does not contain glob characters and916 /// could not be found.917 /// </exception>918 /// <exception cref="NotSupportedException">919 /// If the provider that the <paramref name="path"/> refers to does920 /// not support this operation.921 /// </exception>922 /// <exception cref="ProviderInvocationException">923 /// If the provider threw an exception.924 /// </exception>925 public void Remove(string path, string propertyName)926 {927 Dbg.Diagnostics.Assert(928 _sessionState != null,929 "The only constructor for this class should always set the sessionState field");930 931 // Parameter validation is done in the session state object932 933 _sessionState.RemoveProperty(new string[] { path }, propertyName, false, false);934 }935 936 /// <summary>937 /// Removes a property from the specified item(s)938 /// </summary>939 /// <param name="path">940 /// The path(s) to the item(s) on which the property should be removed.941 /// </param>942 /// <param name="propertyName">943 /// The property name that should be removed.944 /// </param>945 /// <param name="force">946 /// Passed on to providers to force operations.947 /// </param>948 /// <param name="literalPath">949 /// If true, globbing is not done on paths.950 /// </param>951 /// <exception cref="ArgumentNullException">952 /// If <paramref name="path"/> or <paramref name="property"/> is null.953 /// </exception>954 /// <exception cref="ProviderNotFoundException">955 /// If the <paramref name="path"/> refers to a provider that could not be found.956 /// </exception>957 /// <exception cref="DriveNotFoundException">958 /// If the <paramref name="path"/> refers to a drive that could not be found.959 /// </exception>960 /// <exception cref="ItemNotFoundException">961 /// If <paramref name="path"/> does not contain glob characters and962 /// could not be found.963 /// </exception>964 /// <exception cref="NotSupportedException">965 /// If the provider that the <paramref name="path"/> refers to does966 /// not support this operation.967 /// </exception>968 /// <exception cref="ProviderInvocationException">969 /// If the provider threw an exception.970 /// </exception>971 public void Remove(string[] path, string propertyName, bool force, bool literalPath)972 {973 Dbg.Diagnostics.Assert(974 _sessionState != null,975 "The only constructor for this class should always set the sessionState field");976 977 // Parameter validation is done in the session state object978 979 _sessionState.RemoveProperty(path, propertyName, force, literalPath);980 }981 982 /// <summary>983 /// Removes a property from the specified item(s)984 /// </summary>985 /// <param name="path">986 /// The path to the item(s) on which the property should be removed.987 /// </param>988 /// <param name="propertyName">989 /// The property name that should be removed.990 /// </param>991 /// <param name="context">992 /// The context under which the command is running.993 /// </param>994 /// <exception cref="ArgumentNullException">995 /// If <paramref name="path"/> or <paramref name="property"/> is null.996 /// </exception>997 /// <exception cref="ProviderNotFoundException">998 /// If the <paramref name="path"/> refers to a provider that could not be found.999 /// </exception>1000 /// <exception cref="DriveNotFoundException">1001 /// If the <paramref name="path"/> refers to a drive that could not be found.1002 /// </exception>1003 /// <exception cref="ItemNotFoundException">1004 /// If <paramref name="path"/> does not contain glob characters and1005 /// could not be found.1006 /// </exception>1007 /// <exception cref="NotSupportedException">1008 /// If the provider that the <paramref name="path"/> refers to does1009 /// not support this operation.1010 /// </exception>1011 /// <exception cref="ProviderInvocationException">1012 /// If the provider threw an exception.1013 /// </exception>1014 internal void Remove(1015 string path,1016 string propertyName,1017 CmdletProviderContext context)1018 {1019 Dbg.Diagnostics.Assert(1020 _sessionState != null,1021 "The only constructor for this class should always set the sessionState field");1022 1023 // Parameter validation is done in the session state object1024 1025 _sessionState.RemoveProperty(new string[] { path }, propertyName, context);1026 }1027 1028 /// <summary>1029 /// Gets the dynamic parameters for the remove-itemproperty cmdlet.1030 /// </summary>1031 /// <param name="path">1032 /// The path to the item if it was specified on the command line.1033 /// </param>1034 /// <param name="propertyName">1035 /// The name of the property that should be removed.1036 /// </param>1037 /// <param name="context">1038 /// The context which the core command is running.1039 /// </param>1040 /// <returns>1041 /// An object that has properties and fields decorated with1042 /// parsing attributes similar to a cmdlet class.1043 /// </returns>1044 /// <exception cref="ProviderNotFoundException">1045 /// If the <paramref name="path"/> refers to a provider that could not be found.1046 /// </exception>1047 /// <exception cref="DriveNotFoundException">1048 /// If the <paramref name="path"/> refers to a drive that could not be found.1049 /// </exception>1050 /// <exception cref="ItemNotFoundException">1051 /// If <paramref name="path"/> does not contain glob characters and1052 /// could not be found.1053 /// </exception>1054 /// <exception cref="NotSupportedException">1055 /// If the provider that the <paramref name="path"/> refers to does1056 /// not support this operation.1057 /// </exception>1058 /// <exception cref="ProviderInvocationException">1059 /// If the provider threw an exception.1060 /// </exception>1061 internal object RemovePropertyDynamicParameters(1062 string path,1063 string propertyName,1064 CmdletProviderContext context)1065 {1066 Dbg.Diagnostics.Assert(1067 _sessionState != null,1068 "The only constructor for this class should always set the sessionState field");1069 1070 // Parameter validation is done in the session state object1071 1072 return _sessionState.RemovePropertyDynamicParameters(path, propertyName, context);1073 }1074 1075 #endregion RemoveProperty1076 1077 #region RenameProperty1078 1079 /// <summary>1080 /// Renames a property on the specified item(s)1081 /// </summary>1082 /// <param name="path">1083 /// The path to the item(s) on which the property should be renamed.1084 /// </param>1085 /// <param name="sourceProperty">1086 /// The source name of the property to be renamed.1087 /// </param>1088 /// <param name="destinationProperty">1089 /// The new name of the property.1090 /// </param>1091 /// <returns>1092 /// A PSObject for each item that is the new property after the rename.1093 /// </returns>1094 /// <exception cref="ArgumentNullException">1095 /// If <paramref name="path"/>, <paramref name="sourceProperty"/>,1096 /// or <paramref name="destinationProperty"/> is null.1097 /// </exception>1098 /// <exception cref="ProviderNotFoundException">1099 /// If the <paramref name="path"/> refers to a provider that could not be found.1100 /// </exception>1101 /// <exception cref="DriveNotFoundException">1102 /// If the <paramref name="path"/> refers to a drive that could not be found.1103 /// </exception>1104 /// <exception cref="ItemNotFoundException">1105 /// If <paramref name="path"/> does not contain glob characters and1106 /// could not be found.1107 /// </exception>1108 /// <exception cref="NotSupportedException">1109 /// If the provider that the <paramref name="path"/> refers to does1110 /// not support this operation.1111 /// </exception>1112 /// <exception cref="ProviderInvocationException">1113 /// If the provider threw an exception.1114 /// </exception>1115 public Collection<PSObject> Rename(1116 string path,1117 string sourceProperty,1118 string destinationProperty)1119 {1120 Dbg.Diagnostics.Assert(1121 _sessionState != null,1122 "The only constructor for this class should always set the sessionState field");1123 1124 // Parameter validation is done in the session state object1125 1126 return _sessionState.RenameProperty(new string[] { path }, sourceProperty, destinationProperty, false, false);1127 }1128 1129 /// <summary>1130 /// Renames a property on the specified item(s)1131 /// </summary>1132 /// <param name="path">1133 /// The path(s) to the item(s) on which the property should be renamed.1134 /// </param>1135 /// <param name="sourceProperty">1136 /// The source name of the property to be renamed.1137 /// </param>1138 /// <param name="destinationProperty">1139 /// The new name of the property.1140 /// </param>1141 /// <param name="force">1142 /// Passed on to providers to force operations.1143 /// </param>1144 /// <param name="literalPath">1145 /// If true, globbing is not done on paths.1146 /// </param>1147 /// <returns>1148 /// A PSObject for each item that is the new property after the rename.1149 /// </returns>1150 /// <exception cref="ArgumentNullException">1151 /// If <paramref name="path"/>, <paramref name="sourceProperty"/>,1152 /// or <paramref name="destinationProperty"/> is null.1153 /// </exception>1154 /// <exception cref="ProviderNotFoundException">1155 /// If the <paramref name="path"/> refers to a provider that could not be found.1156 /// </exception>1157 /// <exception cref="DriveNotFoundException">1158 /// If the <paramref name="path"/> refers to a drive that could not be found.1159 /// </exception>1160 /// <exception cref="ItemNotFoundException">1161 /// If <paramref name="path"/> does not contain glob characters and1162 /// could not be found.1163 /// </exception>1164 /// <exception cref="NotSupportedException">1165 /// If the provider that the <paramref name="path"/> refers to does1166 /// not support this operation.1167 /// </exception>1168 /// <exception cref="ProviderInvocationException">1169 /// If the provider threw an exception.1170 /// </exception>1171 public Collection<PSObject> Rename(1172 string[] path,1173 string sourceProperty,1174 string destinationProperty,1175 bool force,1176 bool literalPath)1177 {1178 Dbg.Diagnostics.Assert(1179 _sessionState != null,1180 "The only constructor for this class should always set the sessionState field");1181 1182 // Parameter validation is done in the session state object1183 1184 return _sessionState.RenameProperty(path, sourceProperty, destinationProperty, force, literalPath);1185 }1186 1187 /// <summary>1188 /// Renames a property on the specified item(s)1189 /// </summary>1190 /// <param name="path">1191 /// The path to the item(s) on which the property should be renamed.1192 /// </param>1193 /// <param name="sourceProperty">1194 /// The source name of the property to be renamed.1195 /// </param>1196 /// <param name="destinationProperty">1197 /// The new name of the property.1198 /// </param>1199 /// <param name="context">1200 /// The context under which the command is running.