Update configuration on AeroHive APs with Powershell and SSH

Uncategorized No Comments
$ahouis = @("00-19-77","88-5b-dd","08-EA-44","D8-54-A2","C4-13-E2","40-18-b1")

#get domain admin creds
$dacreds = $(Get-Credential -Message "Please enter domain admin credentials for pulling DHCP info.")
$creds = $(Get-Credential -Message "Please enter AeroHive SSH username and password.")
$server = Read-Host -Prompt "DHCP Server name?"

$dhcpscopes = Invoke-Command -Credential $dacreds -ComputerName $server -ScriptBlock { Get-DhcpServerv4Scope } | select ScopeId
$dhcpleases = $dhcpscopes | ForEach-Object { $scope = $_.'ScopeID'; Invoke-Command -Credential $dacreds -ComputerName $server -ScriptBlock { Get-DhcpServerv4Lease -ScopeId $Using:scope} } 

$aps = @()

$ahouis | ForEach-Object {
    $oui = $_
    $aps += $dhcpleases | ? { $_.'ClientId' -like "$($oui)*" }
}

$aps | select -ExpandProperty ipaddress | % {

    if (Test-Connection -Count 1 -ComputerName $_) {
        New-SSHSession -ComputerName $_ -Credential $creds -AcceptKey -Force
    } else {
        return
    }
    
}

