Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts
-
Chris
-
Chris
Happy Thanksgiving!
Its that time of the year again . Time to reflect and give thanks . I hope everyone has a great ,happy and safe thanksgiving .
Chris
-
Chris
Studying for my VCP4 exam
-
Chris
Good to have websites!
I was listening to the latest powerscripting podcast here . They had Jeff Atwood the mastermind behind stackoverflow.com and Serverfault.com. Very nice sites if your searching for technical info or have a question . Great sites to post your question and have high visibility.
Chris
-
Chris
Creating a Unix like tail with Get-content
Wow I haven’t written a blog in a long time ….
Hi everyone hope you’re doing well . A very short blog about the Get-Content cmdlet . Get-content has a very nice parameter called -wait . I have been using this for example to find users that lock out there AD accounts frequently and don’t know why they are getting locked out . The netlogon.log captures this info (If your DC is set up for debugging this info ) so it makes it easy to catch these lockouts . What -wait does is monitor the log file or text file so that anything added to it it will display . If you pipe that to a regex statement you can narrow down your search and pinpoint what you’re looking for … So for example if Bob.Roberts is locking out is account and doesn’t know why you can do this :
gc \\DcName\c$\Windows\debug\netlogon.log -wait | ? {$_ -match "Bob.Roberts"}
So now any entries that contain Bob.Roberts will be displayed and if not it will just sit there and wait and monitor the log . A great way to just put the powershell window to the side and do other things will waiting for results
.Hope you like this tip
Chris
-
Chris
Using Powershell and Subinacl.exe to Permission Printers
Hi Folks ,
I was given a task at work to add a global group to 100’s of printer queue’s . I knew I wanted to use powershell to do this task but was unsure how to permission printers . I came across this utility (Subinacl.exe) that I knew about but didn’t think it permissioned printer queue’s . It took just one line to accomplish this task . In minutes I permssioned 100’s of queue’s and my manager was very happy with the result .
So here is the one line :
gwmi -class Win32_Printer -comp ServerName | % { $_.Name} | % { subinacl.exe /printer \\ServerName\$_ /grant=DomainName\GroupName=F}
F means Full Control…You can also use M for Manage Documents or P for Print .
This is a good example also of Powershell’s ability to work with command line utilities .
I thought this was cool and a super time saver . If you have any questions please comment below and I will respond pronto
Thanks
Chris
Chris
Introduction to Powershell Modules w/ Advanced Functions
If you been using powershell you heard these terms Modules and Advanced functions . What are they ? Why are they important ? Why would I want to use them ? Do I need to use them ? As you can see allot of questions.
Modules have replaced Pssnapins in V1 which was compiled code usually C# that gave powershell more functionality .This was a way to add more cmdlets . An example of this is System Center Operations Manager (SCOM) pssnapin . When you install the console along with powershell you get the pssnapin for SCOM which gives you a bunch of cmdlets.
Now with powershell V2 we have what are called modules . These modules can be any function that you have written in powershell. That is the beauty of modules they are basically scripted cmdlets that you create . Now anyone can create them. You don’t need to fire up a compiler and bang out C# code to get the extra functionality you need .So if you take any function your written in Powershell and changed the extension to .psm1 then you have a module .
They are important because they can save you time by re-using specific scripts to do repetitive tasks . When you import your module its loaded into your powershell session sort of like dot sourcing your script. First you need to know where are the modules located . To find out where your modules folder is located enter this command in your powershell command prompt .
dir env:psmodulepath
psmodulepath is an environment variable. Please see this blog for more information http://tfl09.blogspot.com/2009/01/modules-in-powershell-v2.html
You should see something like this …
Name Value
—- —–
PSMODULEPATH C:\Documents and Settings\username\My Documents\WindowsPowerShell\Modules;
There is also a location in your %windir%\system32\Windowspowershell\modules directory.
You probably be using the user specific directory.
So now that you know where the modules are here is an example of a module I created :
I will call it Get-OSInFo.psm1
Here is what it looks like using Advanced Functions:
Function Get-OsInfo {
<#
.Synopsis
Gets basic Os information Using WMI OperatingSystem Class.
.Description
Gets basic Os information Using WMI OperatingSystem Class.
.Parameter ComputerName
Name of the of the Computer you want info on.
.Example
PS> get-OsInfo -computer serverA
.Link
about_functions
about_functions_advanced
about_functions_advanced_methods
about_functions_advanced_parameters
.Notes
NAME: Get-OsInfo
AUTHOR: Name
LASTEDIT: 05/26/2009
#>
param(
[Parameter(Mandatory=$true)]
[string]$computerName = “localhost”
)
gwmi -class Win32_OperatingSystem -Computer $computername
}
Advanced Functions is new for V2 . What makes them so nice to use is the built in help . Notice the syntax. Also notice the parameter section . This is a new way to specify parameters. Note that I have a parameter called Computername default to local host and it is mandatory. You can go crazy with parameters but this is just an intro so more to come in the future . The last portion is the standard WMI call to OperatingSystem .
Now lets put this all together
Place this file in your modules folder but create a folder called get-osinfo and put the psm1 file in there. I use the same name as the script for the folder . (I am not sure if that is necessary but it is best practices ).
Now that we have the module file in the correct place open up your powershell command prompt.
We are going to import the module …
import-module get-osinfo.psm1
Like I said before this is like dot sourcing a script (. .\scriptname.ps1). Now that we imported it lets check it out ..
Before we do I wanted to point out that you can have an umlimited number of functions in this psm1 file . So what if you got a bunch of functions for a third party how would you know what functions are in this file ?
A somewhat easy way would be to use this command (This is after you imported the module )
get-command -commandtype Function
CommandType Name Definition
———– —- ———-
Function A: Set-Location A:
Function B: Set-Location B:
Function C: Set-Location C:
Function cd.. Set-Location ..
Function cd\ Set-Location \
Function Clear-Host $space = New-Object System.Management.Au
Function D: Set-Location D:
Function Disable-PSRemoting …
Function E: Set-Location E:
Function Enable-PSRemoting …
Function F: Set-Location F:
Function G: Set-Location G:
Function Get-OsInfo …
Function H: Set-Location H:
You can see we see our get-Osinfo function listed .
Now that we know that is the function we need …we need to know how to run it (Remember the built in help for the function we created ?? )
Well lets get help the same way you would get help on any of other function or cmdlet.
help get-osinfo -det
NAME
Get-OsInfo
SYNOPSIS
Gets basic Os information Using WMI OperatingSystem Class.
SYNTAX
Get-OsInfo [-computerName] [<String>] [-Verbose] [-Debug] [-ErrorAction [<ActionPreference>]] [-WarningAction [
nce>]] [-ErrorVariable [<String>]] [-WarningVariable [<String>]] [-OutVariable [<String>]] [-OutBuffer [<Int32>
ameters>]
DETAILED DESCRIPTION
Gets basic Os information Using WMI OperatingSystem Class.
PARAMETERS
-computerName
Name of the of the Computer you want info on.
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug,
-ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
-OutBuffer and -OutVariable. For more information, type,
“get-help about_commonparameters”.
————————– EXAMPLE 1 ————————–
PS> get-OsInfo -computer serverA
REMARKS
To see the examples, type: “get-help Get-OsInfo -examples”.
For more information, type: “get-help Get-OsInfo -detailed”.
For technical information, type: “get-help Get-OsInfo -full”.
Isn’t that great !!!
Lets run it …
Get-Osinfo -computername ServerA
(Notice how the parameter variable computername is used …)
You can even pipe this to the select cmdlet like so
Get-Osinfo -computername ServerA | select Name,Organization,BuildNumber
To sum up … Modules helps you create specific functions to help you with different tasks . Microsoft made these scriptable so that any one can create them . By using advanced functions you get the built in help and special parameter settings for your functions .
It doesn’t stop here … there are also module manifests . Also you can enable different functions in your modules for lets say security reasons . This was just an introduction.
I hope you enjoyed reading this blog
Chris
Chris
Powershell Using $OFS
Hello ,
$OFS which is a special variable in powershell . OFS stands for Output field separator . You would use this to separate objects in your array for example :
PS H:\> $numbers = 1,2,3,4,5
PS H:\> $numbers
1
2
3
4
5
What if you wanted to separate these let say with a semi colon . You can use the $OFS variable..
PS H:\> $ofs = “;” ;[string]$numbers
1;2;3;4;5
This could be useful lets say if your getting users out of AD to setup an e-mail in outlook .
Not to bad …
For More info :
http://blogs.msdn.com/powershell/archive/2006/07/15/What-is-OFS.aspx
Have Fun !
Chris
Chris
The future of Microsoft Flight Simulator
Everyone has heard the news about the layoffs happening at Microsoft and I even seen news relating to laying off the Aces division which includes the Flight Simulator program. If this is true it is truly sad. Its one of the oldest products of Microsoft since 1982 and even older then that starting with Sublogic . I hope this is not the end.
What do you have to say about it ?
Here is a link that has some information about this . Click-here.
Thanks
Chris
-
Kwadir
-
Jim
I feel that even if Microsoft ends this great program,The Exprogramers and 3rd party software developers will continue with this but maybe not with Microsoft over the name!Microsoft made, WAY to much money off this frachise that It is impossible to think they would end it.
RSS - Posts
Just dropping by.Btw, you website have great content!
______________________________
Unlimited Public Records Searches!