2016-12-16 53 views
1

我已經構建了一個腳本,用於從AD,Exchange,Lync等用戶中刪除該腳本。在腳本結尾刪除用戶配置文件文件夾和主目錄。問題是,只有被刪除的用戶擁有完全控制配置文件文件夾,所以我需要用他/她的憑證刪除文件夾。無法使用PowerShell刪除網絡驅動器上的目錄

首先,我想這:

Remove-Item -Path \\networkdrive\share$\profilefolder -Recurse -Force -Credential $UsersCredentials 

,但我得到了以下錯誤:

Remove-Item : Cannot retrieve the dynamic parameters for the cmdlet. The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.

然後我試圖與New-PSDrive cmdlet來做到這一點:

New-PSDrive -Name F -PSProvider FileSystem -Root \\networkdrive\share$\profilefolder -Credential $UsersCredentials 

我得到出現以下錯誤:

New-PSDrive : Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again

我讀的地方,連接到IP地址的網絡驅動器可能會解決上述錯誤,但是當我嘗試,我得到了一個新的錯誤:

New-PSDrive : The specified network password is not correct

你有什麼意見或建議,以我能做什麼?我的目標是使用被刪除者的憑據來刪除文件夾。我的下一步是下載NetApp PowerShell cmdlet並查看是否可以使用這些目錄刪除目錄。

編輯:我決定不嘗試刪除其他憑據的文件夾,而是採取所有權,然後刪除文件夾。我想:

takeown /F \\server\share\folder /A /R /D y 

但我得到了以下錯誤:

SUCCESS: The file (or folder): "\\server\share\folder" now owned by the administrators group. 

takeown: 在行:1字符:1 + takeown/F \服務器\共享\文件夾/ A/R/D y + ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ + CategoryInfo:NotSpecified:(:字符串)[],的RemoteException + FullyQualifiedErrorId:NativeCommandError

錯誤:傳遞給系統調用的數據區域太小。

因此,我似乎無法取得所有權,出於某種原因。任何建議如何從這裏出發?

+0

被刪除的人是否已將驅動器映射到該位置? –

+0

如果您擁有該用戶的憑據,爲什麼不直接運行腳本呢?我希望系統管理員或某人有權訪問以便能夠刪除這些類型的文件夾 – Matt

+2

如果配置文件文件夾和主目錄存儲在ADUser對象中,請將其從對象中保存,然後在需要刪除時,只需'Remove-Item -Path $ profilefolder'和'Remove-Item -Path $ homefolder'。在刪除文件夾之前,您也可以考慮將這些文件夾的所有權作爲管理員。 您描述的業務案例幾乎與https://learn-powershell.net/2014/06/24/changing-ownership-of-file-or-folder-using-powershell/ –

回答

0
Remove-Item -Path \networkdrive\share`$\profilefolder -Recurse -Force-Credential $UsersCredentials 

用倒退(`)將路徑中的$退出。

+1

供參考:如果有以下字母數字,您只需要跳過$。斜線在案件中停止。儘管沒有危害逃脫。 – Matt

+0

'無法檢索cmdlet的動態參數。「我認爲這恰好表明了這種情況? – 4c74356b41

+0

這似乎沒有幫助。我犯了同樣的錯誤。 – TimoY

相關問題