Solved

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

Posted on 2014-11-07
6
149 Views
Last Modified: 2014-12-09
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"):
0
Comment
Question by:robertarenson
  • 3
  • 3
6 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 40430166
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.
0
 

Accepted Solution

by:
robertarenson earned 0 total points
ID: 40448607
Getting a really strange error when I try to run the PowerShell Script on my Windows 2003 Server.

The term 'Remove-SMBShare' is not recognized as the name of a cmdlet, function, script file, or operable program. Check  the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\temp\DisabledShares\DisableMaverickUsersShares.ps1:1 char:16
+ Remove-SMBShare <<<<  -Name ((Get-Content DisableMaverickUsersShare.txt) -replace '$', '$') -CimSession maverick -force -whatif
    + CategoryInfo          : ObjectNotFound: (Remove-SMBShare:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40448638
You can't run it on W2003. It only works in PS3 on W8/W2012 and later.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:robertarenson
ID: 40448776
Darn, the share server is only 2003 R2 server.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40449320
Bad luck! You tried on your workstation before, obviously.
0
 

Author Closing Comment

by:robertarenson
ID: 40488449
Unable to get to work
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
A procedure for exporting installed hotfix details of remote computers using powershell
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now