Monday, September 22, 2014

Permanently removing Requests from SCSM 2012

There isn't a native way (that I could find) to remove Request from System Center Service Manager. Of course, I found a way to do it through the-all-mighty Powershell.
I know... ITIL/Compliance/ITSM you shouldn't ever delete any records but I'm in the middle of building out a new deployment of SCSM 2012 and I've entered a TON of test requests and it was "suggested" that I remove them prior to going live.

So yeah, I removed them - even though only Analyst could see them and they would soon fade out of sight as legit tickets begin to stream into the new system.

get-scsmclassinstance -class (get-scsmclass -name system.workitem.incident) | where-object {$_.id -eq "IR12345"} | Remove-scsmclassinstance

Thursday, August 28, 2014

Exchange 2010 - Creating a Dynamic Distribution List from an AD Security Group

As part of SCSM group notifications I wanted a way to provide security; separate the analysts into groups; be able to provide email addresses for each of the groups; and not have to manage the groups myself.

Enter - Dynamic Distribution Groups

I opened the Exchange Administration Console and started creating a new Dynamic Distribution Group (DDG). I quickly realized that I am unable to filter the DDG based on an Active Directory Security Group (ADSG) like I thought I could.

Quick google search later and I found this technet article

Here is what I came up with Open the Exchange Shell and enter the following commands:

