Solved

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

Posted on 2014-11-07
6
147 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

18 Experts available now in Live!

Get 1:1 Help Now