我想创建一个GUI powershell脚本,它应该执行以下操作,

时间:2018-03-17 15:00:12

标签: powershell

我想创建一个GUI powershell脚本,该脚本应执行以下操作,如果我给出一个名称,它应该在特定列表中搜索(可能在AD或数据库列表中),如果它在那里找到了确切的名称,那么应该复制名称,并使用相同的名称来提供我在上述路径中可用的文件夹的权限。

mY CODE

function selectShare{
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

####################################################################
    $Form = New-Object System.Windows.Forms.Form          #
                                                          #
    $Form.width = 300                                     #      Main Window Section
    $Form.height = 200                                    #
    $Form.Text = ”File Sharing”                           #
#######################################################################################
    #below section function of "Select an item button"

    $Button = new-object System.Windows.Forms.Button
    $Button.Location = new-object System.Drawing.Size(100,100)
    $Button.Size = new-object System.Drawing.Size(105,25)
    $Button.Text = "New Folder"
    $Button.Add_Click({New-Item “h:\shan" –type directory 
    NET SHARE shan = h:\shan /GRANT:everyone`,FULL})
 ###################
 ###################   button section

    $Button1 = new-object System.Windows.Forms.Button
    $Button1.Location = new-object System.Drawing.Size(100,50)
    $Button1.Size = new-object System.Drawing.Size(105,25)
    $Button1.Text = "Existing Folder"
    $Button1.Add_Click(
    {
    function Find-Folders 
    {
    [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
    [System.Windows.Forms.Application]::EnableVisualStyles()
    $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
    $browse = New-Object System.Windows.Forms.FolderBrowserDialog 
    $browse.SelectedPath = "C:\"
    $browse.ShowNewFolderButton = $true
    $browse.Description = "Select a Folder"

    $loop = $true
    while($loop)
    {
        if ($browse.ShowDialog() -eq "OK")
        {
             $loop = $false
        $FolderBrowser.SelectedPath

        #Insert your script here

        } else
        {
            $res = [System.Windows.Forms.MessageBox]::Show("You clicked Cancel. Would you like to try again or exit?", "Select a location", [System.Windows.Forms.MessageBoxButtons]::RetryCancel)
            if($res -eq "Cancel")
            {
                #Ends script
                return
            }
        }
    }
    $browse.SelectedPath
    $browse.Dispose()
} Find-Folders})

    $form.Controls.Add($Button)
    $form.Controls.Add($Button1)

    $Form.Add_Shown({$Form.Activate()})
    [void] $Form.ShowDialog()


    return $script:choice
}

$share = selectShare
write-host $share

0 个答案:

没有答案