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 Item 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 ItemCmdletProviderIntrinsics15 {16 #region Constructors17 18 /// <summary>19 /// Hide the default constructor since we always require an instance of SessionState.20 /// </summary>21 private ItemCmdletProviderIntrinsics()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 ItemCmdletProviderIntrinsics(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 class.53 /// </param>54 /// <exception cref="ArgumentNullException">55 /// If <paramref name="sessionState"/> is null.56 /// </exception>57 internal ItemCmdletProviderIntrinsics(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 GetItem72 73 /// <summary>74 /// Gets the item at the specified path.75 /// </summary>76 /// <param name="path">77 /// The path to the item to retrieve. It may be a drive or provider-qualified path and may include78 /// glob characters.79 /// </param>80 /// <returns>81 /// The object(s) at the specified path.82 /// </returns>83 /// <exception cref="ArgumentNullException">84 /// If <paramref name="path"/> is null.85 /// </exception>86 /// <exception cref="ProviderNotFoundException">87 /// If the <paramref name="path"/> refers to a provider that could not be found.88 /// </exception>89 /// <exception cref="DriveNotFoundException">90 /// If the <paramref name="path"/> refers to a drive that could not be found.91 /// </exception>92 /// <exception cref="ItemNotFoundException">93 /// If <paramref name="path"/> does not contain glob characters and94 /// could not be found.95 /// </exception>96 /// <exception cref="NotSupportedException">97 /// If the provider that the <paramref name="path"/> refers to does98 /// not support this operation.99 /// </exception>100 /// <exception cref="ProviderInvocationException">101 /// If the provider threw an exception.102 /// </exception>103 public Collection<PSObject> Get(string path)104 {105 Dbg.Diagnostics.Assert(106 _sessionState != null,107 "The only constructor for this class should always set the sessionState field");108 109 // Parameter validation is done in the session state object110 111 return _sessionState.GetItem(new string[] { path }, false, false);112 }113 114 /// <summary>115 /// Gets the item at the specified path.116 /// </summary>117 /// <param name="path">118 /// The path(s) to the item(s) to retrieve. They may be a drive or provider-qualified path(s) and may include119 /// glob characters.120 /// </param>121 /// <param name="force">122 /// Passed on to providers to force operations.123 /// </param>124 /// <param name="literalPath">125 /// If true, globbing is not done on paths.126 /// </param>127 /// <returns>128 /// The object(s) at the specified path.129 /// </returns>130 /// <exception cref="ArgumentNullException">131 /// If <paramref name="path"/> is null.132 /// </exception>133 /// <exception cref="ProviderNotFoundException">134 /// If the <paramref name="path"/> refers to a provider that could not be found.135 /// </exception>136 /// <exception cref="DriveNotFoundException">137 /// If the <paramref name="path"/> refers to a drive that could not be found.138 /// </exception>139 /// <exception cref="ItemNotFoundException">140 /// If <paramref name="path"/> does not contain glob characters and141 /// could not be found.142 /// </exception>143 /// <exception cref="NotSupportedException">144 /// If the provider that the <paramref name="path"/> refers to does145 /// not support this operation.146 /// </exception>147 /// <exception cref="ProviderInvocationException">148 /// If the provider threw an exception.149 /// </exception>150 public Collection<PSObject> Get(string[] path, bool force, bool literalPath)151 {152 Dbg.Diagnostics.Assert(153 _sessionState != null,154 "The only constructor for this class should always set the sessionState field");155 156 // Parameter validation is done in the session state object157 158 return _sessionState.GetItem(path, force, literalPath);159 }160 161 /// <summary>162 /// Gets the item at the specified path.163 /// </summary>164 /// <param name="path">165 /// The path to the item to retrieve. It may be a drive or provider-qualified path and may include166 /// glob characters.167 /// </param>168 /// <param name="context">169 /// The context under which the command is running.170 /// </param>171 /// <returns>172 /// Nothing. The object(s) at the specified path are written to the context.173 /// </returns>174 /// <exception cref="ArgumentNullException">175 /// If <paramref name="path"/> is null.176 /// </exception>177 /// <exception cref="ProviderNotFoundException">178 /// If the <paramref name="path"/> refers to a provider that could not be found.179 /// </exception>180 /// <exception cref="DriveNotFoundException">181 /// If the <paramref name="path"/> refers to a drive that could not be found.182 /// </exception>183 /// <exception cref="ItemNotFoundException">184 /// If <paramref name="path"/> does not contain glob characters and185 /// could not be found.186 /// </exception>187 /// <exception cref="NotSupportedException">188 /// If the provider that the <paramref name="path"/> refers to does189 /// not support this operation.190 /// </exception>191 /// <exception cref="ProviderInvocationException">192 /// If the provider threw an exception.193 /// </exception>194 internal void Get(string path, CmdletProviderContext context)195 {196 Dbg.Diagnostics.Assert(197 _sessionState != null,198 "The only constructor for this class should always set the sessionState field");199 200 // Parameter validation is done in the session state object201 202 _sessionState.GetItem(new string[] { path }, context);203 }204 205 /// <summary>206 /// Gets the dynamic parameters for the get-item cmdlet.207 /// </summary>208 /// <param name="path">209 /// The path to the item if it was specified on the command line.210 /// </param>211 /// <param name="context">212 /// The context which the core command is running.213 /// </param>214 /// <returns>215 /// An object that has properties and fields decorated with216 /// parsing attributes similar to a cmdlet class.217 /// </returns>218 /// <exception cref="ProviderNotFoundException">219 /// If the <paramref name="path"/> refers to a provider that could not be found.220 /// </exception>221 /// <exception cref="DriveNotFoundException">222 /// If the <paramref name="path"/> refers to a drive that could not be found.223 /// </exception>224 /// <exception cref="ItemNotFoundException">225 /// If <paramref name="path"/> does not contain glob characters and226 /// could not be found.227 /// </exception>228 /// <exception cref="NotSupportedException">229 /// If the provider that the <paramref name="path"/> refers to does230 /// not support this operation.231 /// </exception>232 /// <exception cref="ProviderInvocationException">233 /// If the provider threw an exception.234 /// </exception>235 internal object GetItemDynamicParameters(string path, CmdletProviderContext context)236 {237 Dbg.Diagnostics.Assert(238 _sessionState != null,239 "The only constructor for this class should always set the sessionState field");240 241 // Parameter validation is done in the session state object242 243 return _sessionState.GetItemDynamicParameters(path, context);244 }245 246 #endregion GetItem247 248 #region SetItem249 250 /// <summary>251 /// Sets the item at the specified path.252 /// </summary>253 /// <param name="path">254 /// The path to the item to set. It may be a drive or provider-qualified path and may include255 /// glob characters.256 /// </param>257 /// <param name="value">258 /// The new value to set the item to.259 /// </param>260 /// <returns>261 /// The object(s) set at the specified path.262 /// </returns>263 /// <exception cref="ArgumentNullException">264 /// If <paramref name="path"/> is null.265 /// </exception>266 /// <exception cref="ProviderNotFoundException">267 /// If the <paramref name="path"/> refers to a provider that could not be found.268 /// </exception>269 /// <exception cref="DriveNotFoundException">270 /// If the <paramref name="path"/> refers to a drive that could not be found.271 /// </exception>272 /// <exception cref="ItemNotFoundException">273 /// If <paramref name="path"/> does not contain glob characters and274 /// could not be found.275 /// </exception>276 /// <exception cref="NotSupportedException">277 /// If the provider that the <paramref name="path"/> refers to does278 /// not support this operation.279 /// </exception>280 /// <exception cref="ProviderInvocationException">281 /// If the provider threw an exception.282 /// </exception>283 public Collection<PSObject> Set(string path, object value)284 {285 Dbg.Diagnostics.Assert(286 _sessionState != null,287 "The only constructor for this class should always set the sessionState field");288 289 // Parameter validation is done in the session state object290 291 return _sessionState.SetItem(new string[] { path }, value, false, false);292 }293 294 /// <summary>295 /// Sets the item at the specified path.296 /// </summary>297 /// <param name="path">298 /// The path(s) to the item(s) to set. They may be drive or provider-qualified paths and may include299 /// glob characters.300 /// </param>301 /// <param name="value">302 /// The new value to set the item to.303 /// </param>304 /// <param name="force">305 /// Passed on to providers to force operations.306 /// </param>307 /// <param name="literalPath">308 /// If true, globbing is not done on paths.309 /// </param>310 /// <returns>311 /// The object(s) set at the specified path.312 /// </returns>313 /// <exception cref="ArgumentNullException">314 /// If <paramref name="path"/> is null.315 /// </exception>316 /// <exception cref="ProviderNotFoundException">317 /// If the <paramref name="path"/> refers to a provider that could not be found.318 /// </exception>319 /// <exception cref="DriveNotFoundException">320 /// If the <paramref name="path"/> refers to a drive that could not be found.321 /// </exception>322 /// <exception cref="ItemNotFoundException">323 /// If <paramref name="path"/> does not contain glob characters and324 /// could not be found.325 /// </exception>326 /// <exception cref="NotSupportedException">327 /// If the provider that the <paramref name="path"/> refers to does328 /// not support this operation.329 /// </exception>330 /// <exception cref="ProviderInvocationException">331 /// If the provider threw an exception.332 /// </exception>333 public Collection<PSObject> Set(string[] path, object value, bool force, bool literalPath)334 {335 Dbg.Diagnostics.Assert(336 _sessionState != null,337 "The only constructor for this class should always set the sessionState field");338 339 // Parameter validation is done in the session state object340 341 return _sessionState.SetItem(path, value, force, literalPath);342 }343 344 /// <summary>345 /// Sets the item at the specified path.346 /// </summary>347 /// <param name="path">348 /// The path to the item to set. It may be a drive or provider-qualified path and may include349 /// glob characters.350 /// </param>351 /// <param name="value">352 /// The new value to set the item to.353 /// </param>354 /// <param name="context">355 /// The context under which the command is running.356 /// </param>357 /// <returns>358 /// Nothing. The object(s) set at the specified path are written to the context.359 /// </returns>360 /// <exception cref="ArgumentNullException">361 /// If <paramref name="path"/> is null.362 /// </exception>363 /// <exception cref="ProviderNotFoundException">364 /// If the <paramref name="path"/> refers to a provider that could not be found.365 /// </exception>366 /// <exception cref="DriveNotFoundException">367 /// If the <paramref name="path"/> refers to a drive that could not be found.368 /// </exception>369 /// <exception cref="ItemNotFoundException">370 /// If <paramref name="path"/> does not contain glob characters and371 /// could not be found.372 /// </exception>373 /// <exception cref="NotSupportedException">374 /// If the provider that the <paramref name="path"/> refers to does375 /// not support this operation.376 /// </exception>377 /// <exception cref="ProviderInvocationException">378 /// If the provider threw an exception.379 /// </exception>380 internal void Set(string path, object value, CmdletProviderContext context)381 {382 Dbg.Diagnostics.Assert(383 _sessionState != null,384 "The only constructor for this class should always set the sessionState field");385 386 // Parameter validation is done in the session state object387 388 _sessionState.SetItem(new string[] { path }, value, context);389 }390 391 /// <summary>392 /// Gets the dynamic parameters for the set-item cmdlet.393 /// </summary>394 /// <param name="path">395 /// The path to the item if it was specified on the command line.396 /// </param>397 /// <param name="value">398 /// The new value of the item at the specified path.399 /// </param>400 /// <param name="context">401 /// The context which the core command is running.402 /// </param>403 /// <returns>404 /// An object that has properties and fields decorated with405 /// parsing attributes similar to a cmdlet class.406 /// </returns>407 /// <exception cref="ProviderNotFoundException">408 /// If the <paramref name="path"/> refers to a provider that could not be found.409 /// </exception>410 /// <exception cref="DriveNotFoundException">411 /// If the <paramref name="path"/> refers to a drive that could not be found.412 /// </exception>413 /// <exception cref="ItemNotFoundException">414 /// If <paramref name="path"/> does not contain glob characters and415 /// could not be found.416 /// </exception>417 /// <exception cref="NotSupportedException">418 /// If the provider that the <paramref name="path"/> refers to does419 /// not support this operation.420 /// </exception>421 /// <exception cref="ProviderInvocationException">422 /// If the provider threw an exception.423 /// </exception>424 internal object SetItemDynamicParameters(425 string path,426 object value,427 CmdletProviderContext context)428 {429 Dbg.Diagnostics.Assert(430 _sessionState != null,431 "The only constructor for this class should always set the sessionState field");432 433 // Parameter validation is done in the session state object434 435 return _sessionState.SetItemDynamicParameters(path, value, context);436 }437 438 #endregion SetItem439 440 #region ClearItem441 442 /// <summary>443 /// Clears the item at the specified path.444 /// </summary>445 /// <param name="path">446 /// The path to the item to clear. It may be a drive or provider-qualified path and may include447 /// glob characters.448 /// </param>449 /// <returns>450 /// The object(s) cleared at the specified path.451 /// </returns>452 /// <exception cref="ArgumentNullException">453 /// If <paramref name="path"/> is null.454 /// </exception>455 /// <exception cref="ProviderNotFoundException">456 /// If the <paramref name="path"/> refers to a provider that could not be found.457 /// </exception>458 /// <exception cref="DriveNotFoundException">459 /// If the <paramref name="path"/> refers to a drive that could not be found.460 /// </exception>461 /// <exception cref="ItemNotFoundException">462 /// If <paramref name="path"/> does not contain glob characters and463 /// could not be found.464 /// </exception>465 /// <exception cref="NotSupportedException">466 /// If the provider that the <paramref name="path"/> refers to does467 /// not support this operation.468 /// </exception>469 /// <exception cref="ProviderInvocationException">470 /// If the provider threw an exception.471 /// </exception>472 public Collection<PSObject> Clear(string path)473 {474 Dbg.Diagnostics.Assert(475 _sessionState != null,476 "The only constructor for this class should always set the sessionState field");477 478 // Parameter validation is done in the session state object479 480 return _sessionState.ClearItem(new string[] { path }, false, false);481 }482 483 /// <summary>484 /// Clears the item at the specified path.485 /// </summary>486 /// <param name="path">487 /// The path(s) to the item to clear. It may be a drive or provider-qualified path and may include488 /// glob characters.489 /// </param>490 /// <param name="force">491 /// Passed on to providers to force operations.492 /// </param>493 /// <param name="literalPath">494 /// If true, globbing is not done on paths.495 /// </param>496 /// <returns>497 /// The object(s) cleared at the specified path.498 /// </returns>499 /// <exception cref="ArgumentNullException">500 /// If <paramref name="path"/> is null.501 /// </exception>502 /// <exception cref="ProviderNotFoundException">503 /// If the <paramref name="path"/> refers to a provider that could not be found.504 /// </exception>505 /// <exception cref="DriveNotFoundException">506 /// If the <paramref name="path"/> refers to a drive that could not be found.507 /// </exception>508 /// <exception cref="ItemNotFoundException">509 /// If <paramref name="path"/> does not contain glob characters and510 /// could not be found.511 /// </exception>512 /// <exception cref="NotSupportedException">513 /// If the provider that the <paramref name="path"/> refers to does514 /// not support this operation.515 /// </exception>516 /// <exception cref="ProviderInvocationException">517 /// If the provider threw an exception.518 /// </exception>519 public Collection<PSObject> Clear(string[] path, bool force, bool literalPath)520 {521 Dbg.Diagnostics.Assert(522 _sessionState != null,523 "The only constructor for this class should always set the sessionState field");524 525 // Parameter validation is done in the session state object526 527 return _sessionState.ClearItem(path, force, literalPath);528 }529 530 /// <summary>531 /// Clears the item at the specified path.532 /// </summary>533 /// <param name="path">534 /// The path to the item to be cleared. It may be a drive or provider-qualified path and may include535 /// glob characters.536 /// </param>537 /// <param name="context">538 /// The context under which the command is running.539 /// </param>540 /// <returns>541 /// Nothing. The object(s) cleared at the specified path are written to the context.542 /// </returns>543 /// <exception cref="ArgumentNullException">544 /// If <paramref name="path"/> is null.545 /// </exception>546 /// <exception cref="ProviderNotFoundException">547 /// If the <paramref name="path"/> refers to a provider that could not be found.548 /// </exception>549 /// <exception cref="DriveNotFoundException">550 /// If the <paramref name="path"/> refers to a drive that could not be found.551 /// </exception>552 /// <exception cref="ItemNotFoundException">553 /// If <paramref name="path"/> does not contain glob characters and554 /// could not be found.555 /// </exception>556 /// <exception cref="NotSupportedException">557 /// If the provider that the <paramref name="path"/> refers to does558 /// not support this operation.559 /// </exception>560 /// <exception cref="ProviderInvocationException">561 /// If the provider threw an exception.562 /// </exception>563 internal void Clear(string path, CmdletProviderContext context)564 {565 Dbg.Diagnostics.Assert(566 _sessionState != null,567 "The only constructor for this class should always set the sessionState field");568 569 // Parameter validation is done in the session state object570 571 _sessionState.ClearItem(new string[] { path }, context);572 }573 574 /// <summary>575 /// Gets the dynamic parameters for the clear-item cmdlet.576 /// </summary>577 /// <param name="path">578 /// The path to the item if it was specified on the command line.579 /// </param>580 /// <param name="context">581 /// The context which the core command is running.582 /// </param>583 /// <returns>584 /// An object that has properties and fields decorated with585 /// parsing attributes similar to a cmdlet class.586 /// </returns>587 /// <exception cref="ProviderNotFoundException">588 /// If the <paramref name="path"/> refers to a provider that could not be found.589 /// </exception>590 /// <exception cref="DriveNotFoundException">591 /// If the <paramref name="path"/> refers to a drive that could not be found.592 /// </exception>593 /// <exception cref="ItemNotFoundException">594 /// If <paramref name="path"/> does not contain glob characters and595 /// could not be found.596 /// </exception>597 /// <exception cref="NotSupportedException">598 /// If the provider that the <paramref name="path"/> refers to does599 /// not support this operation.600 /// </exception>601 /// <exception cref="ProviderInvocationException">602 /// If the provider threw an exception.603 /// </exception>604 internal object ClearItemDynamicParameters(string path, CmdletProviderContext context)605 {606 Dbg.Diagnostics.Assert(607 _sessionState != null,608 "The only constructor for this class should always set the sessionState field");609 610 // Parameter validation is done in the session state object611 612 return _sessionState.ClearItemDynamicParameters(path, context);613 }614 615 #endregion ClearItem616 617 #region InvokeDefaultAction618 619 /// <summary>620 /// Invokes the default action of the item at the specified path.621 /// </summary>622 /// <param name="path">623 /// The path to the item to invoke. It may be a drive or provider-qualified path and may include624 /// glob characters.625 /// </param>626 /// <exception cref="ArgumentNullException">627 /// If <paramref name="path"/> is null.628 /// </exception>629 /// <exception cref="ProviderNotFoundException">630 /// If the <paramref name="path"/> refers to a provider that could not be found.631 /// </exception>632 /// <exception cref="DriveNotFoundException">633 /// If the <paramref name="path"/> refers to a drive that could not be found.634 /// </exception>635 /// <exception cref="ItemNotFoundException">636 /// If <paramref name="path"/> does not contain glob characters and637 /// could not be found.638 /// </exception>639 /// <exception cref="NotSupportedException">640 /// If the provider that the <paramref name="path"/> refers to does641 /// not support this operation.642 /// </exception>643 /// <exception cref="ProviderInvocationException">644 /// If the provider threw an exception.645 /// </exception>646 public void Invoke(string path)647 {648 Dbg.Diagnostics.Assert(649 _sessionState != null,650 "The only constructor for this class should always set the sessionState field");651 652 // Parameter validation is done in the session state object653 654 _sessionState.InvokeDefaultAction(new string[] { path }, false);655 }656 657 /// <summary>658 /// Invokes the default action of the item(s) at the specified path(s).659 /// </summary>660 /// <param name="path">661 /// The path(s) to the item(s) to invoke. They may be drive or provider-qualified paths and may include662 /// glob characters.663 /// </param>664 /// <param name="literalPath">665 /// If true, globbing is not done on paths.666 /// </param>667 /// <exception cref="ArgumentNullException">668 /// If <paramref name="path"/> is null.669 /// </exception>670 /// <exception cref="ProviderNotFoundException">671 /// If the <paramref name="path"/> refers to a provider that could not be found.672 /// </exception>673 /// <exception cref="DriveNotFoundException">674 /// If the <paramref name="path"/> refers to a drive that could not be found.675 /// </exception>676 /// <exception cref="ItemNotFoundException">677 /// If <paramref name="path"/> does not contain glob characters and678 /// could not be found.679 /// </exception>680 /// <exception cref="NotSupportedException">681 /// If the provider that the <paramref name="path"/> refers to does682 /// not support this operation.683 /// </exception>684 /// <exception cref="ProviderInvocationException">685 /// If the provider threw an exception.686 /// </exception>687 public void Invoke(string[] path, bool literalPath)688 {689 Dbg.Diagnostics.Assert(690 _sessionState != null,691 "The only constructor for this class should always set the sessionState field");692 693 // Parameter validation is done in the session state object694 695 _sessionState.InvokeDefaultAction(path, literalPath);696 }697 698 /// <summary>699 /// Invokes the default action for the item at the specified path.700 /// </summary>701 /// <param name="path">702 /// The path to the item to be invoked. It may be a drive or provider-qualified path and may include703 /// glob characters.704 /// </param>705 /// <param name="context">706 /// The context under which the command is running.707 /// </param>708 /// <exception cref="ArgumentNullException">709 /// If <paramref name="path"/> is null.710 /// </exception>711 /// <exception cref="ProviderNotFoundException">712 /// If the <paramref name="path"/> refers to a provider that could not be found.713 /// </exception>714 /// <exception cref="DriveNotFoundException">715 /// If the <paramref name="path"/> refers to a drive that could not be found.716 /// </exception>717 /// <exception cref="ItemNotFoundException">718 /// If <paramref name="path"/> does not contain glob characters and719 /// could not be found.720 /// </exception>721 /// <exception cref="NotSupportedException">722 /// If the provider that the <paramref name="path"/> refers to does723 /// not support this operation.724 /// </exception>725 /// <exception cref="ProviderInvocationException">726 /// If the provider threw an exception.727 /// </exception>728 internal void Invoke(string path, CmdletProviderContext context)729 {730 Dbg.Diagnostics.Assert(731 _sessionState != null,732 "The only constructor for this class should always set the sessionState field");733 734 // Parameter validation is done in the session state object735 736 _sessionState.InvokeDefaultAction(new string[] { path }, context);737 }738 739 /// <summary>740 /// Gets the dynamic parameters for the invoke-item cmdlet.741 /// </summary>742 /// <param name="path">743 /// The path to the item if it was specified on the command line.744 /// </param>745 /// <param name="context">746 /// The context which the core command is running.747 /// </param>748 /// <returns>749 /// An object that has properties and fields decorated with750 /// parsing attributes similar to a cmdlet class.751 /// </returns>752 /// <exception cref="ProviderNotFoundException">753 /// If the <paramref name="path"/> refers to a provider that could not be found.754 /// </exception>755 /// <exception cref="DriveNotFoundException">756 /// If the <paramref name="path"/> refers to a drive that could not be found.757 /// </exception>758 /// <exception cref="ItemNotFoundException">759 /// If <paramref name="path"/> does not contain glob characters and760 /// could not be found.761 /// </exception>762 /// <exception cref="NotSupportedException">763 /// If the provider that the <paramref name="path"/> refers to does764 /// not support this operation.765 /// </exception>766 /// <exception cref="ProviderInvocationException">767 /// If the provider threw an exception.768 /// </exception>769 internal object InvokeItemDynamicParameters(string path, CmdletProviderContext context)770 {771 Dbg.Diagnostics.Assert(772 _sessionState != null,773 "The only constructor for this class should always set the sessionState field");774 775 // Parameter validation is done in the session state object776 777 return _sessionState.InvokeDefaultActionDynamicParameters(path, context);778 }779 780 #endregion InvokeDefaultAction781 782 #region RenameItem783 784 /// <summary>785 /// Renames the item at the given path.786 /// </summary>787 /// <param name="path">788 /// The path to the item to rename. It may be a drive or provider-qualified path and may include789 /// glob characters.790 /// </param>791 /// <param name="newName">792 /// The new name of the item.793 /// </param>794 /// <returns>795 /// The item(s) that were renamed.796 /// </returns>797 /// <exception cref="ArgumentNullException">798 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.799 /// </exception>800 /// <exception cref="ProviderNotFoundException">801 /// If the <paramref name="path"/> refers to a provider that could not be found.802 /// </exception>803 /// <exception cref="DriveNotFoundException">804 /// If the <paramref name="path"/> refers to a drive that could not be found.805 /// </exception>806 /// <exception cref="ItemNotFoundException">807 /// If <paramref name="path"/> does not contain glob characters and808 /// could not be found.809 /// </exception>810 /// <exception cref="NotSupportedException">811 /// If the provider that the <paramref name="path"/> refers to does812 /// not support this operation.813 /// </exception>814 /// <exception cref="ProviderInvocationException">815 /// If the provider threw an exception.816 /// </exception>817 public Collection<PSObject> Rename(string path, string newName)818 {819 Dbg.Diagnostics.Assert(820 _sessionState != null,821 "The only constructor for this class should always set the sessionState field");822 823 // Parameter validation is done in the session state object824 825 return _sessionState.RenameItem(path, newName, false);826 }827 828 /// <summary>829 /// Renames the item at the given path.830 /// </summary>831 /// <param name="path">832 /// The path to the item to rename. It may be a drive or provider-qualified path and may include833 /// glob characters.834 /// </param>835 /// <param name="newName">836 /// The new name of the item.837 /// </param>838 /// <param name="force">839 /// Passed on to providers to force operations.840 /// </param>841 /// <returns>842 /// The item(s) that were renamed.843 /// </returns>844 /// <exception cref="ArgumentNullException">845 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.846 /// </exception>847 /// <exception cref="ProviderNotFoundException">848 /// If the <paramref name="path"/> refers to a provider that could not be found.849 /// </exception>850 /// <exception cref="DriveNotFoundException">851 /// If the <paramref name="path"/> refers to a drive that could not be found.852 /// </exception>853 /// <exception cref="ItemNotFoundException">854 /// If <paramref name="path"/> does not contain glob characters and855 /// could not be found.856 /// </exception>857 /// <exception cref="NotSupportedException">858 /// If the provider that the <paramref name="path"/> refers to does859 /// not support this operation.860 /// </exception>861 /// <exception cref="ProviderInvocationException">862 /// If the provider threw an exception.863 /// </exception>864 public Collection<PSObject> Rename(string path, string newName, bool force)865 {866 Dbg.Diagnostics.Assert(867 _sessionState != null,868 "The only constructor for this class should always set the sessionState field");869 870 // Parameter validation is done in the session state object871 872 return _sessionState.RenameItem(path, newName, force);873 }874 875 /// <summary>876 /// Renames the item at the given path.877 /// </summary>878 /// <param name="path">879 /// The path to the item to rename. It may be a drive or provider-qualified path and may include880 /// glob characters.881 /// </param>882 /// <param name="newName">883 /// The new name of the item.884 /// </param>885 /// <param name="context">886 /// The context under which the command is running.887 /// </param>888 /// <returns>889 /// Nothing. The item(s) that get renamed are written to the context.890 /// </returns>891 /// <exception cref="ArgumentNullException">892 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.893 /// </exception>894 /// <exception cref="ProviderNotFoundException">895 /// If the <paramref name="path"/> refers to a provider that could not be found.896 /// </exception>897 /// <exception cref="DriveNotFoundException">898 /// If the <paramref name="path"/> refers to a drive that could not be found.899 /// </exception>900 /// <exception cref="ItemNotFoundException">901 /// If <paramref name="path"/> does not contain glob characters and902 /// could not be found.903 /// </exception>904 /// <exception cref="NotSupportedException">905 /// If the provider that the <paramref name="path"/> refers to does906 /// not support this operation.907 /// </exception>908 /// <exception cref="ProviderInvocationException">909 /// If the provider threw an exception.910 /// </exception>911 internal void Rename(912 string path,913 string newName,914 CmdletProviderContext context)915 {916 Dbg.Diagnostics.Assert(917 _sessionState != null,918 "The only constructor for this class should always set the sessionState field");919 920 // Parameter validation is done in the session state object921 922 _sessionState.RenameItem(path, newName, context);923 }924 925 /// <summary>926 /// Gets the dynamic parameters for the rename-item cmdlet.927 /// </summary>928 /// <param name="path">929 /// The path to the item if it was specified on the command line.930 /// </param>931 /// <param name="newName">932 /// The new name of the item.933 /// </param>934 /// <param name="context">935 /// The context which the core command is running.936 /// </param>937 /// <returns>938 /// An object that has properties and fields decorated with939 /// parsing attributes similar to a cmdlet class.940 /// </returns>941 /// <exception cref="ProviderNotFoundException">942 /// If the <paramref name="path"/> refers to a provider that could not be found.943 /// </exception>944 /// <exception cref="DriveNotFoundException">945 /// If the <paramref name="path"/> refers to a drive that could not be found.946 /// </exception>947 /// <exception cref="ItemNotFoundException">948 /// If <paramref name="path"/> does not contain glob characters and949 /// could not be found.950 /// </exception>951 /// <exception cref="NotSupportedException">952 /// If the provider that the <paramref name="path"/> refers to does953 /// not support this operation.954 /// </exception>955 /// <exception cref="ProviderInvocationException">956 /// If the provider threw an exception.957 /// </exception>958 internal object RenameItemDynamicParameters(959 string path,960 string newName,961 CmdletProviderContext context)962 {963 Dbg.Diagnostics.Assert(964 _sessionState != null,965 "The only constructor for this class should always set the sessionState field");966 967 // Parameter validation is done in the session state object968 969 return _sessionState.RenameItemDynamicParameters(path, newName, context);970 }971 972 #endregion RenameItem973 974 #region NewItem975 976 /// <summary>977 /// Creates a new item at the given path.978 /// </summary>979 /// <param name="path">980 /// The path to the container to create item in. It may be a drive or provider-qualified path and may include981 /// glob characters.982 /// </param>983 /// <param name="name">984 /// The name of the new item to create.985 /// </param>986 /// <param name="itemTypeName">987 /// The type of the new item to create.988 /// </param>989 /// <param name="content">990 /// The content of the new item to create.991 /// </param>992 /// <returns>993 /// The item that was created.994 /// </returns>995 /// <exception cref="ArgumentNullException">996 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.997 /// </exception>998 /// <exception cref="ProviderNotFoundException">999 /// If the <paramref name="path"/> refers to a provider that could not be found.1000 /// </exception>1001 /// <exception cref="DriveNotFoundException">1002 /// If the <paramref name="path"/> refers to a drive that could not be found.1003 /// </exception>1004 /// <exception cref="ItemNotFoundException">1005 /// If <paramref name="path"/> does not contain glob characters and1006 /// could not be found.1007 /// </exception>1008 /// <exception cref="NotSupportedException">1009 /// If the provider that the <paramref name="path"/> refers to does1010 /// not support this operation.1011 /// </exception>1012 /// <exception cref="ProviderInvocationException">1013 /// If the provider threw an exception.1014 /// </exception>1015 public Collection<PSObject> New(1016 string path,1017 string name,1018 string itemTypeName,1019 object content)1020 {1021 Dbg.Diagnostics.Assert(1022 _sessionState != null,1023 "The only constructor for this class should always set the sessionState field");1024 1025 // Parameter validation is done in the session state object1026 1027 return _sessionState.NewItem(new string[] { path }, name, itemTypeName, content, false);1028 }1029 1030 /// <summary>1031 /// Creates a new item at the given path.1032 /// </summary>1033 /// <param name="path">1034 /// The path(s) to the container to create item in. They may be drive or provider-qualified path and may include1035 /// glob characters.1036 /// </param>1037 /// <param name="name">1038 /// The name of the new item to create.1039 /// </param>1040 /// <param name="itemTypeName">1041 /// The type of the new item to create.1042 /// </param>1043 /// <param name="content">1044 /// The content of the new item to create.1045 /// </param>1046 /// <param name="force">1047 /// Passed on to providers to force operations.1048 /// </param>1049 /// <returns>1050 /// The item(s) that was created.1051 /// </returns>1052 /// <exception cref="ArgumentNullException">1053 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.1054 /// </exception>1055 /// <exception cref="ProviderNotFoundException">1056 /// If the <paramref name="path"/> refers to a provider that could not be found.1057 /// </exception>1058 /// <exception cref="DriveNotFoundException">1059 /// If the <paramref name="path"/> refers to a drive that could not be found.1060 /// </exception>1061 /// <exception cref="ItemNotFoundException">1062 /// If <paramref name="path"/> does not contain glob characters and1063 /// could not be found.1064 /// </exception>1065 /// <exception cref="NotSupportedException">1066 /// If the provider that the <paramref name="path"/> refers to does1067 /// not support this operation.1068 /// </exception>1069 /// <exception cref="ProviderInvocationException">1070 /// If the provider threw an exception.1071 /// </exception>1072 public Collection<PSObject> New(1073 string[] path,1074 string name,1075 string itemTypeName,1076 object content,1077 bool force)1078 {1079 Dbg.Diagnostics.Assert(1080 _sessionState != null,1081 "The only constructor for this class should always set the sessionState field");1082 1083 // Parameter validation is done in the session state object1084 1085 return _sessionState.NewItem(path, name, itemTypeName, content, force);1086 }1087 1088 /// <summary>1089 /// Creates a new item at the given path.1090 /// </summary>1091 /// <param name="path">1092 /// The path to the container to create item in. It may be a drive or provider-qualified path and may include1093 /// glob characters.1094 /// </param>1095 /// <param name="name">1096 /// The name of the new item to create.1097 /// </param>1098 /// <param name="type">1099 /// The type of the new item to create.1100 /// </param>1101 /// <param name="content">1102 /// The content of the new item to create.1103 /// </param>1104 /// <param name="context">1105 /// The context under which the command is running.1106 /// </param>1107 /// <returns>1108 /// Nothing. The new item is written to the context.1109 /// </returns>1110 /// <exception cref="ArgumentNullException">1111 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.1112 /// </exception>1113 /// <exception cref="ProviderNotFoundException">1114 /// If the <paramref name="path"/> refers to a provider that could not be found.1115 /// </exception>1116 /// <exception cref="DriveNotFoundException">1117 /// If the <paramref name="path"/> refers to a drive that could not be found.1118 /// </exception>1119 /// <exception cref="ItemNotFoundException">1120 /// If <paramref name="path"/> does not contain glob characters and1121 /// could not be found.1122 /// </exception>1123 /// <exception cref="NotSupportedException">1124 /// If the provider that the <paramref name="path"/> refers to does1125 /// not support this operation.1126 /// </exception>1127 /// <exception cref="ProviderInvocationException">1128 /// If the provider threw an exception.1129 /// </exception>1130 internal void New(1131 string path,1132 string name,1133 string type,1134 object content,1135 CmdletProviderContext context)1136 {1137 Dbg.Diagnostics.Assert(1138 _sessionState != null,1139 "The only constructor for this class should always set the sessionState field");1140 1141 // Parameter validation is done in the session state object1142 1143 _sessionState.NewItem(new string[] { path }, name, type, content, context);1144 }1145 1146 /// <summary>1147 /// Gets the dynamic parameters for the new-item cmdlet.1148 /// </summary>1149 /// <param name="path">1150 /// The path to the item if it was specified on the command line.1151 /// </param>1152 /// <param name="type">1153 /// The type of the new item to create.1154 /// </param>1155 /// <param name="content">1156 /// The content of the new item to create.1157 /// </param>1158 /// <param name="context">1159 /// The context which the core command is running.1160 /// </param>1161 /// <returns>1162 /// An object that has properties and fields decorated with1163 /// parsing attributes similar to a cmdlet class.1164 /// </returns>1165 /// <exception cref="ProviderNotFoundException">1166 /// If the <paramref name="path"/> refers to a provider that could not be found.1167 /// </exception>1168 /// <exception cref="DriveNotFoundException">1169 /// If the <paramref name="path"/> refers to a drive that could not be found.1170 /// </exception>1171 /// <exception cref="ItemNotFoundException">1172 /// If <paramref name="path"/> does not contain glob characters and1173 /// could not be found.1174 /// </exception>1175 /// <exception cref="NotSupportedException">1176 /// If the provider that the <paramref name="path"/> refers to does1177 /// not support this operation.1178 /// </exception>1179 /// <exception cref="ProviderInvocationException">1180 /// If the provider threw an exception.1181 /// </exception>1182 internal object NewItemDynamicParameters(1183 string path,1184 string type,1185 object content,1186 CmdletProviderContext context)1187 {1188 Dbg.Diagnostics.Assert(1189 _sessionState != null,1190 "The only constructor for this class should always set the sessionState field");1191 1192 // Parameter validation is done in the session state object1193 1194 return _sessionState.NewItemDynamicParameters(path, type, content, context);1195 }1196 1197 #endregion NewItem1198 1199 #region RemoveItem1200 