Powershell - Create Large Number of Shares and Permissions - powershell

I tried about a dozen PowerShell scripts that I found and not one even created a single share.
We are migrating from Win 2008 and SQL Server 2008 R2 to Windows 2012 and SQL Server 2014.
I have to create a ton of shares and assign a lot of varying permissions.
I'm looking for (ideally) a Powershell script (but can live with VB or anything else) that can go through a list of shares and permissions and create/assign them.
For example
E:\Folder1\A Share1 Domain\Tom Read
E:\Folder1\A Share1 Domain\Dick Full
E:\Folder1\A Share1 Domain\Harry Change
So it would go through every line, see if the share exists, if not create it, then assign the permissions.

On Server 2012R2 you can use the New-SmbShare cmdlet : https://technet.microsoft.com/en-us/library/jj635722(v=wps.630).aspx
On older versions you have to fall back to WMI to do it :https://msdn.microsoft.com/en-us/library/aa389393(v=vs.85).aspx (the article even has a PS example).
With Set-Acl you can set the ACLs for the shares.
As you can see all the tools to acomplish this are available in a default installation of Windows Server.

Related

Unix permissions needed when running Powershell script

As a final step in our AD account creation process that is being moved to a powershell script a few folders need to be created on the filer for users and I am coming unstuck with permissions.
I am just using the basic new-item command to create folder but the locations need unix permissions (775) set before anything can be created. I can't go there and right click in Windows explorer and click new.. and the powershell script is being bounced also due to permissions.
The reasoning from one of the tech guys here is that I am trying to create a sub folder via smb mount from Windows using ntfs permissions. There is no correlation to unix permissions and any of our Linux users won't be able to access / use the location created for them.
Sorry if that is a clumsy way of explaining it, I am not a systems engineer, just the guy trying to translate a whole heap if pearl scripts into a new powershell process.
Thank you
S.

update Unix permissions on a windows share

My Unix box has a mapping to a Windows share. On the Windows server, a Powershell script is copying folders to this share UDI/inbound throughout the day. On the Unix side where my Oracle database is running, I need to be able to update or write a file under one of these share folders. But permissions are blocking me. See visual below.
When looking at it from the Unix side, the owner/group(33448/32770) are different than my Unix login (orahubd/dba), so I cannot change the permissions from the Unix side. Is there some way from the Windows side, like in my Powershell script, to change the permissions so that Unix would allow me to write? I was able to set the permissions via Powershell to Everyone:Full, but that doesn't seem to change it from the Unix perspective.
I am an Oracle PL//SQL developer, just a novice dabbling in these other technologies.

Get client connections on cifs share from command line equal to Computer Management view

I would like to use either command line or Powershell to gather the number of client connections on different shares from our NAS'es, multiple vendors.
Connecting "Computer Management" to a NAS-device, this gives us a nice overview of the connections per share under System Tools -> Shared Folders -> Shares. Is it possible to get the same information using cmd or powershell script?
Get-SmbShare, as mentioned by PetSerAl, can list file shares on Windows machines(Windows 8/Server 2012 and later). I do not know if it can enumerate shares on other vendor products that are visible as SMB shares to a Windows machine.
Get-SmbShare | Select Name,ScopeName,PathName,CurrentUsers
For NetApp products, the DataONTAP PowerShell Toolkit has scripts for managing shares, but I'm not sure of the specific commands you would need for the desired output.
For Windows 7/Server 2008 R2, this article discusses a way to use WMI directly to query file shares.
For other products, you may want to contact their respective support teams.

move-item: access denied on server 2012 only

I am running a PS script that people's personal drives to another location when they are terminated. Script runs fine when the users drive is on a 2003 or 2008 server, but I get an error when the drive is on a 2012 server.
"move-item: Acces to the path '[\P drive path]' is denied.
Checked my group's rights to the file servers, and they are the same. Do not know 2012 well enough to know why this would be bombing out on that server only. Any ideas?
Found answer here, should have looked deeper.
Seems it cannot be done with move-item. When I said it worked under Server 2008, well, it did, but only because the user profile containers for a certain number of users is on the same file server/drive as where the terminations were being moved to. The other bunch, were on another file server, so move-item cant be used. Copy-item/Remove-item seems to work, just have to work on some error handling.

PowerShell v2 Server 2003 - Cannot Find Path - Path definitely exists

Usually I can find an answer to PowerShell questions by researching forums and adapting. However, after searching high and low, I cannot find an answer.
I am logged in as a domain administrator working on two enterprise servers in a test domain. $Server2003 is Windows 2003 server running PS v2. $Server2008 is Windows 2008 R2.
Problem: When I am working from $Server2003 I cannot use any commands to access or verify information on $Server2008. This error happens regardless of who the administrator is.
I have used PowerShell fairly extensively in our environments and haven't run into this error before. The error is not present when running commands from $Server2008 on $Server2003. In addition the error is not present when running commands from a production domain. I can also ping the 2003 or 2008 server regardless of which machine I am logged in as.
Examples:
From $Server2008: ping $Server2003 - returns pings
From $Server2003: ping $Server2008 - returns pings
From $Server2003: test-path \\$Server2008\D$\ - Get-ChildItem : Cannot find path '\\$Server2008\D$\' because it does not exist
From $Server2008: test-path \\$Server2003\D$\ - True
The commands I want to run are a lot more complex than test-path; however, if I cannot get the simple command to work I doubt I'll have much luck with a complex one.
The two servers have the same domain, are in the same forest, and have the same domain controllers.
Any ideas where to start?
EDIT: Wanted to add that I have tried using test path from Server2003 to a different 2008 server located in our dev environment (same domain) and it runs the test-path and commands successfully.
can you access the 2008 server remotely by other means? Like the Services MMC? Also, what if you create a share on 2008 rather than rely on the admin share?
The cannot find path error means that it doesn't exist or you don't have permissions. Does it work from a dos prompt?
UPDATE
I just noticed that you used single quotes, the variable will not expand. Enclose it in double wotes and try again