Category Archives: Uncategorized

Windows Update Fix Script

This can run as a BAT file. Depending on which version of Windows you run this script on you may get a bunch of errors as it trys to register dlls that don’t exist.

title windows update fix
cls
echo  DO NOT CLOSE THIS COMMAND PROMPT OR YOU WILL BREAK WINDOWS!!!!
PAUSE 
net stop wuauserv
net stop bits
net stop cryptsvc
ren %systemroot%\System32\Catroot2 Catroot2.old
ren %systemroot%\SoftwareDistribution SoftwareDistribution.old
regsvr32 c:\windows\system32\vbscript.dll /s
regsvr32 c:\windows\system32\mshtml.dll /s
regsvr32 c:\windows\system32\msjava.dll /s
regsvr32 c:\windows\system32\jscript.dll /s
regsvr32 c:\windows\system32\msxml.dll /s
regsvr32 c:\windows\system32\actxprxy.dll /s
regsvr32 c:\windows\system32\shdocvw.dll /s
regsvr32 wuapi.dll /s
regsvr32 wuaueng1.dll /s
regsvr32 wuaueng.dll /s
regsvr32 wucltui.dll /s
regsvr32 wups2.dll /s
regsvr32 wups.dll /s
regsvr32 wuweb.dll /s
regsvr32 Softpub.dll /s
regsvr32 Mssip32.dll /s
regsvr32 Initpki.dll /s
regsvr32 softpub.dll /s
regsvr32 wintrust.dll /s
regsvr32 initpki.dll /s
regsvr32 dssenh.dll /s
regsvr32 rsaenh.dll /s
regsvr32 gpkcsp.dll /s
regsvr32 sccbase.dll /s
regsvr32 slbcsp.dll /s
regsvr32 cryptdlg.dll /s
regsvr32 Urlmon.dll /s
regsvr32 Shdocvw.dll /s
regsvr32 Msjava.dll /s
regsvr32 Actxprxy.dll /s
regsvr32 Oleaut32.dll /s
regsvr32 Mshtml.dll /s
regsvr32 msxml.dll /s
regsvr32 msxml2.dll /s
regsvr32 msxml3.dll /s
regsvr32 Browseui.dll /s
regsvr32 shell32.dll /s
regsvr32 wuapi.dll /s
regsvr32 wuaueng.dll /s
regsvr32 wuaueng1.dll /s
regsvr32 wucltui.dll /s
regsvr32 wups.dll /s
regsvr32 wuweb.dll /s
regsvr32 jscript.dll /s
regsvr32 atl.dll /s
regsvr32 Mssip32.dll /s
net start wuauserv
net start bits
net start cryptsvc
echo I HAVE FINSHED, REBOOT THIS COMPUTER
PAUSE 
exit

User prompts in PowerShell

This first example is a simple Yes / No…..

#region select search
$Correct = "N"
while($Correct -ne "Y"){

    $SelectedSearch = Read-Host -Prompt "Enter the name of the search you wish to action"
    $Correct = Read-Host -Prompt "Is this the correct Search '$SelectedSearch' (y/n)"
}
#endregion select search

This second example nests another confirmation…..



#region hard or soft
$Correct = "N"
while($Correct -ne "Y"){

    $Action = "X"
    $Actions = "h", "s"
    while($Actions -notcontains $Action){

        $Action = Read-Host -Prompt "Hard Delete or Soft Delete (h/s)"
    }
    
    if($Action -eq "s"){$ActionDesc = "Soft Delete"}
    elseif($Action -eq "h"){$ActionDesc = "Hard Delete"}
    $Correct = Read-Host -Prompt "Is this the correct action '$ActionDesc' (y/n)"
}
#endregion hard or soft

Setting Modern or Basic Auth


# Basic and Modern Authentication Policies

$email = "test@test.ac.uk"
Connect-ExchangeOnline

$AuthPolicies = Get-AuthenticationPolicy | select name, allow*
$DefaultAuthPolicy = Get-OrganizationConfig | Select DefaultAuthenticationPolicy
$User = get-user $email | select UserPrincipalName, AuthenticationPolicy


$AuthPolicies | fl
$DefaultAuthPolicy
$User | fl

#Set User Level Auth Policy
#Set-User -Identity $Email -AuthenticationPolicy "Block Basic Authentication"

