PowerShell: Rainer Leemet, New-share.ps1: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Rleemet (talk | contribs)
Created page with '<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 skri…'
 
Rleemet (talk | contribs)
No edit summary
 
Line 3: Line 3:
<#
<#
.SYNOPSIS
.SYNOPSIS
     Skript mis teeb kettale kus on kõige rohkem vaba ruumi kausta ja jagab selle välja vaikimisi õigustes
     Väike inetu skript mis teeb võrgus asuvale arvutile kausta kettale kus on kõige rohkem vaba ruumi ja jagab selle välja vaikimisi õigustes
   
   
.DESCRIPTION
.DESCRIPTION

Latest revision as of 09:28, 27 January 2012

<source lang="powershell">

<# .SYNOPSIS

   Väike inetu skript mis teeb võrgus asuvale arvutile kausta kettale kus on kõige rohkem vaba ruumi 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
  1. >

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 
     

}