Saturday, December 20, 2008
PowerShell at HIMSS
This year, the presentation will be titled, “Managing your Healthcare environment with PowerShell”. I am looking forward to evangelizing PowerShell with this group! Given the time constraint (approx. 50 minutes), I will more then likely show examples of various monitoring and scheduled jobs that we currently use. I will also try to demonstrate how the use of PowerShell has impacted productivity and budgets.
Any suggestions from the PowerShell community would be appreciated!
Friday, December 19, 2008
PowerShell Twitterers
What is Twitter you ask? Good question! A concise definition would be - It is free social networking service. This however doesn't quite do it justice. Check out a few of the following posts for a better idea of how people are using it.
- http://tweeternet.com/
- http://www.davidleeking.com/2008/07/09/why-use-twitter/
- http://www.caroline-middlebrook.com/blog/twitter-guide-1-what-is-twitter/
- http://www.901am.com/2007/the-top-5-ways-smart-people-use-twitter.html
Better yet, go to Twitter and set up your free account.
Enjoy!
Wednesday, December 17, 2008
BlackBerry Disaster Recover Information
Was asked yesterday if I could write something that would periodically generate a CSV file of our BlackBerry users and their pin numbers. This "report" would be used for communication purposes in a Disaster situation. I looked on the BlackBerry server for a few minutes hunting for a way to do it from the server. No such luck. I then remembered that all the data resides in SQL Server diligently waiting to be queried. Following is a small script that I have scheduled to run once a week:
# Parse the DN to get the SAMAccountName
$SQLQuery = "SELECT DisplayName,PIN,CreationTime,MailboxSMTPAddr,
Right(MailboxDN,(LEN(MailboxDN)-CHARINDEX('s/cn=', MailboxDN)-4)) AS SamAccountName
FROM UserConfig
ORDER BY DisplayName"
#Set up connection
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = YourServer; Database = YourDB; User ID=YourID; Password=YourPWD; Integrated Security = False"
$SqlConnection.Open()
# Setup SQL Command
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SQLQuery
$SqlCmd.Connection = $SqlConnection
# Create the table and export!
$SqlVMDataReader = $SqlCmd.ExecuteReader()
$SqlVMDataTable = New-Object System.Data.DataTable
$SqlVMDataTable.Load($SqlVMDataReader)
$SqlVMDataTable Export-Csv 'L:\DRDocs\BBPins.csv' -noTypeInformation
# Cleanup
$SqlVMDataReader.Close()
$SqlConnection.Close()
Enjoy!
Monday, December 15, 2008
PrimalForms Example (Virtual Center Log)
Concurrently, I was investigating PrimalForms (PowerShell UI builder - FREE). Once I saw Alan's post, I knew it would be a good example to try PrimalForms with.
The UI was simple to create with PrimalForms, here is a screenshot of the UI.
The dropdowns are filled on the form load with the following:
- Distinct Virtual Machine
- Distinct User
- Distinct Event (in Alan's case vim.event.VmRemovedEvent)
- Search Start Date
- Search End Date
Selecting the above variables generates the SQL statement to the VPX_EVENT table. The results are then passed to the datagrid.
Pretty cool!
As soon as I figure out how to attach a text file to Blogger, I will do so. In the short-term, if you are interested in the script(s), send me a note at stahler.2@osu.edu.
Enjoy!
Thursday, November 6, 2008
Creating Printer Install Batch Files
Was given the task to write a PowerShell script that would do the following:
- Given a supplied list of host name, find the hostnames that have a specific named printer. In this case "osu_mc" will be in the Name property.
- If a printer is found, create a batch file that is titled from the supplied host name.
- The batch file should contain these 2 lines for every printer
"rundll32 printui.dll,PrintUIEntry /in /q /n" and
the printer name:
(i.e. file:////OSU/NDPS_HP4350.OSU.HOSP.CAMPUS.OSU)
Here is the script that meets the need!
Function Get-PrinterName ([string]$HostName) {
Begin {}
Process {
Write-Host "HostName: "$_
$FileName = "C:\PrinterBatch\" + $_ + ".bat"
$file = New-Item -type file $FileName
$Printers = Get-WmiObject `
-Class Win32_Printer`
-ComputerName $_ `
-ErrorAction SilentlyContinue
ForEach ($Printer in $Printers){ if ($Printer.Name -match 'osu_mc'){
Add-Content -Path $FileName `
-value "rundll32 printui.dll,PrintUIEntry /in /q /n"
Add-Content -Path $FileName `
-value $Printer.Name
}
}
}
}
Get-Content 'C:\HostNames.txt' Get-PrinterName
Enjoy!
Wednesday, October 29, 2008
Logon Restrictions
Was approached yesterday with the following request.
- Find all users that have a logon restriction
- Return Last, First name and the users login ID
- Indicate if they belong to any group like "Citrix.PatientLink.*"
Quest AD CMDLETS to the rescue (again).
First let's find all the users with a logon restriction and toss them into a CSV file.
GET-QADUser -SizeLimit 0 -IncludeAllProperties `
WHERE {$_.logonHours -ne $null} `
SELECT logonname, logonHours `
EXPORT-CSV -Path 'C:\logonRestrictions.csv' -NoTypeInformation
We have to use the parameter -IncludeAllProperties to expand the property logonHours.
Next we will use this list to grab the users last, first name, department, logonName and indicate if they belong to any group matching "Citrix.PatientLink.*".
function Get-LogonRestrictions {
foreach($Users in $AllUsers) {
$MemberOF = $Null
$User = Get-QADUser $Users.LogonName `
Select LastName, FirstName, Department, LogonName, MemberOf
$Groups = (Get-QADUser $Users.LogonName).MemberOf
foreach ($Group in $Groups){
if($Group -match 'Citrix.Patient') {
$MemberOF = (get-qadgroup $Group).Name
}
}
$obj = New-Object psObject
$obj Add-Member NoteProperty LastName $User.LastName
$obj Add-Member NoteProperty FirstName $User.FirstName
$obj Add-Member NoteProperty Department $User.Department
$obj Add-Member NoteProperty LogonName $User.LogonName
$obj Add-Member NoteProperty MemberOF $MemberOF
Write-Output $obj
}
}
$AllUsers = Import-Csv -Path 'C:\logonRestrictions.csv'
$AllUsers Get-LogonRestrictions Export-Csv `
-Path 'C:\logonRestrictionsDetail.csv'
And we are done!
Wednesday, October 15, 2008
PowerScripting Podcast
- Jeffery Snover
- Don Jones
- Alex Reidel
- Kirk Munro
Do it!