Create remoting share folder

来源:互联网 发布:ps头像源码 编辑:程序博客网 时间:2024/05/17 01:45


$password= $ptfproppassWord
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force

$domain=$ptfpropdomainName
$userName=$ptfpropuserName

# create the credential for access to the sharepoint site
$credential = new-object Management.Automation.PSCredential(($domain+"/"+$userName),$securePassword)

$computerName = $ptfpropcomputerName

#make sure the path is end with the '/'
$sharedFolderPath = $ptfpropsharedFolderPath
if($sharedFolderPath.LastIndexOf('/') -ne $sharedFolderPath.length-1)
{
  $sharedFolderPath = $sharedFolderPath + "/"
}

$sharedFolderName = $ptfpropsharedFolderName

$ret = invoke-command -computer $computerName -Credential $credential -scriptblock{
  param(
      [string]$sharedFolderPath,
      [string]$sharedFolderName
      )

$sharedFolderFullName = $sharedFolderPath + $sharedFolderName

$isHaveSameFolder = Test-Path $sharedFolderFullName

if($isHaveSameFolder -eq $false)
{
  # Creat the shared directory 
  New-Item -path $sharedFolderPath -ItemType directory -Name $sharedFolderName
}


(Get-WmiObject -List -ComputerName . | Where-Object -FilterScript {$_.Name -eq "Win32_Share"}).InvokeMethod("Create",($sharedFolderFullName,$sharedFolderName,0,25,"Shared folder for the error reporting"))


} -argumentlist $sharedFolderPath, $sharedFolderName

if($? -eq $false)
{

throw $error[0]

}