New-DynamicDistributionGroup -Name "NAME_OF_DDG_TO_CREATE" -RecipientFilter {(RecipientTypeDetails -eq 'UserMailbox') -and (MemberOfGroup -eq 'CN=ADSEC_GROUP,OU=GROUPS,DC=SOMEWHERE,DC=COM')

Then I was able to find my DDG in the Exchange Administration Console and set other options like:

  • "Managed By"
  • "Select the recipient container where you want to apply this filter" (by default this points to domain/Users and we have moved all users into a different container for organization)
  • "Hide group from Exchange address lists" (I don't want people to be able to email these groups directly
  • "Do not send delivery reports" (No need since all of these emails are coming from Orchestration Runbooks as the SCSM notifications)

Monday, August 11, 2014

Check for Running Task & Start

We have an open source Application call iSpy Connect that monitors all of the IP cameras in the building. This software (because we aren't paying for the licensed version) runs as a standard application and not as a service. This causes issues when someone logs into the server to check a recording and closes the Application or logs out. Now the software isn't running which means it isn't recording camera activity. I wrote this powershell script to check to see if the service was running. If it's running it just closes... if it's not running it will start the application. It looks like this -
#Process Name
$procToCheck = "iSpy"

#Process exe location
$procFileExe = "C:\Program Files\iSpy\iSpy (64 bit)\ispy.exe"

#Checks for running process and starts if needed 
$process = Get-process $procToCheck
if (!($process)) {
 start-process $procFileExe
}
And added a 15 minute task in Task Scheduler following these steps: Create Basic Task Name Task and Description Schedule it Daily Run it Every Day Start a Program Program/Script: powershell.exe Add arguments (optional): -file "c:\scripts\ispy_Running.ps1" Check the box to open the Properties dialog for this task when clicking Finish Double click the trigger created to edit the trigger Check the box to Repeat the task every: - And set it to 15 minutes or whatever is appropriate Change the duration to Indefinite Save your changes and that should create a task that will monitor for your program running and start it should it close (or be closed)

Wednesday, April 30, 2014

Excel - Format Data Cell for kb/mb/gb

Have you ever exported a powershell script only to see values like 876755433?

Have you ever wanted an easy way to format that number auto-magically into a kb's mb's or gb's?

Use the following process:

In Excel
Select the column needed to format
Right click column header
Choose "Format Cells"
Choose the "Custom" option under the "Number" tab
Paste this value - [<1000]#,##0.00" KB ";[<1000000]#,##0.00," MB";#,##0.00,," GB"
And click OK


MAGIC!

Monday, April 21, 2014

Remote DNS Check

In moving our data center the request was made to identify all servers with static IP's that had DNS entries of servers that we were being decommissioned.
This is what I used -
param( 
  [parameter(ValueFromPipeline=$TRUE)] 
    [String[]] $ComputerName=$Env:COMPUTERNAME, 
    [System.Management.Automation.PSCredential] $Credential 
) 
 
begin { 
  $PipelineInput = (-not $PSBOUNDPARAMETERS.ContainsKey("ComputerName")) -and (-not $ComputerName) 
 
  # Outputs the computer name, IP address, and DNS and WINS settings for 
  # every IP-enabled adapter on the specified computer that's configured with 
  # an IPv4 address. 
  function Get-IPInfo($computerName) { 
    $params = @{ 
      "Class" = "Win32_NetworkAdapterConfiguration" 
      "ComputerName" = $computerName 
      "Filter" = "IPEnabled=True" 
    } 
    if ( $Credential ) { $params.Add("Credential", $Credential) } 
    get-wmiobject @params | foreach-object { 
      foreach ( $adapterAddress in $_.IPAddress ) { 
        if ( $adapterAddress -match '(\d{1,3}\.){3}\d{1,3}' ) { 
          foreach ( $dnsServerAddress in $_.DNSServerSearchOrder ) { 
            new-object PSObject -property @{ 
              "ComputerName" = $_.__SERVER 
              "IPAddress" = $adapterAddress 
              "DNSServer" = $dnsServerAddress 
            } | select-object ComputerName,IPAddress,DNSServer 
          } 
        } 
      } 
    } 
  } 
} 
 
process { 
  if ( $PipelineInput ) { 
    Get-IPInfo $_ 
  } 
  else { 
    $ComputerName | foreach-object { 
      Get-IPInfo $_ 
    } 
  } 
}

Gather all 5 FSMO Roles with Powershell

<#
This simple script will pole your domain for the 5 FSMO roles
#>
import-module activedirectory
$fqdn = Read-Host 'Domain Name'
$forest = get-adforest $fqdn | Format-Table SchemaMaster,DomainNamingMaster
$domain = get-addomain $fqdn | Format-Table PDCEmulator,RIDMaster,InfrastructureMaster
$info = $forest,$domain
$info

Monday, February 3, 2014

Poor Man's Hardware Inventory - Powershell through logon script

We are in the middle of migrating a domain to ours and I was working on a plan to move all of the PC's over. I wanted to make sure that I was able to capture all of the existing hardware/OS configs without staying up till 2am and grab them manually... if they were online:)
I came up with this powershell script that will run on logon and write back to a specified location. Then I could gather them as people logged on/connected.
$name = (Get-Item env:\Computername).Value
$filepath = "\\SERVER\DIRECTORY"

function inventory {
# MotherBoard: Win32_BaseBoard
$manuf = Get-WmiObject Win32_ComputerSystem -ComputerName $name
# Hard-Disk
$hd = Get-WmiObject win32_diskDrive -ComputerName $name | ForEach-Object {[math]::round($_.size / 1GB)}
# Memory
$mem = Get-WmiObject Win32_ComputerSystem -ComputerName $name | ForEach-Object {[math]::round($_.TotalPhysicalMemory / 1GB)}
# Processor 
$cpu = Get-WmiObject Win32_Processor -ComputerName $name
#OS Architecture
$OS = Get-WmiObject Win32_OperatingSystem -ComputerName $name
## System enclosure 
$enc = Get-WmiObject Win32_SystemEnclosure -ComputerName $name
$type = $enc.chassistypes
$chassis = Switch ($type)
    {
        "1" {"Other"}
        "2" {"Virtual Machine"}
        "3" {"Desktop"}
        "4" {"Low Profile Desktop"}
        "5" {"Pizza Box"}
        "6" {"Mini Tower"}
        "7" {"Tower"}
        "8" {"Portable"}
        "9" {"Laptop"}
        "10" {"Notebook"}
        "11" {"Handheld"}
        "12" {"Docking Station"}
        "13" {"All-in-One"}
        "14" {"Sub-Notebook"}
        "15" {"Space Saving"}
        "16" {"Lunch Box"}
        "17" {"Main System Chassis"}
        "18" {"Expansion Chassis"}
        "19" {"Sub-Chassis"}
        "20" {"Bus Expansion Chassis"}
        "21" {"Peripheral Chassis"}
        "22" {"Storage Chassis"}
        "23" {"Rack Mount Chassis"}
        "24" {"Sealed-Case PC"}
        Default {"Unknown"}
     }

##Excract Object Data
$obj = New-Object psobject
$obj | Add-Member noteproperty Manufacturer $manuf.Manufacturer
$obj | Add-Member noteproperty Model $manuf.Model
$obj | Add-Member noteproperty CPU $cpu.Name
$obj | add-member noteproperty RAM $mem
$obj | add-member noteproperty HD $hd
$obj | Add-Member noteproperty Type $chassis
$obj | Add-Member noteproperty OS $OS.Caption
$obj | Add-Member noteproperty Arch $OS.OSArchitecture
Write-Output $obj
}

##Run function and export to csv
inventory | format-table
inventory | Export-Csv -NoTypeInformation $filepath\$name.csv

Remote Mailboxes - Hybrid Config - Missing

The Remote Mailbox exists on the On Prem Exchange server and linked to the Office 365 mailbox. Without one of these for each Office 365 mail...