• Why I Love PowerShell (Yeah, I’m a bit Weird)

    Home » Forums » Developers, developers, developers » DevOps Lounge » Why I Love PowerShell (Yeah, I’m a bit Weird)

    Author
    Topic
    #1774096

    Hey Y’all,

    Note: This is a long post so if you’re not into Powershell or Programming you may just want to skip it. I’ll understand.

    I was messing around with PowerShell tonight trying to get the settings for Windows Update and I got to fooling around with powershell trying to compress code so I didn’t have to do so much repetitive typing.

    I started out with this to retrieve 3 registry key values.

    Code:
    Clear-Host
    
    
    $RegPath = "Registry::HKLMSOFTWAREPolicies" +
                      "MicrosoftWindowsWindowsUpdate"
    $RegKey  = "ExcludeWUDriversinQualityUpdate"
    
    
    $GIPArgs = 
      @{Path = "$RegPath"
        Name = "$RegKey"
        EA   = "Stop"}
    
    
    Try {
    
    
       $SVArgs = @{Name  = $($($GIPArgs).Name) 
                   Value = $(Get-ItemProperty @GIPArgs).$($($GIPArgs).Name)}
       Set-Variable @SVArgs
    
    
       "$($($GIPArgs).Name) set to: $ExcludeDrivers"
    }
    Catch { "$($($GIPArgs).Name) Not Found!" }
    
    
    $RegPath = "Registry::HKLMSOFTWAREPoliciesMicrosoft" +
                      "WindowsWindowsUpdateAU"
    $RegKey  = "NoAutoRebootWithLoggedOnUsers"
    
    
    $GIPArgs = 
      @{Path = "$RegPath"
        Name = "$RegKey"
        EA   = "Stop"}
    
    
    Try {
    
    
       $SVArgs = @{Name  = $($($GIPArgs).Name) 
                   Value = $(Get-ItemProperty @GIPArgs).$($($GIPArgs).Name)}
       Set-Variable @SVArgs
    
    
       "$($($GIPArgs).Name) set to: $NoReboot"
    }
    Catch { "$($($GIPArgs).Name) Not Found!" }
    
    
    $GIPArgs.Name = "AUOptions"
    
    
    Try {
    
    
       $SVArgs = @{Name  = $($($GIPArgs).Name) 
                   Value = $(Get-ItemProperty @GIPArgs).$($($GIPArgs).Name)}
       Set-Variable @SVArgs
    
    
       "$($($GIPArgs).Name) set to: $AUOptions"
    }
    Catch { "$($($GIPArgs).Name) Not Found!" }
    

    Note some of the code is there due to my desire to maintain code lines
    [/code]

    Ain’t PowerShell a BLAST?

    Consider this my Holiday Gift to all my Geeky Friends @ the Lounge!

    HTH :cheers:

    Reply To: Why I Love PowerShell (Yeah, I’m a bit Weird)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: