支持所有版本。
利用WMI可以很方便创建文件共享,下面代码将演示如何共享:
$ShareName = 'NewShare'
$Path = 'c:\123'
If (!(Get-WmiObject -Class Win32_Share -Filter "name='$ShareName'"))
{
$Shares=[WMICLASS]"WIN32_Share"
$Shares.Create($Path,$ShareName,0).ReturnValue
}
else
{
Write-Warning "Share $ShareName exists already."
}
You can also create shares on remote machines, provided you have Admin privileges on the remote machine. To do that, simply add the complete WMI path like this:
$ShareName = 'NewShare'
$Path = 'c:\123'
$Server = 'MyServer'
If (!(Get-WmiObject -Class Win32_Share -Filter "name='$ShareName'" -ComputerName $Server))
{
$Shares=[WMICLASS]"\\$Server\root\cimv2:WIN32_Share"
$Shares.Create($Path,$ShareName,0).ReturnValue
}
else
{
Write-Warning "Share $ShareName exists already."
}
原文地址:Creating New Shares
本文链接: https://www.pstips.net/creating-new-shares.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
