Solved

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

Posted on 2014-11-07
6
164 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
Technology Partners: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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