Monday, January 20, 2020

Back-Up your Powershell ISE color scheme

I used this method to import my favorite Powershell ISE color scheme, to another computer:

# Back-Up your Powershell ISE color scheme -
$ISE_Settings = @()
$ISE_Settings += "`$psISE.Options.ScriptPaneBackgroundColor = '$(($psISE.Options.ScriptPaneBackgroundColor).ToString())'"
$ISE_Settings += "`$psISE.Options.ScriptPaneForegroundColor = '$(($psISE.Options.ScriptPaneForegroundColor).ToString())'"
Write-Host "`$psISE.Options.ScriptPaneBackgroundColor = '$(($psISE.Options.ScriptPaneBackgroundColor).ToString())'"
Write-Host "`$psISE.Options.ScriptPaneForegroundColor = '$(($psISE.Options.ScriptPaneForegroundColor).ToString())'"
$psISE.Options.TokenColors | % {
    $ISE_Settings += "`$psISE.Options.TokenColors.item('$($_.Key)') = '$($_.Value)'"
    Write-Host "`$psISE.Options.TokenColors.item('$($_.Key)') = '$($_.Value)'"
}
# Run this in your new ISE, to import...
$ISE_Settings |  Out-File "C:\Powershell_Stuff\ISE_Settings.ps1"


 Those Write-Host items are there, just in case the import can be done via copy / pasta.


$psISE.Options.ScriptPaneBackgroundColor = '#FFF5DEB3'
$psISE.Options.ScriptPaneForegroundColor = '#FF000000'
$psISE.Options.TokenColors.item('Attribute') = '#FF00BFFF'
$psISE.Options.TokenColors.item('Command') = '#FF0000FF'
$psISE.Options.TokenColors.item('CommandArgument') = '#FF8A2BE2'
$psISE.Options.TokenColors.item('CommandParameter') = '#FF000080'
$psISE.Options.TokenColors.item('Comment') = '#FF006400'
$psISE.Options.TokenColors.item('GroupEnd') = '#FF000000'
$psISE.Options.TokenColors.item('GroupStart') = '#FF000000'
$psISE.Options.TokenColors.item('Keyword') = '#FF00008B'
$psISE.Options.TokenColors.item('LineContinuation') = '#FF000000'
$psISE.Options.TokenColors.item('LoopLabel') = '#FF00008B'
$psISE.Options.TokenColors.item('Member') = '#FF000000'
$psISE.Options.TokenColors.item('NewLine') = '#FF000000'
$psISE.Options.TokenColors.item('Number') = '#FF800080'
$psISE.Options.TokenColors.item('Operator') = '#FF696969'
$psISE.Options.TokenColors.item('Position') = '#FF000000'
$psISE.Options.TokenColors.item('StatementSeparator') = '#FF000000'
$psISE.Options.TokenColors.item('String') = '#FF8B0000'
$psISE.Options.TokenColors.item('Type') = '#FF006161'
$psISE.Options.TokenColors.item('Unknown') = '#FF000000'
$psISE.Options.TokenColors.item('Variable') = '#FFFF0000'

 


Friday, January 17, 2020

Audit Mapped drive GPO with Powershell

Lists out all of the mapped drives in a GPO.
I’ve found a few different approaches to auditing ‘Drive Maps’ GPO - But wanted something easier to read…
It also shows where these settings are found in the XML output of a GPO report.
Hopefully the below offering is helpful to others:
Getting to the exact path / data, was kinda' a pan in in the ass!
$report.GPO.User.extensiondata.Extension.DriveMapSettings.Drive



try
{
If (!(Get-Module GroupPolicy)) {Import-Module GroupPolicy -ErrorAction Stop}
}
catch
{
throw "Module GroupPolicy not Installed"
}


$GPOs = Get-GPO -All  | ? {
($_.DisplayName -match "drive") -and `
($_.DisplayName -NOTmatch "Hide") -and `
($_.DisplayName -NOTmatch "Remote")  -and `
($_.GpoStatus -match "Enabled")
}
$GPOs.Id.Guid
$GPOs.DisplayName | % {
    Write-Host "##########################" -ForegroundColor DarkYellow
    Write-Host " Policy Name: " -ForegroundColor Yellow -NoNewline
    Write-Host "$($_)" -ForegroundColor Green
    Write-Host " GPO GUID: " -ForegroundColor Yellow -NoNewline
    Write-Host "$($GPOs.Id.Guid)" -ForegroundColor Green
    [xml]$report = get-gporeport -Name $_ -ReportType XML
    $Output = @()
    Write-Host " ~~~~~~~~~~~~~~~~~~~~~~"
    $report.GPO.User.extensiondata.Extension.DriveMapSettings.Drive | % {
        Clear-Variable -Name ("DriveLetter", "Label", "Path ","Action","Targeting") -ErrorAction SilentlyContinue
        $DriveLetter = $_.Properties.Letter
        $Label = $_.Properties.label
        $Path = $_.Properties.path
        $Action = $_.Properties.action
        $Targeting = $_.Filters.FilterGroup.Name
            $OutputX = New-Object PSObject
                $OutputX | Add-Member -type NoteProperty -Name 'DriveLetter' -Value $DriveLetter
                $OutputX | Add-Member -type NoteProperty -Name 'Label' -Value $Label
                $OutputX | Add-Member -type NoteProperty -Name 'Path' -Value $Path
                $OutputX | Add-Member -type NoteProperty -Name 'Action' -Value $Action
                $OutputX | Add-Member -type NoteProperty -Name 'Targeting' -Value $Targeting
            $Output += $OutputX
        }
    }

$CRUD = @{
C = "Create"
R = "Replace"
U = "Update"
D = "Delete"
}
$Output | sort DriveLetter | % {
    If (($_.Label -ne "") -and ($_.Label -ne $null)) {
    Write-Host "   Drive Label: " -ForegroundColor Yellow -NoNewline
    Write-Host $_.Label -ForegroundColor Cyan
    }
    Write-Host "   Drive Letter: " -NoNewline -ForegroundColor Yellow
    Write-Host "$($_.DriveLetter):" -NoNewline -ForegroundColor Yellow -BackgroundColor Magenta
    If (($_.Path -ne "") -and ($_.Path -ne $null)) {
    Write-Host " $($_.Path)" -ForegroundColor Cyan
    }
    If (($_.Path -eq "") -and ($_.Path -eq $null)) {
    Write-Host "" -ForegroundColor Cyan
    }
    If (($_.Path -ne "") -and ($_.Path -ne $null)) {
    Write-Host "   Targeting (group): " -NoNewline -ForegroundColor Yellow
    Write-Host $_.Targeting -ForegroundColor Cyan
    }
    If ($_.Action -ne "") {
    Write-Host "     Action: $($CRUD[$_.Action])
    "
    }
}