Monthly Archive

Categories

Monthly Archives: March 2010

PowerShell pack: ISEpack commands

The ISEpack adds a number of commands to the Add-ons menu in ISE.  The list of additional commands includes

Add-ForeachStatement                                 Add-IfStatement
Add-InlineHelp                                       Add-IseMenu
Add-Parameter                                        Add-PInvoke
Add-SwitchStatement                                  Close-AllOpenedFiles
Colorize                                             ConvertTo-ShortcutKeyTable
Export-FormatView                                    Get-CurrentFunction
Get-CurrentOpenedFileToken                           Get-CurrentToken
Get-FunctionFromFile                                 Get-ShellVerb
Get-TokenFromFile                                    Invoke-Line
Move-ToLastGroup                                     Move-ToLastPowerShellTab
Move-ToNextGroup                                     Move-ToNextPowerShellTab
New-IseScript                                        New-ScriptModuleFromCurrentLocation
Push-CurrentFileLocation                             Push-Module
Save-IseFileWithAutoName                             Select-AllInFile
Select-CurrentText                                   Select-CurrentTextAsCommand
Select-CurrentTextAsType                             Select-CurrentTextAsVariable
Show-HelpForCurrentSelection                         Show-Member
Show-SyntaxForCurrentCommand                         Show-TypeConstructor
Show-TypeConstructorForCurrentType                   Split-IseFile
Switch-CommentOrText                                 Switch-SelectedCommentOrText

how did I generate this list

Get-ChildItem -Path (Join-Path -Path ($env:PSModulePath -split ";")[1]   -ChildPath ISEPack) -Filter *.ps1 | format-wide basename -Column 2

all built up at the command line – gotta love it when a script comes together

if you are a regular ISE user these commands could be a big help

Technorati Tags: PowerShell,ISE

PowerShell pack: ISEpack

The ISEpack adds a number of commands to the Add-ons menu in ISE.  The list of additional commands includes

Add-ForeachStatement                    Add-IfStatement                         Add-InlineHelp
Add-IseMenu                             Add-Parameter                           Add-PInvoke
Add-SwitchStatement                     Close-AllOpenedFiles                    Colorize
ConvertTo-ShortcutKeyTable              Export-FormatView                       Get-CurrentFunction
Get-CurrentOpenedFileToken              Get-CurrentToken                        Get-FunctionFromFile
Get-ShellVerb                           Get-TokenFromFile                       Invoke-Line
Move-ToLastGroup                        Move-ToLastPowerShellTab                Move-ToNextGroup
Move-ToNextPowerShellTab                New-IseScript                           New-ScriptModuleFromCurrentLocation
Push-CurrentFileLocation                Push-Module                             Save-IseFileWithAutoName
Select-AllInFile                        Select-CurrentText                      Select-CurrentTextAsCommand
Select-CurrentTextAsType                Select-CurrentTextAsVariable            Show-HelpForCurrentSelection
Show-Member                             Show-SyntaxForCurrentCommand            Show-TypeConstructor
Show-TypeConstructorForCurrentType      Split-IseFile                           Switch-CommentOrText
Switch-SelectedCommentOrText

how did I generate this list

Get-ChildItem -Path (Join-Path -Path ($env:PSModulePath -split ";")[1]   -ChildPath ISEPack) -Filter *.ps1 | format-wide basename -Column 3

all built up at the command line – gotta love it when a script comes together

if you are a regular ISE user these commands could be a big help

Technorati Tags: PowerShell,ISE

Access: Remove Stored Procedure

We have seen how to create and use a stored procedure – but as part of our usage patterns we need to be able to delete stored procedures as well.

001
002
003
004
005
006
007
008
009
010
011
012
013
function Remove-AccessStoredProcedure {
# .ExternalHelp Maml-AccessFunctions.XML
[CmdletBinding()]
param (
    [System.Data.OleDb.OleDbConnection]$connection,
    [string]$name
)
    $sql = "DROP PROCEDURE $name"
    Write-Debug $sql
   
    $cmd = New-Object System.Data.OleDb.OleDbCommand($sql, $connection)
    $cmd.ExecuteNonQuery()   
}

 

