2016-12-09 8 views
0
function global:Get-Shares(){ 
    <# 
    .SYNOPSIS 
    Get Shares 
    .DESCRIPTION 
    This function fetches all shares on the computer when you run get-shares localhost. If you 
    just run get-shares then it will show all the non-$ shares. 
    .LINK 
    You can use "et" to end the transcript. 
    .PARAMETER prefix 
    The prefix for the transcript file name. Default: PowerShell_get-shares 
    .EXAMPLE 
    } 
    #> 
    param (
     [string]$Computername, [string]$Allshares 
    ) 
    [AllowNull()] 
    $computername = 'localhost' 
    $Allshares = gwmi -Computer $computername -Class Win32_Share | Where-Object { $_.Name -notlike "*$" } 
    if ($ComputerName -eq 'localhost') { 
    gwmi -Computer $ComputerName -Class Win32_Share 

    } 
    else { 
    gwmi -Computer $computername -Class Win32_Share | Where-Object { $_.Name -notlike "*$" } 
} 
} 
なぜ私のelseステートメントは機能しませんか?私は私が得る-株式を実行したり、株式を取得

答えて

0

をlocalhostのところ######文はあなたは間違いなくここにAbout_Function_Advanced

-ヘルプ見るには見る必要がある場合、デフォルトを挙げることができるため、結果のみを取得しますParam()ブロックの$ ComputerNameの値はブロックします。 及び許可ヌル属性がない外部

Param(
[AllowNull()] 
$ComputerName = 'localhost' 
) 

$ComputerName IDのローカルホスト、必要はgwmi -computername $ComputerNameを使用しないようにすれば、ちょうどgwmi -Class Win32_Share十分であり、n = Paramのブロックに述べられなければなりません。

ここでの主な問題は、$ComputerNameの値が記載されていても、それが$ComputerNme = 'localhost'に置き換えられ、渡される場合のみです。

よろしく、

kvprasoon