?
Solved

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

Posted on 2014-11-07
6
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 70

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 70

Expert Comment

by:Qlemo
ID: 40448638
You can't run it on W2003. It only works in PS3 on W8/W2012 and later.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

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

Are your AD admin tools letting you down?

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

752 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