Friday, October 5, 2012

Replacement Commands

Netdom http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/29/use-powershell-to-replace-netdom-commands-to-join-the-domain.aspx

UPDATE - PowerShell 3.0 now includes a last switch for get-content
get-content <file> -last 5
To watch a log file ...
get-content <file> -wait
but not exactly the same functionality. So a better way is to get the command from Microsoft.

Tail is included in the 2003 Resource Kit and works well in Server 2008 environment.
Download tail here:
http://www.microsoft.com/download/en/details.aspx?id=17657

Thursday, June 14, 2012

Tips and Tricks in 3.0

Latest

From Scripting Guy 5 new tips and tricks

http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/20/my-five-favorite-powershell-3-0-tips-and-tricks.aspx

Create PowerShell profiles

http://msdn.microsoft.com/en-us/library/windows/desktop/bb613488(v=vs.85).aspx

help *  (man for linux)

New window popup
help get-service -showwindow  (v2 help get-process -online )

Auto build you commands
show-command get-wmiobject

Help can get updates
update-help (save-help)

Find the verbs
Get-verb

Find the verbs and count
Measure-object

If you have a conflict
microsoft.powershell.management\get-process

One Line is Magic
get-process | kill -whatif
get-process | kill -confirm

get-process [a-r]*[g-w] | kill -whatif

does it work well in a pipeline?
get-help get-service -full

PowerShell 3.0

Crash Course on V3 (awesome)
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/WSV321

Check out whats new in powershell 3.0
http://technet.microsoft.com/en-us/library/hh857339.aspx

Guides from Technet Library
http://technet.microsoft.com/en-us/library/bb978525.aspx

Tuesday, May 29, 2012

Using Powershell to change powerpoint themes

 
Getting ready to give a presentation and noticed that all 14 modules are using the wrong theme.  Started in changing the theme on the seeming endless list of files and I thought, how about powershell.  Well after a quick search found this great article from Ed Wilson, thank you again ED!  http://blogs.technet.com/b/heyscriptingguy/archive/2010/05/11/hey-scripting-guy-may-11-2010.aspx
I did simplify his code by just using one folder that contains both the theme an PowerPoint slides. Just change $themepath  to the name and location or your theme and $path to the folder location of your powerpoint slides are you are set.
Add-type -AssemblyName office
$Application = New-Object -ComObject powerpoint.application
$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$themePath = "c:\presentations\moc.thmx"
$path = "C:\Presentations"
Get-ChildItem -Path $path -Include "*.ppt", "*.pptx" -Recurse |
ForEach-Object {
 $presentation = $application.Presentations.open($_.fullname)
 $presentation.ApplyTemplate($themePath)
 $presentation.Save()
 $presentation.Close()
 "Modifying $_.FullName"
} 

$application.quit()
$application = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()




Wednesday, May 2, 2012

User Demo

Well I need to test the view limits of the new Active Directory Administrative Center I needed a quick 10000 users.  So I started by clicking … Ok thats not going to happen.  I need a script and needed to work with the AD module introduced back in Windows Server 2008 R2.
First problem is to count through several users.  After a little research the best cmdlet for this is the For Loop and here is the syntax.  I started my testing only using 25 students.
For (variable=starting number ; variable less than or equal to last number ; increment)
for ($u = 0; $u -le 25; $u++) {
     $user = "Student"+$("{0:D2}" -f $u)
    Write-Host "Creating User for $user from $u"
}
NOTE that "+$("{0:D2}" cleans up the display to 2 characters
for ($u = 0; $u -le 25; $u++) {
     $user = "Student"+$("{0:D2}" -f $u)
    Write-Host "Creating User for $user from $u"
}
image
Now that I am counting I am ready to add user but running out of time today more to come later.

Wednesday, March 28, 2012

Replacement for Unix tail command in Windows

Wow - surprised to find that there is no direct tail command in powershell.  In the unix environment you can tail a logfile, very helpful tool.

In powershell you can look at the last lines of a file by piping content to select so ...
get-content <file> | select-object -last 5

UPDATE - powershell 3.0 now includes a last switch for get-content
get-content <file> -last 5
To watch a log file ...
get-content <file> -wait
but not exactly the same functionality.  So a better way is to get the command from Microsoft.

Tail is included in the 2003 Resource Kit and works well in Server 2008 environment.
Download tail here:
http://www.microsoft.com/download/en/details.aspx?id=17657

Tuesday, January 24, 2012

Internet Explorer with Tabs

Here is some neat code to open IE using tabs

$ie = New-Object -ComObject InternetExplorer.Application
$ie.Navigate2("www.microsoft.com")
$ie.Navigate2("technet.microsoft.com",0x1000)
$ie.Navigate2("sharepoint.microsoft.com",0x1000)
$ie.Navigate2("office.microsoft.com",0x1000)
$ie.Navigate2("randelhall.blogspot.com",0x1000)
$ie.Visible = $true