windows-server-2012-r2 – 在启用了配额的故障转移群集中添加共享需要10分钟

前端之家收集整理的这篇文章主要介绍了windows-server-2012-r2 – 在启用了配额的故障转移群集中添加共享需要10分钟前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有文件服务集群,其中一个文件服务器资源托管〜50,000个用户主目录.主目录具有通过 FSRM分配的配额模板.

尝试使用故障转移群集管理器的“添加文件共享”向导添加新共享时,它首先在所有已定义的文件服务器群集资源上检索所有共享文件夹上的所有配额.在这种环境下需要大约10分钟.

我怎么可能

>加快配额枚举的过程
>将配额枚举过程限制为仅一个文件服务器群集资源
>为“新建共享向导”完全禁用配额枚举

我终于解决了这个问题,提出了完全使用GUI进行文件共享创建的要求.相反,我记录了使用New-SmbShare作为共享创建过程.以这种方式添加共享会绕过GUI向导正在执行的所有预配置检查,包括配额枚举.
New-SmbShare -Name <ShareName> -ScopeName "<CAPName>" -Path "<LocalDirectoryToBeShared>" -FullAccess "Everyone" -Description "<Comment>"

New-SmbShare cmdlet已与Server 2012 R2 / Windows 8.1一起推出.对于以前的(2012,2008R2,2008)版本的文件服务器群集,您可以借用NativeMethods类,该类从a scriptMSDN blog post about shares in Fileover Cluster scopes一起从Netapi32.dll导入NetShareAdd函数.

我的缩短版本看起来像这样:

#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并且无法使用此方法指定.

原文链接:https://www.f2er.com/windows/369284.html

猜你在找的Windows相关文章