Solved

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

Posted on 2014-11-07
6
152 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 69

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 69

Expert Comment

by:Qlemo
ID: 40448638
You can't run it on W2003. It only works in PS3 on W8/W2012 and later.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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 …
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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