zoukankan      html  css  js  c++  java
  • 使用PowerShell 自动创建DFS命名空间服务器

     运行环境:Windows Server 2012 R2

    DFS命名空间概述

    DFS命名空间 PowerShell脚本命令

    Writing PowerShell DFS Scripts: Managing DFS Links——包含了常用dfs操作语句

    需要注意的是DFS依赖域,若此服务器未存在于域控上,或未存在域内,则此脚本会报错

    创建DFS命名空间服务器,DFS命名空间会创建在当前服务器上

    在脚本中自动获取本机服务器名称

    $server = (Get-WmiObject -Class Win32_ComputerSystem | Select-Object Name).Name

    脚本如下

    # 创建DFS命名空间服务器,DFS命名空间会创建在当前服务器上
    # author:lttr <www.cnblogs.com/GoCircle>
    # date:2019-08-09
    # eg. # C:dfsn.ps1 -Domain 'test.to' -ShareFolderPhysicalPath 'C:dfsn' -ShareFolderNetworkPath 'DFSN01' [CmdletBinding()] param ( # 域名 [Parameter(Mandatory=$true,Position=0)][string]$Domain, # 共享文件夹物理路径 [Parameter(Mandatory=$true,Position=1)][string]$ShareFolderPhysicalPath, # 共享文件夹网络路径 [Parameter(Mandatory=$true,Position=2)][string]$ShareFolderNetworkPath ) # 设置共享文件夹 function SET-Share($ShareFolderPhysicalPath,$ShareFolderNetworkPath){ #文件夹不存在就创建 if(!(Test-Path $ShareFolderPhysicalPath)){ $null = New-Item -Path $ShareFolderPhysicalPath -type directory } #调用WMI对象 WIN32_Share类 $ShareHandle=[WMIClass]"WIN32_Share" #添加为共享 $null = $ShareHandle.Create($ShareFolderPhysicalPath,$ShareFolderNetworkPath,0) } SET-Share $ShareFolderPhysicalPath $ShareFolderNetworkPath pause try { #检测命名空间是否存在 if((Get-DfsnRoot -Path "\$Domain$ShareFolderNetworkPath" -ErrorAction SilentlyContinue).State -eq 'Online') { Write-Host "DFS命名空间[\$Domain$ShareFolderNetworkPath]已存在!" -ForegroundColor Red }else{ $DFSServerName = (Get-WmiObject -Class Win32_ComputerSystem | Select-Object Name).Name $null = New-DfsnRoot -Path "\$Domain$ShareFolderNetworkPath" -TargetPath "\$DFSServerName$ShareFolderNetworkPath" -Type DomainV2 if((Get-DfsnRoot -Path "\$Domain$ShareFolderNetworkPath" -ErrorAction SilentlyContinue).State -eq 'Online') { Write-Host "创建DFS命名空间[\$Domain$ShareFolderNetworkPath]成功!" -ForegroundColor Green } else { Write-Host "创建DFS命名空间[\$Domain$ShareFolderNetworkPath]失败!" -ForegroundColor Red } } } catch { Write-Host "DFS命名空间[\$Domain$ShareFolderNetworkPath]失败" -ForegroundColor Red }

  • 相关阅读:
    ORACLE的专用模式和共享模式(转)
    用TSQL修改数据库的恢复模型
    Python中的数组
    hotmail是如何被劫持的?
    [收藏] vss自动备份
    在Oracle中模拟ms Sql 中的自动增加字段
    Oracle重建所有表和索引
    CentOS6.0安装PostgreSQL9.1
    linux查找文件命令find
    Linux修改网络配置
  • 原文地址:https://www.cnblogs.com/GoCircle/p/11250415.html
Copyright © 2011-2022 走看看