Simple function to pass the name of the procedure and call a DROP ROCEDURE statement.

 

Advance Warning

The next User group meeting will be a Live Meeting on 20 April 2010.

The subject is Modules in PowerShell v2 – details to follow

Technorati Tags: PowerShell,user group

50% discount extended

 

Manning www.manning.com have extended their 50% discount across the weekend as follows:

(Today) Friday March 5, 2010: 50% off all MEAPs. Use code dotd0305tw

Saturday March 6, 2010: 50% off all print books. Use code dotd0306tw

Sunday March 7, 2010: 50% off all ebooks. Use code dotd0307tw

Looks like its a good time to buy a book

Elevating now

Running Windows 7 with UAC turned on I get an error when trying to access the security log

PS> Get-EventLog -LogName Security
Get-EventLog : Requested registry access is not allowed.
At line:1 char:13
+ Get-EventLog <<<<  -LogName Security
    + CategoryInfo          : NotSpecified: (:) [Get-EventLog], SecurityException
    + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetEventLogCommand

 

OK – not a surprise because I was expecting it. 

Remember I mentioned the psusertools module in the PowerShell pack had a command to test if you are running with elevated privileges

PS> Test-IsAdministrator
False

 

Now we know how to test we can load the PowerShell Comunity Extensions v2 beta and find a function called Invoke-Elevated.  Put the two together and we get

if (!(Test-IsAdministrator)){Invoke-Elevated {Get-EventLog -LogName Security -Newest 5}}

The UAC prompt will appear – click yes – and another PowerShell window will appear with your answers.

We could extend this idea to put the invoke-elevated so all we did was pass in a string with the command.   Consider that your homework for tonight.  🙂

Technorati Tags: PowerShell,Resource kit,PSCX

Manning Special Offer

Manning – the publishers of my book – have a big promotion on Friday 5 March.

Go to www.manning.com on Friday and get 50% off any MEAP.

 

MEAP is Manning Early Access Program – get early access to the book (raw manuscript) and get the full book delivered when its published.

Good time to stock on the PowerShell book you’ve always wanted (especially as it will be out of MEAP soon)  🙂

Technorati Tags: Books,offer

PowerShell pack: PSuserTools

The PSusertools module contains 4 functions:

Get-CurrentUser
Get-Everyone
Start-ProcessAsAdministrator
Test-IsAdministrator

 

get-currentuser uses System.Security.Principal.WindowsIdentitiy to identify the current user. One oddity is that the group information returns the SID of the group rather than the name.  We need a SID to name translator.

Test-IsAdministrator returns true if the user is an administrator. In PowerShell this equates to running the shell with elevated privileges – good test to put in your scripts to make sure that you have the permissions to do what you need

UG meeting – recording

Thank you to the people who attended tonight’s Live Meeting and especially for the feedback.

The slides and demo script from tonight’s PowerShell UG meeting can be found here

http://cid-43cfa46a74cf3e96.skydrive.live.com/browse.aspx/PowerShell%20User%20Group

in the March 2010 folder.

 

The recording is available from

Richard Siddaway has invited you to view a Microsoft Office Live Meeting recording.
View Recording
Recording Details
    Subject: PowerShell, Windows 7 and the Resource Kit
    Recording URL: https://www.livemeeting.com/cc/usergroups/view
    Recording ID: C6F282
    Attendee Key: tj|G4%&`8

 

Enjoy

 

Technorati Tags: Powershell,User Group

Book review: Practical Virtualization Solutions

I’ve just published a review of this book

http://itknowledgeexchange.techtarget.com/powershell/practical-virtualization-solutions/

Its a good general introduction to the whole virtualisation story with some interesting points to make.

Technorati Tags: Books,Virtualisation