windows-server-2012-r2 – 在启用了配额的故障转移群集中添加共
我有文件服务集群,其中一个文件服务器资源托管?50,000个用户主目录.主目录具有通过 FSRM分配的配额模板. 尝试使用故障转移群集管理器的“添加文件共享”向导添加新共享时,它首先在所有已定义的文件服务器群集资源上检索所有共享文件夹上的所有配额.在这种环境下需要大约10分钟. 我怎么可能 >加快配额枚举的过程 ? 我终于解决了这个问题,提出了完全使用GUI进行文件共享创建的要求.相反,我记录了使用New-SmbShare作为共享创建过程.以这种方式添加共享会绕过GUI向导正在执行的所有预配置检查,包括配额枚举.New-SmbShare -Name <ShareName> -ScopeName "<CAPName>" -Path "<LocalDirectoryToBeShared>" -FullAccess "Everyone" -Description "<Comment>"
我的缩短版本看起来像这样: #Using Win32 API NetShareAdd via p/invoke to be able to specify the scope in SHARE_INFO_503 $signature = @" using System; using System.Runtime.InteropServices; using System.Collections; public class NativeMethods { [DllImport("Netapi32.dll")] public static extern uint NetShareAdd([MarshalAs(UnmanagedType.LPWStr)] string strServer,Int32 dwLevel,ref SHARE_INFO_503 buf,out uint parm_err); [StructLayoutAttribute(LayoutKind.Sequential)] struct SECURITY_DESCRIPTOR { public byte revision; public byte size; public short control; public IntPtr owner; public IntPtr group; public IntPtr sacl; public IntPtr dacl; } public enum SHARE_TYPE : uint { STYPE_DISKTREE = 0,STYPE_PRINTQ = 1,STYPE_DEVICE = 2,STYPE_IPC = 3,STYPE_SPECIAL = 0x80000000 }; [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Unicode)] public struct SHARE_INFO_503 { public string shi503_netname; [MarshalAs(UnmanagedType.U4)] public SHARE_TYPE shi503_type; public string shi503_remark; [MarshalAs(UnmanagedType.U4)] public int shi503_permissions; [MarshalAs(UnmanagedType.U4)] public int shi503_max_uses; [MarshalAs(UnmanagedType.U4)] public int shi503_current_uses; public string shi503_path; public string shi503_passwd; public string shi503_servername; [MarshalAs(UnmanagedType.U4)] public int shi503_reserved; public IntPtr shi503_security_descriptor; } public static uint ShareFolder(string servername,string sharename,string path,string remark) { SHARE_INFO_503 shInfo = new SHARE_INFO_503(); shInfo.shi503_netname = sharename; shInfo.shi503_type = SHARE_TYPE.STYPE_DISKTREE; shInfo.shi503_remark = remark; shInfo.shi503_permissions = 0; shInfo.shi503_max_uses = -1; shInfo.shi503_current_uses = 0; shInfo.shi503_path = path; shInfo.shi503_passwd = null; shInfo.shi503_servername = servername; shInfo.shi503_reserved = 0; shInfo.shi503_security_descriptor = IntPtr.Zero; uint nRetValue = 0; uint param_err = 0; nRetValue = NetShareAdd(servername,503,ref shInfo,out param_err); //Console.WriteLine("Sharing " + path + " on " + servername + " as " + sharename + " returned " + nRetValue + " (" + param_err+ ")"); return nRetValue; } } "@ #Import the FailoverClusters PowerShell module if it is not already imported Import-Module FailoverClusters #Add the function type that will be used to share the folder in the defined scope Add-Type -TypeDefinition $signature 用法很简单: [NativeMethods]::ShareFolder("<CAPname>","<ShareName>","<LocalDirectoryToBeShared>","<Comment>") ShareFolder函数在成功执行后返回0并立即结束,即使启用了配额.在托管CAP /文件服务器资源的其中一个集群节点上运行.您可能必须在之后修复共享ACL,因为默认共享创建ACL只是Everyone:Read并且无法使用此方法指定. (编辑:ASP站长网) |