This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.
-
Recent Posts
Archives
- May 2012 (26)
- April 2012 (21)
- March 2012 (65)
- February 2012 (94)
- January 2012 (54)
- December 2011 (17)
- November 2011 (11)
- October 2011 (15)
- September 2011 (39)
- August 2011 (57)
- July 2011 (58)
- June 2011 (65)
- May 2011 (53)
- April 2011 (25)
- March 2011 (12)
- February 2011 (18)
- January 2011 (27)
- December 2010 (2)
- November 2010 (14)
- October 2010 (13)
- September 2010 (1)
- June 2010 (11)
- May 2010 (31)
- April 2010 (29)
- March 2010 (19)
- February 2010 (31)
- January 2010 (28)
- December 2009 (11)
- November 2009 (40)
- October 2009 (2)
- September 2009 (8)
- August 2009 (21)
- July 2009 (21)
- June 2009 (27)
- May 2009 (32)
- April 2009 (24)
- March 2009 (41)
- February 2009 (42)
- January 2009 (34)
- December 2008 (30)
- November 2008 (40)
- October 2008 (42)
- September 2008 (52)
- August 2008 (40)
- July 2008 (35)
- June 2008 (38)
- May 2008 (29)
- April 2008 (32)
- March 2008 (59)
- February 2008 (43)
- January 2008 (47)
- December 2007 (30)
- November 2007 (62)
- October 2007 (54)
- September 2007 (43)
- August 2007 (44)
- July 2007 (55)
- June 2007 (57)
- May 2007 (55)
- April 2007 (43)
- March 2007 (61)
- February 2007 (50)
- January 2007 (21)
- December 2006 (7)
- November 2006 (16)
Categories
- .NET
- Active Directory
- Active Directory administration with PowerShell
- Architecture
- BITS
- Books
- COM
- Deep Dive
- DHCP
- DNS
- Events
- Exchange
- File system
- files
- Firewall
- General
- General IT matters
- IT Community
- IT Security
- Learning Powershell
- Math
- Microsoft
- Networking
- Office 2010
- Opinion
- Outlook
- Philosophy
- Powershell
- PowerShell and Active Directory
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- Powershell Basics
- PowerShell User Group
- PowerShell V2
- PowerShell V3
- PSAM
- Rant
- Science Fiction
- Script of the Week
- Scripting
- SQL Server
- Strings
- Technology
- Uncategorized
- Virtualisation
- Walking
- Windows 7
- Windows 8
- Windows 8 Server
- Windows Server 2008
- Windows Server 2008 R2
- WPF
- WSH
Meta
Twitter
- Preparing for the next UG meeting - PowerShell in Server 2012 - too much to choose from 1 week ago
- Reading about regular expressions in #PowerShell . My head is exploding 1 week ago
- Sat in San Diego airport waiting to fly home after an awesome deep dive 3 weeks ago
- #PowerShell Deep Dive is over. Another awesome event. It's the only place I learn something from every session 3 weeks ago
- #PowerShell v3 jobs give many more options - results available across sessions in many cases 3 weeks ago
Hi Richard,
i just stumbled abaout a tweet where you mentioned your PS Admin Modules
As Modules are my next thing i want to add to my PS learning curve i had a quick look what you published on Codeplex.
In your PAMSysInfo.psm1 i saw in your Get-Bus function some things which are quite new to me:
#================================ Your Function:
$bustype = DATA {
ConvertFrom-StringData -StringData @’
-1 = Undefined
0 = Internal
1 = ISA
2 = EISA
3 = MicroChannel
4 = TurboChannel
5 = PCI Bus
6 = VME Bus
7 = NuBus
8 = PCMCIA Bus
9 = C Bus
10 = MPI Bus
11 = MPSA Bus
12 = Internal Processor
13 = Internal Power Bus
14 = PNP ISA Bus
15 = PNP Bus
16 = Maximum Interface Type
‘@
}
function Get-Bus {
param(
[string]$computer=”.”
)
Get-WmiObject -class Win32_Bus -ComputerName $computer |
sort BusType, Busnum | select BusNum,
@{Name=”Bus type”; Expression={$bustype["$($_.BusType)"]}},
DeviceID, PNPDeviceID
}
#===============================
Som Questions about your code:
1)
$bustype = DATA {
-> Keyword DATA: what is this about? How do you call this Technique (So i can google for?) Are there more Keywords beside DATA?
2)
Think that you used:
$bustype = DATA { … ConvertFrom-StringData
and not just a Hashtable like:
$bustype = @{
-1 = “Undefined”
0 = “Internal”
1 = “ISA”
2 = “EISA
}
is , because you just did not like to write the ” ” or is ther another special reason why you did that? Think Both way’s produce a Hashtable as far as i saw it.
3)
And My last question is, why you placed the $bustype assignment outside your function and not inside?
Hope you find some minutes to answer my questions
Actually Question Nr 4. about Modules in General came into my mind while writing this Email
4)
You have Several Modules PAMSysInfo, PAMShares, …. I all would place in my modules Folder and then load with Import-Module..
I think i will also split up my scripts to multiple Modules.
What i like to do finally if possible is Following:
Having a Folder WindowsPowershell\Modules\PAM , and there are my “Sub”ModulesFolder WindowsPowershell\Modules\PAM\PAMSysInfo, WindowsPowershell\Modules\PAM\PAMShares, …
In the PAM folder itself i have a Preference File where i set the individual Submodules to load or not e.g.
ModulesToImport = @{
PAMSysInfo = $true
PAMShares = $true
PAMbla = $false
}
So with a “Import-Module PAM” , all specified SubModules would be loaded. (Like said before, if this is Possible at all
)
Maybe you like the idea as well for your PAM Modules.. I Think PSCX uses such a technique but i had just a very quick look to PSCX Structure..
Thanks for you PS Community work! Really enjoy your blog, SG2011, Tweets, …
Regards from Munich, Germany
Thomas
luesec@googlemail.com
I have tried to use you code
$acmsk = DATA {
ConvertFrom-StringData -StringData @’
1 = Read/List
2 = Write/Create File
4 = Append/Create Subdirectory
8 = Read extended attributes.
16 = Write extended attributes.
32 = Execute file/Traverse directory
64 = Delete directory
128 = Read file attributes.
256 = Change file attributes.
65536 = Delete
131072 = Read access to the security descriptor and owner.
262144 = Write access to the discretionary access control list (DACL).
524288 = Assigns the write owner.
1048576 = Synchronizes access, allows a process to wait for an object to enter the signaled state.
‘@
}
$flags = @(1,2,4,8,16,32,64,128,256,65536,131072,262144,524288,1048576)
$share = Get-WmiObject -Class Win32_Share -computername ‘fwcsqlbk01vp’
$mast = Invoke-WmiMethod -InputObject $share -Name GetAccessMask
foreach ($flag in $flags){
if ($mask.ReturnValue -band $flag) {
Write-Host $acmsk["$($flag)"]
}
}
but I get the following error message
Invoke-WmiMethod : Cannot convert ‘System.Object[]‘ to the type ‘System.Management.ManagementObject’ required by parameter ‘InputObject’. Specified method is not supported
.
At H:\powershell\Untitled3.ps1:23 char:38
+ $mast = Invoke-WmiMethod -InputObject <<<< $share -Name GetAccessMask
+ CategoryInfo : InvalidArgument: (:) [Invoke-WmiMethod], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.InvokeWmiMethod
I can't figure out why this does not work.
Not sure where this code came from as I can’t find the original post.
The orginal code was this
$acmsk = DATA {
ConvertFrom-StringData -StringData @’
1 = Read/List
2 = Write/Create File
4 = Append/Create Subdirectory
8 = Read extended attributes.
16 = Write extended attributes.
32 = Execute file/Traverse directory
64 = Delete directory
128 = Read file attributes.
256 = Change file attributes.
65536 = Delete
131072 = Read access to the security descriptor and owner.
262144 = Write access to the discretionary access control list (DACL).
524288 = Assigns the write owner.
1048576 = Synchronizes access, allows a process to wait for an object to enter the signaled state.
‘@
}
$flags = @(1,2,4,8,16,32,64,128,256,65536,131072,262144,524288,1048576)
$share = Get-WmiObject -Class Win32_Share -Filter “Name=’Test’”
$mask = Invoke-WmiMethod -InputObject $share -Name GetAccessMask
foreach ($flag in $flags){
if ($mask.ReturnValue -band $flag) {
Write-Host $acmsk["$($flag)"]
}
}
By leaving out the filter you get all shares returned which means that the Invoke-WmiMethod fails because you are passing it an array of share objects. If you want all shares then change the code to this
$computer = “$env:COMPUTERNAME”
$acmsk = DATA {
ConvertFrom-StringData -StringData @’
1 = Read/List
2 = Write/Create File
4 = Append/Create Subdirectory
8 = Read extended attributes.
16 = Write extended attributes.
32 = Execute file/Traverse directory
64 = Delete directory
128 = Read file attributes.
256 = Change file attributes.
65536 = Delete
131072 = Read access to the security descriptor and owner.
262144 = Write access to the discretionary access control list (DACL).
524288 = Assigns the write owner.
1048576 = Synchronizes access, allows a process to wait for an object to enter the signaled state.
‘@
}
$flags = @(1,2,4,8,16,32,64,128,256,65536,131072,262144,524288,1048576)
Get-WmiObject -Class Win32_Share -ComputerName $computer |
foreach {
“`n $($_.Name)”
$mask = Invoke-WmiMethod -InputObject $_ -Name GetAccessMask
foreach ($flag in $flags){
if ($mask.ReturnValue -band $flag) {
Write-Host $acmsk["$($flag)"]
}
}
}
Hi Richard,
Since you have been doing a series of articles around AD Commands, I’d thought I’d pose a question to you. I found the following code on the Tech Net site for Determining a users last logon time: http://technet.microsoft.com/en-us/library/dd378867(WS.10).aspx
Import-Module ActiveDirectory
function Get-ADUserLastLogon([string]$userName)
{
$dcs = Get-ADDomainController -Filter {Name -like “*”}
$time = 0
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$user = Get-ADUser $userName | Get-ADObject -Properties lastLogon
if($user.LastLogon -gt $time)
{
$time = $user.LastLogon
}
}
$dt = [DateTime]::FromFileTime($time)
Write-Host $username “last logged on at:” $dt }
Get-ADUserLastLogon -UserName SaraDavis
While the script will come back with the date and the time like this:
SaraDavis last logged on at: 1/15/2012 7:28:56 PM
I’d like to get the DC name in there as well. My feable attampts keep just returning the first DC name after the correct time.
This would be helpful in other scripts that I have for searching for inactive users or computers, to make sure that the account is truely aged out, and just not reporting that from the DC the script runs against.
Thanks in advance, and thanks for actively posting on your blog, it’s awesome!!
Jerame
Hi Jerame
The code you copied from TechNet is incorrect.
I’ve posted a function here
http://richardspowershellblog.wordpress.com/2012/01/18/last-logon-time/
that will do the job
Thank you very much!!!
You are very welcome. thanks for the feedback on the blog
Hi Richard,
We are currently in the process of readdressing our network to a 10.x.x.x network. I created a script to export my printer ports, and then would change them to the new IP’s, and I have modified script CreatePrinters.ps1 (http://poshcode.org/1462) to create my ports. This has worked well for many sites. I’m now starting to hit some of my larger sites, and want to script the change of the printers to use the new ports (which are already created) to speed up our migration time.
This works for one printer:
$Print = Get-WMIObject Win32_Printer -Filter “Name=’MyPrinterName’”
$Print.Port = “10.x.x.x”
$Print.Put()
So now I’m trying to pull the Printer Name and Port from a csv file to run through all of them. I’m hitting a snag passing the printer name into the WMI object:
function ChangePrinterPort {
$Server = $args[0]
$PrintName = $args[1]
$Print.Printer = Get-WMIObject Win32_Printer -Filter “Name=’$PrintName’”
$Print.Port = $args[2]
$Print.Put()
}
$Printers = Import-Csv c:\Scripts\Printers\NewPrintPorts.csv
foreach ($Printer in $Printers) {
ChangePrinterPort $Printer.Printserver $Printer.PrinterName $Printer.PortName
}
Would you have a suggestion as to how to correct this? I didn’t see this in Chapter 10 of PowerShell and WMI
Thanks,
Jerame