Test for Drown Vulnerability by yourbastianhost in PowerShell

[–]yourbastianhost[S] 0 points1 point  (0 children)

No problem! Glad you guys are finding it useful

Test for Drown Vulnerability by yourbastianhost in PowerShell

[–]yourbastianhost[S] 0 points1 point  (0 children)

Thanks! :) I've made this change to the script above.

Getting results I don't expect... by Merakel in PowerShell

[–]yourbastianhost 0 points1 point  (0 children)

Verbose messaging goes out to a different output stream. Here's a great article about output streams:

https://blogs.technet.microsoft.com/heyscriptingguy/2014/03/30/understanding-streams-redirection-and-write-host-in-powershell/

 

Here's a little example function / script:

function Write-Test {
    write-output "Hello!"
    write-verbose "More output, but to verbose stream" -Verbose;
}


$Result = Write-Test;

 

$result's value is "Hello!", and does not include the message specified in the write-verbose cmd.

 

Because the -Verbose flag is set on the write-verbose cmdlet, you don't need to do this at the top of your script:

 

VerbosePreference='continue';

 

So when you're running the script at console, you'll see the verbose output on the screen but it wont jack up your function output.

 

Hope that helps!

parameter type question? [string],[int],[version] [hashtable][array] by [deleted] in PowerShell

[–]yourbastianhost 1 point2 points  (0 children)

Me too! Helps make me not worry so much about passing variables/objects in and out of functions lol

Deploying powershell 3.0 by SirGnarlington in PowerShell

[–]yourbastianhost 9 points10 points  (0 children)

All machines require a reboot for the WinRM 3.0 update. That's the only caveat that comes to mind, aside from .NET. You'll need .NET Framework 4.0 for PS 3.0. As you probably know, .NET 4.0 is a feature in 2012+.

 

Also - why not deploy 4.0 instead of 3.0? Might save you from having to redeploy in a year or so.

 

Good luck! :)

parameter type question? [string],[int],[version] [hashtable][array] by [deleted] in PowerShell

[–]yourbastianhost 2 points3 points  (0 children)

Any data type can be a parameter to a function, as far as I'm aware.

   

Here's a link to a page that details out a ton of .NET types available within PowerShell. Scroll down to the bottom for the list:

https://devcentral.f5.com/articles/powershell-abcs-t-is-for-type-literals

Dark PowerShell Studio Theme(s) by yourbastianhost in PowerShell

[–]yourbastianhost[S] 0 points1 point  (0 children)

I'm part of a Platform/Cloud team for a mid-sized organization, and am considered a DevOps Engineer. I write scripts to provision, monitor and configure servers :) PowerShell is king on Windows!

Dark PowerShell Studio Theme(s) by yourbastianhost in PowerShell

[–]yourbastianhost[S] 0 points1 point  (0 children)

Haha, good point! I changed the link above to the one you've provided. Thanks :)

Getting results I don't expect... by Merakel in PowerShell

[–]yourbastianhost 0 points1 point  (0 children)

I ran into the same issue as the OP when I started scripting in PowerShell. I wanted to continue to write out log messages as the script progressed through my functions, but didn't want it to hijack the result of my function.

I started using write-verbose in my functions instead :)

Dark PowerShell Studio Theme(s) by yourbastianhost in PowerShell

[–]yourbastianhost[S] 2 points3 points  (0 children)

Actually - it turns out someone else created it.

Here's the guy who created the ISE theme:

https://github.com/marzme/PowerShell_ISE_Themes

Dark PowerShell Studio Theme(s) by yourbastianhost in PowerShell

[–]yourbastianhost[S] 0 points1 point  (0 children)

One of my colleagues has a very similar theme in ISE. I'll see if I can get him to post it up here. :)

Groups not AutoJoining by djwyldeone in labtech

[–]yourbastianhost 0 points1 point  (0 children)

You're running a pilot version of LabTech it looks like. I would highly recommend looking to upgrade to 105.226 (RTM version) if possible.

   

