2015-01-26 44 views
1

我試圖執行下面的腳本:使用與powershell交易?

Start-Transaction 
Remove-Item D:\sandbox\temp.txt -UseTransaction 
Undo-Transaction 

我不斷收到以下錯誤:

The provider does not support transactions. Perform the operation again without the -UseTransaction parameter. 
At line:3 char:1 
+ Remove-Item D:\sandbox\temp.txt -UseTransaction 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotImplemented: (:) [], PSNotSupportedException 
    + FullyQualifiedErrorId : NotSupported 

任何人都知道爲什麼嗎?我在Powershell 4中使用Windows 7 Professional x64。D:\是本地驅動器。

回答

5

從一開始幫助啓動交易:

The cmdlets used in a transaction must be designed to support transactions. Cmdlets that support transactions have a UseTransaction parameter. To perform transactions in a provider, the provider must support transactions. The Windows PowerShell Registry provider in Windows Vista and later versions of Windows supports transactions. You can also use the Microsoft.PowerShell.Commands.Management.TransactedString class to include expressions in transactions on any version of Windows that supports Windows PowerShell. Other Windows PowerShell providers can also support transactions.

着重強調

我不相信FileSystem提供支持事務。

+0

根據https://technet.microsoft.com/en-us/library/hh849765.aspx Remove-Item支持事務。 – coding4fun 2015-01-26 19:17:40

+0

Remove-Item支持事務***當與支持事務***的提供者一起使用時。因此,例如,您應該能夠將remove-item用作註冊表提供程序的事務。 – EBGreen 2015-01-26 19:19:46

+0

感謝您的澄清。我知道Vista +向操作系統添加了基於文件的事務,我錯誤地認爲微軟自己的cmdlet會支持該功能。呃,祝你好運。他們會很有用。 – coding4fun 2015-01-26 19:23:34