New-SmbShare doesn't respect -WhatIf switch?

Welcome Forums General PowerShell Q&A New-SmbShare doesn't respect -WhatIf switch?

This topic contains 6 replies, has 5 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #32651

    Participant
    Points: 0
    Rank: Member

    It looks like the New-SmbShare cmdlet isn't respecting the -WhatIf switch.

    To reproduce, run
    New-SmbShare -Name TempFolder -Path "C:\Temp" -WhatIf

    I would not expect the "TempFolder" share to actually be created due to the addition of the WhatIf switch. However, on my server, the share is indeed created as can be seen by running:
    Get-SmbShare -Name TempFolder

    Is this intended behaviour and, if not, where is the best place to report a bug?

    P.S. I am running Windows Server 2012 R2 and PowerShell version 4.0.

  • #32652

    Keymaster
    Points: 1,524
    Helping HandTeam Member
    Rank: Community Hero

    It's a CIM command – you can likely open the code (I think it's a function) and see what's up. And bug it on Connect.

  • #32654

    Participant
    Points: 0
    Rank: Member

    is that the new command for creating a symbolic link? does it work well I have no choice but to use

    cmd.exe /c mklink /d "c:\ShadowCopy" ($shadows[$val].DeviceObject + "\users\$($val2)")

  • #32658

    Participant
    Points: 0
    Rank: Member

    No Mark, it's the new command for creating network shares.

    https://technet.microsoft.com/en-us/%5Clibrary/jj635722(v=wps.630).aspx

  • #32676

    Moderator
    Points: 0
    Team Member
    Rank: Member

    Colin,

    You can report this as a bug. New-SmbShare relies on a wrapper function generated by the PowerShell engine to access the CreateShare function of the ROOT/Microsoft/Windows/SMB/MSFT_SMBShare CIM/WMIclass. The wrapper function does not implement the WhatIf switch exposed by the CmdletBinding parameter SupportsShouldProcess.

    You can look at the wrapper function with the following code snippet.

    Import-Module SmbShare; Get-Content -Path Function:\New-SmbShare
    

    The CDXML definition for the New-SmbShare CIM cmdlet can be found in the file: C:\Windows\System32\WindowsPowerShell\v1.0\Modules\SmbShare\SmbShare.cdxml

  • #32724

    Participant
    Points: 0
    Rank: Member

    Ha i'm an idiot.. I should of looked it up in stead of assuming 😛 Thanks Curtis!!

  • #32895

    Participant
    Points: 0
    Rank: Member

The topic ‘New-SmbShare doesn't respect -WhatIf switch?’ is closed to new replies.