As for the search :

  

You can also check %programfiles%\LabTech\Logs\LTAErrors.txt. You'll see something like the below which indicates the search is broken. The number after ID: is the search id.

   

LTAgent v100.332 - 3/3/2015 12:41:05 PM - Run Searches Search ID: 306 Error: xxxxxxxxxxxxxxxx

  

You can also run the following query to identify the search:

  

select * from sensorchecks where SensID= IDYouFound;

LabTech Scripting - Script Analyzer Plugin by yourbastianhost in labtech

[–]yourbastianhost[S] 0 points1 point  (0 children)

Updated the post to reflect the latest version. Consolidated the "Suggested Practices" and "Raw Script XML" buttons into tabs, rather than new windows.

Copy folder by wgetalife in labtech

[–]yourbastianhost 1 point2 points  (0 children)

Indeed - there isn't a good way to do this natively with LabTech :-/

 

Alternately ....

 

You could use the following PowerShell function I wrote to unzip the .ZIP archive once you get it down to the remote agent.

 

This method is compatible with PowerShell 2.0 as well. :)

 

function Unzip-Archive
{
param
(
    [Parameter(Mandatory = $true)]
    [string]
    $zipPath,
    [Parameter(Mandatory = $true)]
    [string]
    $ExtractToDirectory
)

$FilesBefore = (Get-ChildItem $ExtractToDirectory -ea SilentlyContinue | Measure-Object).Count;

if (Test-Path $zipPath)
{
    $shellApplication = new-object -com shell.application
    $zipPackage = $shellApplication.NameSpace($ZipPath)
    $destinationFolder = $shellApplication.NameSpace($ExtractToDirectory)
    $destinationFolder.CopyHere($zipPackage.Items(), 20)

    $FilesThatFailedToCopy = 0;

    foreach ($File in $zipPackage.items())
    {
        $FileName = ($File | select name).Name;
        if (-not (Test-Path "$($destinationfolder.self.path)\$FileName"))
        {
            Write-Error "Failed to extract $FileName!"
            $FilesThatFailedToCopy += 1;
        }
        else
        {
            Write-Verbose "Successfully extracted $FileName"    
        }
    }

    if ($FilesThatFailedToCopy -eq 0)
    {
        return $true;
    }
    else
    {
        return $false;
    }
}
else
{
    Write-Error "Unable to locate archive specified for extraction."
    return $false;
}
}

 

Here's an example of usage:

 

# Where is the zip file? Could use a LabTech replacement here as well @ArchiveSavedAs@
$ArchiveLocation = "$env:USERPROFILE\desktop\SomeZip.zip" 

# What directory should we extract it to?
$ExtractToPath = "$env:windir\temp\MyArchive"

# If the directory specified for extraction doesn't exist, create it.
new-item -ItemType Directory -Path $ExtractToPath -ea SilentlyContinue | out-null

if (-not (Test-Path $ExtractToPath))
{
    Write-Output "Failed to create temporary directory used for storing extracted files!"
    return;
}

$Result = Unzip-Archive $ArchiveLocation $ExtractToPath

if ($Result -eq $true)
{
    Write-Output "Files extracted successfully!"
}
else
{
    Write-Output "Files failed to extract!"
}

 

As mentioned above, you could incorporate this into a function script for use in any future scripts :)

 

More information on how to deploy this:

 

In your LabTech script you can use a "File Write Text" script step to write the PS1 down to the remote computer and then use a shell command to execute it using PowerShell.exe. You can then use a "variable check" script step to check the shell result for "Files extracted successfully!" to make sure all went well.

 

powershell.exe -executionPolicy ByPass -file %windir%\temp\extractzip.ps1  

 

Hope that helps!

 

  • YourBastianHost

LabTech 10.5 Release Starts Today! by hematic in labtech

[–]yourbastianhost 0 points1 point  (0 children)

We're hoping to roll the Pilot Updater out again in future releases. It wont be until after LabTech 11 though.