#Get the sessions where we successfully made a connection.
Get-SSHSession | ? { $_.'Connected' -eq $True } | select -ExpandProperty SessionID | % {

    $session = Get-SSHSession -SessionId $_
    $stream = $session.Session.CreateShellStream("dumb",0,0,0,0,1000)
    $stream.Write("show capwap client | include `"Primary Name`"`n")
    Start-Sleep -Seconds 1
    $result = $stream.Read()

    $result.Split([System.Environment]::NewLine) | % {
        if ($_ -like "*Primary Name:*") {
            if ($_ -like "*:cloud-va2-cws-1*") {
                write-host "Already updated"
                #already done
            } elseif ($_ -like "*aerohive.com") {
                #command ran successfully but the host needs updated.
                #$stream.Write("capwap client name cloud-va2-cws-1.aerohive.com`n")
                write-host "Host $($session.Host) needs updated"
                write-host $_
                $stream.Write("capwap client server name cloud-va2-cws-1.aerohive.com`n")
            }
        }
    }

}

#disconnect all sessions
Get-SSHSession | Remove-SSHSession

exit

Move CD-Drive Letter in Lab

Uncategorized No Comments
1..26 | % { Invoke-Command -ComputerName "LABNAME-C$($_)" -ScriptBlock {
Get-WmiObject -Class Win32_volume -Filter "DriveLetter = ""$(Get-Volume | ? { $_.DriveType -eq "CD-ROM" } | select -ExpandProperty DriveLetter | select -first 1):""" |Set-WmiInstance -Arguments @{DriveLetter='Z:'} }

1..26 creates an array 1 through 26.
% is short for foreach
$($_) uses each number from the 1..26 array
$(Get-Volume | ? { $_.DriveType -eq “CD-ROM” } | select -ExpandProperty DriveLetter | select -first 1) gets the first cd drive.

Select only 25 Active Emails as CSV

Uncategorized No Comments

$mail = @(); $teachers = Get-ADUser -filter { mail -like "*@localdomain.com" } -Properties mail | ? { $_.Enabled -eq $True } | select mail | select -First 25 | % { $mail += $_.mail }; $mail -join "," | clip
$mail = @(); $teachers = Get-ADUser -filter { mail -like "*@localdomain.com" } -Properties mail | ? { $_.Enabled -eq $True } | select mail | select -First 25 -Skip 25 | % { $mail += $_.mail }; $mail -join "," | clip
etc.

Powershell Detection Method Uninstaller

Uncategorized No Comments

There is no detection method logic to check that a file doesn’t exist for a required Application.

You have two options to accomplish this:
1. You run a script that creates a file after the uninstall if complete. Then use the file as a detection method.
2. Run a Powershell script that checks that the file is missing and return $true.

Option #2:
sccm-programs

sccm-detection-method


if (-Not (Test-Path "c:\Program Files (x86)\Program\Program.exe") -and -Not (Test-Path "c:\Program Files\Program\Program.exe")) { $true }

Replace fake checkboxes with Content Control Checkboxes in Word

Uncategorized No Comments

Sub ReplaceWithCheckBoxes()
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ChrW(61551)
        .Replacement.Text = ChrW(9744)
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    Do While Selection.Find.Execute
    Selection.Range.ContentControls.Add (wdContentControlCheckBox)
    Loop
    End With
End Sub

Most Recently Edited File

Uncategorized No Comments

Making note of this because I use it so often.  It is an easy way to find where configuration files are after making a change in a GUI.

Lists the last 10 recently edited files:


find . -type f -printf '%T@ %p\n' | sort -n | tail -10

Samba shares with PowerBroker Identity Services

Uncategorized Comments Off on Samba shares with PowerBroker Identity Services

Install PowerBroker Identity Services from their website. I personally only install the the pbis-open.deb and pbis-open_upgrade.deb.

Prerequisites:


sudo apt-get install samba samba-common

You are going to get an error about PAM conflicts with likewise. Just ignore and go on.


sudo /opt/pbis/bin/domainjoin-cli join domain.fqdn username
sudo /opt/pbis/bin/config AssumeDefaultDomain 1
sudo /opt/pbis/bin/config UserDomainPrefix DOMAIN
sudo /opt/pbis/bin/config RequireMembershipOf DOMAIN\\group1 DOMAIN\\group2
sudo /opt/pbis/bin/config LoginShellTemplate /bin/bash
sudo /opt/pbis/bin/samba-interop-install --install
sudo nano /etc/samba/smb.conf

[global]
        security = ADS
        workgroup = DOMAIN
        realm = DOMAIN.FQDN
        machine password timeout = 0
        log file = /var/log/samba/log.%m
#       log level = 2
        Kerberos method = dedicated keytab
        dedicated keytab file = /etc/krb5.keytab

[share]
        writeable = yes
        create mode = 777
        path = /share
        directory mode = 777
        valid users = @DOMAIN\groupname

sudo service smbd restart

Should work!

Find and Sort Files by Recent Modified Date

Uncategorized No Comments

find . -printf "%T@ %Tc %p\n" | sort -n

Gimp 2.8 in Ubuntu 12.04

Uncategorized No Comments

I’m a big fan of the newest feature in GIMP called Single Window Mode. You have to add this PPA to get Gimp 2.8 in Ubuntu 12.04.


sudo su
add-apt-repository ppa:otto-kesselgulasch/gimp -y && apt-get update && apt-get install gimp -y

Open GIMP, click on Windows and click on Single Window Mode.

Yay!

Clone Linux Hard Drive

Uncategorized No Comments

So the other day I wanted to swap out the hard drives in my laptop. I had a sata hard drive that had slightly better performance and I wanted to trade to use the slower hard drive in another project. I figured it would be an easy fix since I pretty much have a good understanding of Linux now. However, I was wrong. My first attempt was booting a live cd, using gparted to create my partitions, then using rsync to clone the hard drive. I attempted 3 times and each time it rebooted I got an error about X being in safemode. All my files were there, I had fixed the boot sector but it still failed. I ended up using DD to copy the partitions and fschk to fix the filesystem size on the new partition. I’ll have to wait until my next need to try out these commands but I wanted to document them.

From a live CD and after clicking on each partition in nautilus to mount them: (found these switches online, untested)


rsync -aAXv /media/BLKIDOFOLDHDD /media/BLKIDOFNEWHDD

To reinstall grub:


install-grub --boot-directory /media/BLKIDOFNEWHDD /dev/sdx

You need to update the /etc/fstab on your new hard drive. You will need to know the BLKID of your newly created partitions. At the command prompt you need to run:


blkid
sudo gedit /media/BLKIDOFNEWHDD/etc/fstab

That should be it. The new hard drive should boot. If nothing else at least some of my commands are documented here for myself and I can test out that rsync command later.

« Previous Entries