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
- January 2020 (4)
- December 2019 (12)
- November 2019 (9)
- October 2019 (12)
- September 2019 (7)
- August 2019 (12)
- July 2019 (12)
- June 2019 (12)
- May 2019 (12)
- April 2019 (12)
- March 2019 (12)
- February 2019 (12)
- January 2019 (12)
- December 2018 (12)
- November 2018 (12)
- October 2018 (15)
- September 2018 (12)
- August 2018 (15)
- July 2018 (11)
- June 2018 (12)
- May 2018 (12)
- April 2018 (12)
- March 2018 (12)
- February 2018 (12)
- January 2018 (12)
- December 2017 (12)
- November 2017 (14)
- October 2017 (12)
- September 2017 (12)
- August 2017 (12)
- July 2017 (12)
- June 2017 (12)
- May 2017 (12)
- April 2017 (12)
- March 2017 (12)
- February 2017 (6)
- January 2017 (14)
- December 2016 (12)
- November 2016 (12)
- October 2016 (12)
- September 2016 (15)
- August 2016 (12)
- July 2016 (17)
- June 2016 (15)
- May 2016 (12)
- April 2016 (14)
- March 2016 (12)
- February 2016 (14)
- January 2016 (17)
- December 2015 (14)
- November 2015 (12)
- October 2015 (20)
- September 2015 (12)
- August 2015 (16)
- July 2015 (22)
- June 2015 (12)
- May 2015 (12)
- April 2015 (12)
- February 2015 (15)
- January 2015 (19)
- December 2014 (14)
- November 2014 (12)
- October 2014 (23)
- September 2014 (20)
- August 2014 (20)
- July 2014 (20)
- June 2014 (24)
- May 2014 (22)
- April 2014 (20)
- March 2014 (21)
- February 2014 (20)
- January 2014 (20)
- December 2013 (20)
- November 2013 (21)
- October 2013 (20)
- September 2013 (38)
- August 2013 (24)
- July 2013 (20)
- June 2013 (21)
- May 2013 (21)
- April 2013 (22)
- March 2013 (7)
- February 2013 (12)
- January 2013 (24)
- December 2012 (19)
- November 2012 (15)
- October 2012 (8)
- September 2012 (19)
- August 2012 (7)
- July 2012 (5)
- June 2012 (19)
- May 2012 (30)
- 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
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File system
- files
- Firewall
- General
- General IT matters
- Hyper-V
- IIS
- IT Community
- IT Security
- Learning Powershell
- Linux
- Math
- Microsoft
- Modules
- Nano server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- Powershell
- PowerShell 7
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- Powershell Basics
- PowerShell User Group
- PowerShell V2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- powershell.org
- PowerShellGet
- PSAM
- Rant
- Registry
- Science Fiction
- Script of the Week
- Scripting
- Scripting Games
- Scritping Games 2014
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualisation
- Walking
- Windows 10
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows Server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSH
- WSUS
Meta
Twitter
Tweets by RSiddaway
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
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
Hi Richard,
Just wanted to say thanks for sharing your knowledge. I like your books Powershell in Practice and Powershell and WMI.
Soyka
Hi Richard
I am trying to figure out how to use Power Shell to update the Cost Center field for a user?
Ideally, should be able to say update cost centre 252525 for all 10 users: user1, user2, user3 etc.
Any help would be appreciated š
Thanks
I can’t see a Cost Center field in Active Directory? Is this an application data store you’re trying to update?
Hello Richard,
IĀ“m very interested in your book “Powershell and wmi” but I canĀ“t find it in Spanish. I guess no edition in spanish… Could you confirm me?
Thanks
Sorry – only available in English