PowerShell: Rainer Leemet, New-share.ps1
From ICO wiki
<source lang="powershell">
<# .SYNOPSIS
Skript mis teeb kettale kus on kõige rohkem vaba ruumi kausta ja jagab selle välja vaikimisi õigustes
.DESCRIPTION
Lahe skript
.NOTES
Autor: Rainer Leemet
.EXAMPLE
PS> New-Share.ps1 -filename mycsvfile.csv -foldername Myfolder -sharename Myshare
- >
Param ( [Parameter(Mandatory = $true)] [String] $Filename, [Parameter(Mandatory = $true)] [String] $Foldername, [Parameter(Mandatory = $true)] [String] $Sharename )
Function new-share ($Foldername, $Sharename) {
IF (!(TEST-PATH $Foldername)) { NEW-ITEM $Foldername -type Directory } If (!(GET-WMIOBJECT Win32_Share -filter "name='$Sharename'")) { $Shares=[WMICLASS]"WIN32_Share" $Shares.Create($Foldername,$Sharename,0) }
}
Function get-drive {
Get-WmiObject win32_logicaldisk -Filter "DriveType='3'" | Sort-Object -Property FreeSpace -descending ` | Select-Object -First 1 -ExpandProperty DeviceID
}
if (!$filename) {
write-host "Palun sisesta failinimi, mis on kohustuslik parameeter" exit
}
Get-Content $Filename | Foreach-Object {
$drivename = invoke-command -computername $_ -scriptblock ${function:get-drive} write-host $drivename $Foldername = $drivename +"\$Foldername" invoke-command -computername $_ -scriptblock ${function:New-Share} -Argumentlist $Foldername,$Sharename
}