none
Help a new power shell guy RRS feed

  • Question

  • Hi 

    I have been fighting this all morning. I am trying to check if SMBv1 is enabled and if it returns a NULL value then I run the disable script below it. I cant get past the IF to run the ELSE

    cls
    Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters | ForEach-Object {Get-ItemProperty $_.pspath} IF ($_.pspath::IsNullOrEmpty($variable)){
    Write-Host "Hello"
    } Else {
    Write-Host "It worked"
    }


    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1 -Type DWORD -Value 0 –Force

    Thank you I love this group
    • Edited by JRitten3 Friday, September 29, 2017 3:55 PM Typo
    • Moved by Bill_Stewart Wednesday, November 29, 2017 6:35 PM Abandoned
    Friday, September 29, 2017 3:54 PM

All replies

  • "Help a new power shell guy" is not a question.  It is of no help to anyone looking for assistance..

     Get-SmbServerConfiguration | select EnableSMB1Protocol

    Start by learning how to write and format PS code.  What you have posted in unreadable and badly formatted and syntactically incorrect. I suspect you copied it from a web page and the copy is broken.


    \_(ツ)_/

    Friday, September 29, 2017 6:05 PM
  • Sorry I'm such a terrible user. I guess I have to be an expert before I can ask a question. Sorry I'm trying to learn!!
    Friday, October 6, 2017 5:27 PM
  • "Help a new PowerShell guy" is not a question."  It sounds more like begging.  How would people searching find the issue when you didn't ask about it or mention the subject.

    If you use the code posting tool and format the code you will produce a better post.

    Also the code posted is broken because it was either copied and pasted from a we b page or you need to learn basic PowerShell.

    Feel free to ask questions even dumb one but try to make you posts readable and do try to learn the very simple stuff.

    Also find scripts here: http://gallery.technet.microsoft.com/

    Learn PowerShell: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276


    \_(ツ)_/

    Friday, October 6, 2017 10:19 PM
  • Im sorry that was just a part of my script that I could not get to work. My formatting skills are not the greatest as Im a systems engineer not developer. I was just trying to get help on the if else part.
    Friday, October 13, 2017 7:28 PM
  • Thank you for the Learn Power Shell link as I am self taught which is very obvious.
    Friday, October 13, 2017 7:30 PM
  • help about_if

    Use the CmdLet as it is easier and safer.

    Get-ChildItem is not the correct command to read a property use "Get-ItemProperty".

    help Get-ItemProperty.

    Your code is syntactically wrong.  The learning video will help you to understand the syntax.

    All schools that I have ever heard of always give basic programming for a degree in Computer Systems Engineering.  Programming is fundamental to systems engineering.  Help Desk and Desktop Support are usually not schooled in basic programming.

    There are many sites that can teach you the basics in a couple of hours.


    \_(ツ)_/

    Friday, October 13, 2017 7:41 PM
  • This can be set with Group Policy which would be the preferred method.

    The easiest way to test this is here:

    $params = Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
    if ($params.SMB1) {
    	Write-Host 'SMBv1 is enabled'
    }else{
    	Write-Host 'SMBv1 is not enabled'
    }


    \_(ツ)_/

    Friday, October 13, 2017 7:52 PM