Link to home
Start Free TrialLog in
Avatar of robertarenson
robertarenson

asked on

How to Disable a File Share on a server via a text file

I need to disable multiple file shares from users who are no longer in our organization. I have added all of the share names to a text file but need to set the text file so that the PowerShell Script can call it so that it can then remove all of the shares from the text file from the 1 share server name.

Not sure if I need the $ included in the usernames though since the actual share is restricted to usera$

Thank you

Example of what is in the text file:

usera
userb
userc

PS C:\> Remove-SmbShare -Name Files -CimSession SRV2K12RC

Confirm

Are you sure you want to perform this action?

SRV2K12RC: Performing operation 'Remove-Share' on Target

  '*,Files'.

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?]

  Help (default is "Y"):
Avatar of Qlemo
Qlemo
Flag of Germany image

We need the $, as it is part of the SMB share name, and hence we have to add it to the text file content. The command looks strange, but works.
Remove-SMBShare -Name ((Get-Content RemoveUsers.txt) -replace '$', '$') -CimSession Srv2k12rc -force -whatif

Open in new window

Remove the last switch to apply the change. As-is the removal is only simulated.
ASKER CERTIFIED SOLUTION
Avatar of robertarenson
robertarenson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can't run it on W2003. It only works in PS3 on W8/W2012 and later.
Avatar of robertarenson
robertarenson

ASKER

Darn, the share server is only 2003 R2 server.
Bad luck! You tried on your workstation before, obviously.
Unable to get to work