#Set Tenant Level Auth Policy
#Set-OrganizationConfig -DefaultAuthenticationPolicy "Block Basic Authentication"

This will list all of the available Auth Policies, show which one is assigned to $email and then change the policy applied to $email.

Send-Mail

$Body = "<i>Enter your HTML Waffle here</i>"
$Creds = Get-Credential

$MailProps = @{
    To = "Joe.Bloggs@domain.com"
    From = "Joe.Bloggs@domain2.com"
    Body = $Body
    BodyAsHTML = $true

    Subject = "Test"
    UseSSL = $true
    Port = 587
    SMTPServer = "smtp.domain.com"
    Credential = $Creds
    Attachments = "C:\temp\file.txt"
}

Send-Mail @MailProps

Floating images with the Display Posts plugin

It’s a great plugin bit the view is a bit clunky if you are displaying thumbnails and exerpts. Try adding the CSS below:

/* ICENI CUSTOM CSS */
.display-posts-listing img{
    float: left;
    margin: 0px 10px 10px 10px;
}
.display-posts-listing li{
    clear: both;
    list-style: none;
}

This can be added at the bottom of a CSS file or through the GUI at Appearance > Customise > Additional CSS

Tags and Categories on Pages

I’ve thrown together this plugin to sort this!

<?php
/*
Plugin Name: Enable Tags in WordPress Pages
Plugin URI: http://www.sitepoint.com/
Description: Enables tags in all content
Version: 1.0
Author: Craig Buckler
Author URI: http://twitter.com/craigbuckler
License: Free to use and adapt
*/

// add tag support to pages
function tags_support_all() {
	register_taxonomy_for_object_type('post_tag', 'page');
}

// ensure all tags are included in queries
function tags_support_query($wp_query) {
	if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
}

// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');

Excerpts on Pages

Add the following to the Functions.php file…

/**
 * Enables Excerpts on Pages
 */
function enable_page_excerpt() {
  add_post_type_support('page', array('excerpt'));
}
add_action('init', 'enable_page_excerpt');

Adding it manually is a bad idea and I should stop being lazy so here is the same thing as its own plugin!

<?php
/*
Plugin Name: Enable Excerpts in WordPress Pages
Plugin URI: http://www.icenidesign.com/
Description: Enables Excerpts on pages
Version: 1.0
Author: Tom Nickel
Author URI: http://twitter.com/icenidesign
License: Free to use and adapt
*/


function enable_page_excerpt() {
  add_post_type_support('page', array('excerpt'));
}
add_action('init', 'enable_page_excerpt');

Save it as a php file in a folder of the same name and upload it to the plugins folder.

Checking if a variable has been submitted to a function

$PSBoundParameters.ContainsKey('Username')

The line above will return true if the ‘Username’ has been provided to the function

https://stackoverflow.com/questions/48643250/how-to-check-if-a-powershell-optional-argument-was-set-by-caller

Function get-TPNUserState() {
    <#
    .Description
    Supplies some sommonly needed values for a user:
    PasswordLastSet, DisplayName, Description, LastLogonDate, Manager, DistinguishedName, whencreated

    .Example
    get-TPNUserState tp-nickel

    .Parameter Username
    The username that you want to look into. If you don't enter one then it will prompt you.

    #>

    [Cmdletbinding()]
    param(
        [Parameter(Position=0)]
        [string]$Username
        )
    process{
         
        if(!$PSBoundParameters.ContainsKey('Username')){ $Username = read-host -Prompt UserName } #if Username is not set then prompt for it.
        Get-ADuser $Username -properties PasswordLastSet, DisplayName, Description, LastLogonDate, Manager, DistinguishedName, whencreated | select SAMAccountName, DisplayName, Description, Enabled, PasswordLastSet, LastLogonDate, whencreated, Manager, DistinguishedName | fl
    }

}

Module Directory in PowerShell

$env:PSModulePath -split ';'

The command above will list the directories that PowerShell will search for installed modules.

There is a difference between VSCode and PowerShell ISE though!

VSCode
PowerShell ISE

Notethat VSCode looks in C:\Users\User\Documents\Powershell\Modules compared with C:\Users\User\Documents\WindowsPowershell\Modules