taking a power shell cmdlet and changing it into script by importing from file and applying to each name

In my other post I was helped out on using the command pwdlastset

https://social.technet.microsoft.com/Forums/windowsserver/en-US/ac4d4fb8-0780-4f0d-9e0e-9fec2ff87fbf/using-the-pwdlastset-attribute?forum=winserverpowershell

I decided I would then try to build on that. 

1. create a CSV file and import

2. take each value as it comes in and change it.

I came up with the following but something odd is happening:

its asking for an identity. (I got the idea from another script that I had which creates accounts, see below) any idea what I is wrong in my thinking here?

--------------------------

PS C:\Windows\system32> # Import from CSV
Import-csv c:\scripts\Book1.csv | Foreach-Object { Set-ADUser -Replace @{pwdLastSet=0}}
cmdlet Set-ADUser at command pipeline position 1
Supply values for the following parameters:
Identity:

--------------------------

I got the idea from another script that I had which creates user accounts.  it was similar type of item using the new_ADUser instead of the set-ADuser but the important thing I wanted was to create a for loop but was not sure how in power shell and this seemed to use that.

-----------------------------

# Import from CSV
Import-csv c:\scripts\PSBulkAccountCreation.csv | ForEach-Object {
              
                New-ADUser -Path "OU=users,DC=somename" -Name $_.Name -SamAccountName $_.SamAccountName -Description $_.Description -emailaddress $_.emailaddress -AccountPassword (ConvertTo-Securestring -AsplainText $_.AccountPassword -Force) -Enable $true -ChangePasswordatlogon 0 -PasswordNeverExpires:$true

}

}

-----------------------------

September 10th, 2015 5:02pm

I found this which may be a clue I am looking into it now:

" Script block. You can use a script block to specify the operation. Within the script
    block, use the $_ variable to represent the current object. The script block is the
    value of the Process parameter. The script block can contain any Windows PowerShell
    script."

wondering if I somehow need to create a variable to use. maybe $users

------------------------------------------------------------

PS C:\Windows\system32> get-help ForEach

NAME
    ForEach-Object
   
SYNOPSIS
    Performs an operation against each item in a collection of input objects.
   
   
SYNTAX
    ForEach-Object [-Process] <ScriptBlock[]> [-Begin <ScriptBlock>] [-End <ScriptBlock>]
    [-InputObject <PSObject>] [-RemainingScripts <ScriptBlock[]>] [-Confirm] [-WhatIf]
    [<CommonParameters>]
   
    ForEach-Object [-MemberName] <String> [-ArgumentList <Object[]>] [-InputObject
    <PSObject>] [-Confirm] [-WhatIf] [<CommonParameters>]
   
   
DESCRIPTION
    The ForEach-Object cmdlet performs an operation on each item in a collection of input
    objects. The input objects can be piped to the cmdlet or specified by using the
    InputObject parameter.
   
    Beginning in Windows PowerShell 3.0, there are two different ways to construct a
    ForEach-Object command.
   
    Script block. You can use a script block to specify the operation. Within the script
    block, use the $_ variable to represent the current object. The script block is the
    value of the Process parameter. The script block can contain any Windows PowerShell
    script.
   
    For example, the following command gets the value of the ProcessName property of each
    process on the computer.
   
    Get-Process | ForEach-Object {$_.ProcessName}
   
    Operation statement. You can also write a operation statement, which is much more like
    natural language. You can use the operation statement to specify a property value or
    call a method. Operation statements were introduced in Windows PowerShell 3.0.
   
    For example, the following command also gets the value of the ProcessName property of
    each process on the computer.
   
    Get-Process | ForEach-Object ProcessName
   
    When using the script block format, in addition to using the script block that
    describes the operations that are performed on each input object, you can provide two
    additional script blocks. The Begin script block, which is the value of the Begin
    parameter, runs before the first input object is processed. The End script block,
    which is the value of the End parameter, runs after the last input object is processed.

RELATED LINKS
    Online Version: http://go.microsoft.com/fwlink/p/?linkid=289582

REMARKS
    To see the examples, type: "get-help ForEach-Object -examples".
    For more information, type: "get-help ForEach-Object -detailed".
    For technical information, type: "get-help ForEach-Object -full".
    For online help, type: "get-help ForEach-Object -online"


PS C:\Windows\system32>


Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 5:04pm

I tried to change it a bit but that seemed to give me a new error.  I am pretty sure It has something to do with  needing to go into a variable and then each variable be fed, but I may be trying to put simple understanding to something that has a bit more complexity to it than what I am thinking with just a basic import, loop and set statement.  =(

-------------------

PS C:\Windows\system32> Import-csv c:\scripts\Book1.csv | Foreach-Object { Set-ADUser -Replace $.Replace @{pwdLastSet=0}}

Set-ADUser : Cannot bind parameter 'Replace'. Cannot convert the "$.Replace" value of type
"System.String" to type "System.Collections.Hashtable".
At line:1 char:72
+ Import-csv c:\scripts\Book1.csv | Foreach-Object { Set-ADUser -Replace $.Replace ...
+                                                                        ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Man
   agement.Commands.SetADUser

-------------------

September 10th, 2015 5:12pm

I found the following article and I am working with it

http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/22/use-powershell-to-read-a-csv-file-and-create-active-directory-user-accounts.aspx

I am coming up with something new like the following below but I have not tested or refined it yet. Hoping I am getting on the right track I like how he lays it out more like regular programming code.

$UserList=Import-csv c:\scripts\Book1.csv
Foreach-Object ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}

==========edited======= nm it gave me error but it was finding names but trying to set one name = to the name after

------------------------------

$UserList=Import-csv c:\scripts\Book1.csv
Foreach-Object ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}

PS C:\Windows\system32> $UserList=Import-csv c:\scripts\Book1.csv
Foreach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}
Set-ADUser : Cannot bind parameter 'Identity'. Cannot convert value
"@{firstname.lastname1=firstname.lastname2}" to type "Microsoft.ActiveDirectory.Management.ADUser".
Error: "Cannot convert the "@{firstname.lastname1=firstname.lastname2}" value of type
"System.Management.Automation.PSCustomObject" to type
"Microsoft.ActiveDirectory.Management.ADUser"."
At line:2 char:45
+ Foreach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}
+                                             ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Man
   agement.Commands.SetADUser

-----------------------------------

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 5:26pm

Well it turned out that my CSV file repeated the names every third name because from my excel file when I copied I grabbed the first three boxes then dragged down and was not paying attention. So my file was screwed up with to start. I have since fixed that.

I am starting off very simple now I created the following code which works.  so I outputted like 50 names each on their own line.   So that looks like my forEach is working atleast in doing that I will try to work from here into using the command I want.

---------------

$UserList=Import-csv c:\scripts\Book1.csv
ForEach ($Person in $UserList) { Write-Output $Person}

---------------

September 10th, 2015 5:58pm

I don't seem to be able to figure this out. I tried the command again with a fixed csv file.

Unlike the print command that outputs each item in order this one gives me an error and it tries to set the firstname in the list = to the second name in the list.

I have an idea of whats going on here "I think", but not positive.  I know with Hash Table that you have two values the first is the key and the second is the value.

could it be trying to set john.doe as the key and the value jane.smith?    how its showing the error looks to me like its all inside the @{} which is the hash table.  yet I think I need the hash table to use the pwdlastset attribute.... This is very frustrating.

------------------

$UserList=Import-csv c:\scripts\Book1.csv
ForEach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdlastSet=0}}
Set-ADUser : Cannot bind parameter 'Identity'. Cannot convert value
"@{john.doe=jane.smith}" to type "Microsoft.ActiveDirectory.Management.ADUser".
Error: "Cannot convert the "@{john.doe=jane.smith}" value of type
"System.Management.Automation.PSCustomObject" to type
"Microsoft.ActiveDirectory.Management.ADUser"."
At line:2 char:45
+ ForEach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdlastSet=0}}
+                                             ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Man
   agement.Commands.SetADUser

-----------------

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 6:08pm

Import-Csv -Path C:\users\adm_hlabuser1\desktop\Users.csv | select -ExpandProperty identity | Set-Aduser -replace @{pwdlastset=0}

I have used my column header in the CSV file as identity & the object values reflect the samaccountname

The key point here is how pipeline works

The parameter IDENTITY accepts pipeline input ByValue, which in powershell world says, I will go first, and if I do not work then go by property name.

You need to EXPAND the property name here and take out the string output 

Check out the below detailed example i gave for you 

As with the example I am providing, with input from one of my lab environments.
I have two users whose samid's have been noted in the file. 
User1 = std_hlabuser1 
PwdLastSet = (Before I executed the above command)

PwdLastSet = (After I executed the above command)

User2 = std_hlabuser2
PwdLastSet = (Before I executed the above command)

PwdLastSet = (After I executed the above command)

September 10th, 2015 6:34pm

You can spend the rest of your life guessing and asking incremental questions or you can sit dowsn and learn PowerShell. Everryoneof your problems are due to not having learned how PowerShell works.

PowerShell is an object system (OOP).  It cannot be easily guessed at until you learn how it works then you can use methhods to discover how things are built like "Get-Member".

You also fail to read all of the help for the CmdLet you are using.

"Identity" is required.  It cannot be guessed from a CSV.  You must always supply an Identity or a user object which has numerous forms of identity.

Set-Aduser -Identity <samaccountname> -Replace @{pwdLastSet=0}}

With that and the learning pages here you should be able to figure out how this works.

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 6:34pm

OMG I get what your saying now so deleting all that stuff I wrote.  My CSV was messed up and why I am getting the double name crap, or atleast I am pretty sure that's what you mean.

I have used CSV in the past just been awhile let me go back to messing with this. 


September 10th, 2015 7:14pm

I am thinking you might mean create a column header named samaccountname and then under that header have my CSV name list. which I think I did something similar in the past. that would go along with what Soumyajyoti stated as well.  I just didn't catch it at first as my brain is jumbled let me go play with my CSV sheet and add a column header like I have in the past. 

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 7:21pm

Ok below I posted the final product:

I just forgot about the CSV item because I don't work with the stuff until I work with it.  I have been busy with my bachelor degree.  I am finishing up my last class which is a basic programming class in python.  However, I am excited about applying programming concepts to my power shell which is why I was excited about the for each loop.

I did not use it because the select presented above was already supplied but I am going to see if I can get the for each loop to work with what I was reminded of with the CSV files. 

I will start learning powershell formally by the way its just hard to work all day then go home study all night and to complete side projects as well.  Power shell is a passion of mine its just not something I have had time to stay steady with until I finish my bachelor.  I take my python test sunday then all I have left is my technical writing class and my capstone and I will have finished my first bachelor.  

then I will have a lot more time in the evenings to pursue current interest!

had to run three commands but when you think of how much time it saves (hours!), and that you can do this in like 10 seconds for thousands of users I think its pretty useful

  1. First run:
    • Import-csv c:\scripts\Book1.csv | select -ExpandProperty samaccountname | Set-Aduser -replace @{pwdlastset=-0}

  1. Then run:
    • Import-csv c:\scripts\Book1.csv | select -ExpandProperty samaccountname | Set-Aduser -replace @{pwdlastset=-1}

  1. And lastly run:
    • Import-csv c:\scripts\Book1.csv | select -ExpandProperty samaccountname | Set-Aduser -PasswordNeverExpires $false

September 10th, 2015 7:52pm

Yes but you still do not understand the difference between a CSV and  text file and how the pipeline.

Your file has a list of user names...

Without the added header:

Get-Content <yourfile> | Set-Aduser -replace @{pwdlastset=-0}

That is what Soumyajyoti.Biswas was trying to show you but both he and you assumed you knew what a CSV file was.

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 8:09pm

I found this which may be a clue I am looking into it now:

" Script block. You can use a script block to specify the operation. Within the script
    block, use the $_ variable to represent the current object. The script block is the
    value of the Process parameter. The script block can contain any Windows PowerShell
    script."

wondering if I somehow need to create a variable to use. maybe $users

------------------------------------------------------------

PS C:\Windows\system32> get-help ForEach

NAME
    ForEach-Object
   
SYNOPSIS
    Performs an operation against each item in a collection of input objects.
   
   
SYNTAX
    ForEach-Object [-Process] <ScriptBlock[]> [-Begin <ScriptBlock>] [-End <ScriptBlock>]
    [-InputObject <PSObject>] [-RemainingScripts <ScriptBlock[]>] [-Confirm] [-WhatIf]
    [<CommonParameters>]
   
    ForEach-Object [-MemberName] <String> [-ArgumentList <Object[]>] [-InputObject
    <PSObject>] [-Confirm] [-WhatIf] [<CommonParameters>]
   
   
DESCRIPTION
    The ForEach-Object cmdlet performs an operation on each item in a collection of input
    objects. The input objects can be piped to the cmdlet or specified by using the
    InputObject parameter.
   
    Beginning in Windows PowerShell 3.0, there are two different ways to construct a
    ForEach-Object command.
   
    Script block. You can use a script block to specify the operation. Within the script
    block, use the $_ variable to represent the current object. The script block is the
    value of the Process parameter. The script block can contain any Windows PowerShell
    script.
   
    For example, the following command gets the value of the ProcessName property of each
    process on the computer.
   
    Get-Process | ForEach-Object {$_.ProcessName}
   
    Operation statement. You can also write a operation statement, which is much more like
    natural language. You can use the operation statement to specify a property value or
    call a method. Operation statements were introduced in Windows PowerShell 3.0.
   
    For example, the following command also gets the value of the ProcessName property of
    each process on the computer.
   
    Get-Process | ForEach-Object ProcessName
   
    When using the script block format, in addition to using the script block that
    describes the operations that are performed on each input object, you can provide two
    additional script blocks. The Begin script block, which is the value of the Begin
    parameter, runs before the first input object is processed. The End script block,
    which is the value of the End parameter, runs after the last input object is processed.

RELATED LINKS
    Online Version: http://go.microsoft.com/fwlink/p/?linkid=289582

REMARKS
    To see the examples, type: "get-help ForEach-Object -examples".
    For more information, type: "get-help ForEach-Object -detailed".
    For technical information, type: "get-help ForEach-Object -full".
    For online help, type: "get-help ForEach-Object -online"


PS C:\Windows\system32>


  • Edited by wilder7bc Thursday, September 10, 2015 9:04 PM
September 10th, 2015 9:01pm

I found this which may be a clue I am looking into it now:

" Script block. You can use a script block to specify the operation. Within the script
    block, use the $_ variable to represent the current object. The script block is the
    value of the Process parameter. The script block can contain any Windows PowerShell
    script."

wondering if I somehow need to create a variable to use. maybe $users

------------------------------------------------------------

PS C:\Windows\system32> get-help ForEach

NAME
    ForEach-Object
   
SYNOPSIS
    Performs an operation against each item in a collection of input objects.
   
   
SYNTAX
    ForEach-Object [-Process] <ScriptBlock[]> [-Begin <ScriptBlock>] [-End <ScriptBlock>]
    [-InputObject <PSObject>] [-RemainingScripts <ScriptBlock[]>] [-Confirm] [-WhatIf]
    [<CommonParameters>]
   
    ForEach-Object [-MemberName] <String> [-ArgumentList <Object[]>] [-InputObject
    <PSObject>] [-Confirm] [-WhatIf] [<CommonParameters>]
   
   
DESCRIPTION
    The ForEach-Object cmdlet performs an operation on each item in a collection of input
    objects. The input objects can be piped to the cmdlet or specified by using the
    InputObject parameter.
   
    Beginning in Windows PowerShell 3.0, there are two different ways to construct a
    ForEach-Object command.
   
    Script block. You can use a script block to specify the operation. Within the script
    block, use the $_ variable to represent the current object. The script block is the
    value of the Process parameter. The script block can contain any Windows PowerShell
    script.
   
    For example, the following command gets the value of the ProcessName property of each
    process on the computer.
   
    Get-Process | ForEach-Object {$_.ProcessName}
   
    Operation statement. You can also write a operation statement, which is much more like
    natural language. You can use the operation statement to specify a property value or
    call a method. Operation statements were introduced in Windows PowerShell 3.0.
   
    For example, the following command also gets the value of the ProcessName property of
    each process on the computer.
   
    Get-Process | ForEach-Object ProcessName
   
    When using the script block format, in addition to using the script block that
    describes the operations that are performed on each input object, you can provide two
    additional script blocks. The Begin script block, which is the value of the Begin
    parameter, runs before the first input object is processed. The End script block,
    which is the value of the End parameter, runs after the last input object is processed.

RELATED LINKS
    Online Version: http://go.microsoft.com/fwlink/p/?linkid=289582

REMARKS
    To see the examples, type: "get-help ForEach-Object -examples".
    For more information, type: "get-help ForEach-Object -detailed".
    For technical information, type: "get-help ForEach-Object -full".
    For online help, type: "get-help ForEach-Object -online"


PS C:\Windows\system32>


  • Edited by wilder7bc Thursday, September 10, 2015 9:04 PM
Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 9:01pm

I found the following article and I am working with it

http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/22/use-powershell-to-read-a-csv-file-and-create-active-directory-user-accounts.aspx

I am coming up with something new like the following below but I have not tested or refined it yet. Hoping I am getting on the right track I like how he lays it out more like regular programming code.

$UserList=Import-csv c:\scripts\Book1.csv
Foreach-Object ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}

==========edited======= nm it gave me error but it was finding names but trying to set one name = to the name after

------------------------------

$UserList=Import-csv c:\scripts\Book1.csv
Foreach-Object ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}

PS C:\Windows\system32> $UserList=Import-csv c:\scripts\Book1.csv
Foreach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}
Set-ADUser : Cannot bind parameter 'Identity'. Cannot convert value
"@{firstname.lastname1=firstname.lastname2}" to type "Microsoft.ActiveDirectory.Management.ADUser".
Error: "Cannot convert the "@{firstname.lastname1=firstname.lastname2}" value of type
"System.Management.Automation.PSCustomObject" to type
"Microsoft.ActiveDirectory.Management.ADUser"."
At line:2 char:45
+ Foreach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}
+                                             ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Man
   agement.Commands.SetADUser

-----------------------------------

  • Edited by wilder7bc Thursday, September 10, 2015 9:37 PM
September 10th, 2015 9:24pm

I found the following article and I am working with it

http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/22/use-powershell-to-read-a-csv-file-and-create-active-directory-user-accounts.aspx

I am coming up with something new like the following below but I have not tested or refined it yet. Hoping I am getting on the right track I like how he lays it out more like regular programming code.

$UserList=Import-csv c:\scripts\Book1.csv
Foreach-Object ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}

==========edited======= nm it gave me error but it was finding names but trying to set one name = to the name after

------------------------------

$UserList=Import-csv c:\scripts\Book1.csv
Foreach-Object ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}

PS C:\Windows\system32> $UserList=Import-csv c:\scripts\Book1.csv
Foreach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}
Set-ADUser : Cannot bind parameter 'Identity'. Cannot convert value
"@{firstname.lastname1=firstname.lastname2}" to type "Microsoft.ActiveDirectory.Management.ADUser".
Error: "Cannot convert the "@{firstname.lastname1=firstname.lastname2}" value of type
"System.Management.Automation.PSCustomObject" to type
"Microsoft.ActiveDirectory.Management.ADUser"."
At line:2 char:45
+ Foreach ($Person in $UserList) { Set-ADUser $Person -Replace @{pwdLastSet=0}}
+                                             ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Man
   agement.Commands.SetADUser

-----------------------------------

  • Edited by wilder7bc Thursday, September 10, 2015 9:37 PM
Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 9:24pm

OMG I get what your saying now so deleting all that stuff I wrote.  My CSV was messed up and why I am getting the double name crap, or atleast I am pretty sure that's what you mean.

I have used CSV in the past just been awhile let me go back to messing with this. 


  • Edited by wilder7bc Thursday, September 10, 2015 11:23 PM
September 10th, 2015 11:12pm

OMG I get what your saying now so deleting all that stuff I wrote.  My CSV was messed up and why I am getting the double name crap, or atleast I am pretty sure that's what you mean.

I have used CSV in the past just been awhile let me go back to messing with this. 


  • Edited by wilder7bc Thursday, September 10, 2015 11:23 PM
Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 11:12pm

Hello wilder7bc,

As you are using your column name as SAMACCOUNTNAME
I used mine as IDENTITY. So, in your words, physically IDENTITY was my column name and all the samaccountnames were row values under it.

Again just to emphasize, in powershell world, column headers are called property values & rows are called objects. The whole thing is just a collection.

I could have shown you the text file way, but you wanted it from a CSV.

And as jrv says, study powershell. :)

Hope this helps

September 10th, 2015 11:48pm

Well I certainly have learned a few things from the post. I have forgotten more things than you can even imagine.  That's that's how much I enjoy learning, and how many things I have learned, and yes as mentioned sadly forgotten =)

I would rather be underestimated in what I do and do not know and have things over explained than someone think I know more than I may and then under explain it.  I feel the digs like other people do as well but the learning just has a priority for me and holds more importance.

I have started on Power shell about 4-5 times now.  the last time I hit it up the hardest but had to stop because of college, and it kind of went away.  So your definitely right about needing to study it and study about 15 other things as well... However, I will say this Power Shell is my favorite, and I get the most excited working with it.

I have the entire cbt nuggets Power Shell recorded from my CBT Nuggets subscription I just have never had time to watch it.  

What do you think is the fastest and most powerful way to really take off in Power Shell? 

I want to be able to approach power shell in a coding way and be able to right if and loops and arrays and connect things together.  Like the above I had three different things but I bet with some work and logic you could right up a class with methods and have it execute one bit then move to the next and execute it and then to the next.  When I can sit down and do that with just the minimum amount of looking at syntax then I will be happy with where I am at.

I think I could do that in python with some work but not PowerShell at this time without someone helping me a lot.

Well thanks for sharing information, Its appreciated.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 1:05am

Yup thanks Soumyajyoti you post certainly finally got the forgotten piece of information to resurface in my head and it may have been a lot longer before it resurfaced if not for your post.

Well I think I have used the text file way in the past the difference is in how you call it correct? 

I started using CSV though as that format was always easier when working with excel sheets and stuff, or at least that was my thoughts lol.

now that I look at it I mean it was obvious and I should have known as I have did that many times and read up on that.  I don't know why I forgot it I just did and then when I was working on this my andrenlin was flowing and I was excited about using a for each loop in power shell and for some reason I didn't remember it until you coaxed it out of me.   not really a desired trait but I am what I am and sometimes my brain gets so focused and goes so fast that I miss the things that are obvious. I can be like a force of nature when moving towards something sometimes I slow myself down as it can get a bit wilddddddddddd

September 11th, 2015 1:15am

Hello wilder7bc,

Thank you for your post.

Glad to be of help.

If you are trying yo make it into a single line, why not try a -passthru parameter ?

I will let you find out more about it :)

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 7:08am

I am looking the -passthru parameter up this morning Soumyajyoti found this link which I am reading through

http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/18/use-the-powershell-passthru-parameter-and-get-back-objects.aspx

Hopefully its something I can understand then transpose into something simple that I can understand sometimes the scripting guy loses me!

Ok I like to share and post information. I love teaching as well even though I am not the best communicator. So I am going to post a link here that references CSV files in case someone else looks at this in the future and is new or not sure on the CSV side.

Here is what was trying to be communicated to myself.

"The first record in a CSV file may be a header record    containing column (field) names
    There is no mechanism for automatically discerning if the first    record is a header row, so in the general case, this will have    to be provided by an outside process (such as prompting the user).    The header row is encoded just like any other CSV record in accordance    with the rules above.    A header row for the multi-line example above, might be:
      Location, Notes, "Start Date", ... "

http://creativyst.com/Doc/Articles/CSV/CSV01.htm

September 11th, 2015 10:25am

A CSV file nearly always has a header.

A CSV file is a complex data object as text.

The description of a CSV file can be found here: https://en.wikipedia.org/wiki/Comma-separated_values

PowerShell and all MS utilities and programs create SCV files with headers.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 11:35am

Hello wilder7bc,

Thank you for your post.

You have to learn how cmdlets & parameters work to understand the power of the parameter i asked you to check. :)

Till then, on to your next question. Headers are there to be used judiciously from a CSV file. That is what gives us the flexibility of parameter bindings. Now you can obviously change that too. I mean change the header names as you desire and form new headers. I have given an example. It is powershell, and you have the power. ;)

In my example in the snippet, if you see, I used the cmdlet get-wmiobject to fetch the sizes of all the drives (logical) in my laptop. See I took the default output headers (properties/columns for your csv file). But as you can see the free space & total disk sizes are 'ugly' (in bytes). So i corrected them in a language easy for me to understand (GigaBytes), and used custom header names. :)

Hope this helps.

If you find this helpful, you can mark the post as helpful too. :)

September 11th, 2015 12:27pm

testing adding a picture to forums so I can communicate with more tools in the future.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 12:42pm

Hello wilder7bc,

Glad to be of help. 

Happy Scripting :)

September 11th, 2015 12:45pm

Ok I purchased the CBT Nuggets and I am going to do the entire Don Jones Power Shell series

If I don't learn all this stuff by the end of this series I will be fit to be tied.  I will commit to doing  7 videos a week minimum.

Windows PowerShell v2-v3-v4 Ultimate Training

Level: Advanced  Hours: 31  Videos: 90


1. Course Introduction and Lab Setup  (8 min)
2. Windows PowerShell Orientation and Requirements  (24 min)
3. Finding and Discovering Commands  (23 min)
4. Interpreting Command Help  (23 min)
5. Running Commands  (26 min)
6. Working with PSProviders and PSDrives  (17 min)
7. Variables, Strings, Hashtables, and Core Operators  (24 min)
8. Regular Expression Basics  (23 min)
9. Running External Commands: Tips and Tricks  (11 min)
10. Learning the Pipeline: Exporting and Converting Data  (23 min)
11. Understanding Objects in PowerShell  (23 min)
12. Core Commands: Selecting, Sorting, Measuring, and More  (27 min)
13. How the PowerShell Pipeline Works  (35 min)
14. Formatting Command Output  (19 min)
15. Comparison Operators and Filtering  (17 min)
16. Advanced Operators  (26 min)
17. Setting Default Values for Command Parameters  (20 min)
18. Enumerating Objects in the Pipeline  (16 min)
19. Soup to Nuts: Completing a New Task  (19 min)
20. LAB A: PowerShell Core Review  (27 min)
21. PowerShell Remoting Basics  (45 min)
22. Persistent Remoting: PSSessions  (14 min)
23. Implicit Remoting: Using Commands on Another Computer  (22 min)
24. Advanced Remoting: Passing Data and Working with Output  (27 min)
25. Advanced Remoting: Crossing Domain Boundaries  (22 min)
26. Advanced Remoting: Custom Session Configurations  (28 min)
27. Web Remoting: PowerShell Web Access  (20 min)
28. LAB B: PowerShell Remoting Review  (12 min)
29. WMI and CIM: WMI, Docs, and the Repository  (23 min)
30. WMI and CIM: Using WMI to Commands Query Data  (23 min)
31. WMI and CIM: Using CIM Commands to Query Data  (25 min)
32. WMI and CIM: Filtering and WMI Query Language  (20 min)
33. WMI and CIM: Associations  (18 min)
34. WMI and CIM: Working with CIM Sessions  (18 min)
35. WMI and CIM: Executing Instance Methods  (22 min)
36. LAB C: WMI and CIM Review  (11 min)
37. Background Job Basics: Local, WMI, and Remoting Jobs  (19 min)
38. Scheduled Background Jobs  (24 min)
39. LAB D: Jobs Review  (10 min)
40. PowerShell Script Security  (25 min)
41. Prompting for Input, Producing Output  (17 min)
42. Creating Basic Parameterized Scripts  (19 min)
43. PowerShell Scripting: Logical Constructs  (22 min)
44. PowerShell Scripting: Looping Constructs  (23 min)
45. PowerShell Scripting: Basic Functions, Filters, and Pipeline Functions  (35 min)
46. PowerShell Scripting: Best Practices  (17 min)
47. PowerShell Scripting: From Command to Script to Function to Module  (14 min)
48. PowerShell Scripting: Scope  (20 min)
49. PowerShell Scripting: Combining Data from Multiple Sources  (16 min)
50. LAB E: PowerShell Scripting Review  (13 min)
51. Advanced Functions: Adding Help  (15 min)
52. Advanced Functions: Parameter Attributes  (17 min)
53. Advanced Functions: Pipeline Input  (16 min)
54. Advanced Functions: Parameter Sets  (18 min)
55. LAB F: Advanced Functions Review  (22 min)
56. Creating Private Utility Functions and Preference Variables  (16 min)
57. Adding Error Capturing and Handling to a Function  (20 min)
58. Advanced Error Handling  (26 min)
59. Error Handling the Old Way: Trap  (8 min)
60. Debugging Techniques  (32 min)
61. Creating Custom Formatting Views  (25 min)
62. Creating Custom Type Extensions  (21 min)
63. Working with SQL Server (and other) Databases  (40 min)
64. Working with XML Data Files  (29 min)
65. Supporting WhatIf and Confirm in Functions  (13 min)
66. Troubleshooting and Tracing the Pipeline  (16 min)
67. Using Object Hierarchies for Complex Output  (17 min)
68. Creating a Proxy Function  (19 min)
69. LAB G: Advanced Scripting Review  (16 min)
70. From the Field: Enhanced HTML Reporting  (43 min)
71. From the Field: Trend Analysis Reporting  (18 min)
72. From the Field: Scraping HTML Pages  (9 min)
73. Introduction to PowerShell Workflow  (36 min)
74. Desired State Configuration: The Basics  (14 min)
75. Desired State Configuration: Configuration Scripts and Pull Servers  (37 min)
76. Desired State Configuration: Writing Resources  (25 min)
77. Controller Scripts: Automating Business Processes  (10 min)
78. Controller Scripts: A Menu of Tools  (9 min)
79. Creating a GUI Tool: The GUI  (10 min)
80. Creating a GUI Tool: The Code  (11 min)
81. Creating a GUI Tool: The Output  (15 min)
82. Creating a GUI Tool: Using Data Tables  (8 min)
83. LAB H: Automating a Business Process  (7 min)
84. Globalizing a Function or Script  (11 min)
85. Discovering and Using COM Objects  (10 min)
86. Discovering and Using .NET Classes and Instances  (14 min)
87. Using Type Accelerators  (12 min)
88. The Big Gotchas in PowerShell  (23 min)
89. Fun With Profiles  (18 min)
90. Random Tips and Tricks  (26 min

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 1:16pm

Great :)
Good luck learning. 


September 11th, 2015 1:22pm

This is not popcorn time at the movies.  You must do every one of the examples and excercises until you fully understand the lesson before moving to the next lesson.

Only good study habits will work.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 3:32pm

Hi Jrv,

I like popcorn, and I really really like movies. 

What are you trying to say here? "don't make me angry. You wouldn't like me when I'm angry"

hah ;)

POPCORN + MOVIES = Goooooooood!


  • Edited by wilder7bc 10 hours 30 minutes ago
September 11th, 2015 4:38pm

I meant exactly what I posted.  Do all examples and exercises and do not move on until you completely understand the current lesson.  Ask questions when you get stuck by first search the web then post her or other forum if that doesn't help.

Just watching videos like a movie will not teach you anything.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 4:47pm

JRV,

Only the young and stupid would do it any differently.

A. I am not stupid

B. I am young (lets not over analyze the broad statement here, its just a generality "lol")

C. Now that we have that out of the way and you know who you are dealing with a fellow professional in the field of IT that has a burning passion for learning but is much weaker in a specific area than yourself you can relax and know that your dealing with a learnaholic and can then devote more time in assisting them knowing they don't take it for granted.

have a great weekend!

September 11th, 2015 6:28pm

You posted: "What do you think is the fastest and most powerful way to really take off in Power Shell? "

I answered: "Do all examples and exercises and do not move on until you completely understand the current lesson.  Ask questions when you get stuck by first search the web then post her or other forum if that doesn't help."

So why are you being defensive.  No one mentioned anything about "stupid" but you.

I have heard from dozens of you guys and girls how hard they work to learn PowerShell and then they ask a question from page one of the manual.  I am just trying to help you focus as you seem to have been trying to learn this for some time.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 7:04pm

Hi Jrv,

I like popcorn, and I really really like movies. 

What are you trying to say here? "don't make me angry. You wouldn't like me when I'm angry"

hah ;)

POPCORN + MOVIES = Goooooooood!


  • Edited by wilder7bc Friday, September 11, 2015 8:40 PM
September 11th, 2015 8:35pm

Hi Jrv,

I like popcorn, and I really really like movies. 

What are you trying to say here? "don't make me angry. You wouldn't like me when I'm angry"

hah ;)

POPCORN + MOVIES = Goooooooood!


  • Edited by wilder7bc Friday, September 11, 2015 8:40 PM
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 8:35pm

I have not been defensive until just now, as I have not been agitated until after you last post and then only due to the pattern of your post.

I cannot get my entire 4.3 pages of text to fit on here that I typed that  laid out an organized break down step by step details of exactly where you was rude and how you was rude. I am not going to go into all of it again.

Point is you have been impolite throughout this post and what I consider disrespectful.  A lot of it was grey areas but when the patterns add up they impact the whole.

So to keep it short.

Either apologize and say your sorry and say your piece and we can move on and both let it go, and who knows maybe be friends in the future.

Or you can not apologize, and you can go your own way.  I don't need help from people that are not very nice, as there are many others that are nice.

Just for the record.

I am a 47 year old professional Server Administrator and Engineer who has 20 years in the IT industry.

I work for a global company who is on pretty much every content and I am a primary person responsible for taking care of that infrastructure in a small team of about 6 of the top admins.

I also have my own business on top of that which I work evenings and weekends which enables small and medium businesses to achieve Enterprise level IT support we build their network and servers infrastructure and whatever they might need.

On top of that I go to school full time and I part of the honor society picking up my second degree in network and server engineering.  My first degree is in Engineering Physics.

I also am married and have 3 kids one of which just finished school and another which is just starting college.

I am military veteran who served in the US armed forces as well.

So I have been very busy and I don't have a ton of time to spend studying extra things at least not while in college.  So I don't have any problem learning I just have not had enough time in the day for everything.

People are more than just names on the internet we are all somebody and in my opinion we all, including yourself, disserve respect as we are all humans.

September 11th, 2015 11:20pm

Hello wilder7bc,

Request you to calm down. Too many posts and a lot of misunderstanding has occurred.

I would request the same to  jrv.

We all here are to learn. I am very new to this forum too. 

@wilder7bc: I am also using the series by Don-Jones. He is really great. You should follow all his labs. It would do you great, if you can do along with a couple of VM's. He will show you how to find and troubleshoot your own problems and I am sure after a couple of videos you will feel very confident. 

Good luck learning. :)

Free Windows Admin Tool Kit Click here and download it now
September 12th, 2015 2:34am

I am glad you like it Soumyajyoti  I am just on video number 3 right now.  I have a Python test tomorrow at 1pm though so I better not study the PS today as I should review one last time before my test. 

I am sure I will see you around your a very sharp young man I am impressed.  Talk to you soon!

September 12th, 2015 5:51pm

...

I have started on Power shell about 4-5 times now.  ... However, I will say this Power Shell is my favorite, and I get the most excited working with it.

...   

What do you think is the fastest and most powerful way to really take off in Power Shell? 

....

Do you use PowerShell as your usual command interpreter?   

Do you use command line interaction?

I have switched away from cmd.exe to powershell.exe and find that having a PowerShell base of operations really reinforces the PowerShell way of thinking.
Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 11:08am

Hi Larry,

I think your correct, and I am trying to do that and you make a very good point there.  its like right now I am learning about (cbt nuggets - Don Jones) "get-command  - NAME *some name", and "help about*", and "Get-Command -Verb  get -Noun somename*", and basic stuff.

I see that I understand and learn that in like 2 seconds, but to ingrain that into memory like ipconfig, or ping takes actually doing it all the time.

The problem is that my experience and what I do at work is at a very high level on scale to 1-100 probably a 75-90.  I don't use Powershell for a lot of it because it takes me to long to research every single task when I just know how to do it manually.

That's why if you look at every post I ever put on here its always about doing something in bulk or reading off a file. Its not very hard stuff but sometimes it uses a somewhat intermediate portion of PowerShell.  I know that if it takes me 3 minutes to do something and I have 1000 of them that is just not acceptable so I come to PowerShell forums, as well as Google what I need.

When I can learn enough powershell to catch up with my server and networking experience and be able to use it like I do "ping", or "ipconfig" or other simple cmd.exe then I am going to retain it because I will be able to start using it at work and it will be on par with my server experience and what I do on the job.

Right now we have a disconnect between my powershell level of knowledge and my Server and Network Engineering level of expertise, and this is why I am not retaining the information.

I think JRV, and Soumyajyoti are correct in saying I need to study power shell starting at the basics and make sure I learn it correctly. There can be no arguing that point. If I can learn the basic, and learn the intermediate and get into the advanced that I can actually start using it all the time then I will retain it because I am using it, and the old saying "use it or lose it" wont reach out and bite me.

I just have not had time because of my schedule, but that is changing and I actually paid 100.00 a month to get subscription to CBT Nuggets, and I will learn more than just from that but I think that's a good start.

Great comment Larry, Thanks!

September 13th, 2015 12:26pm

When you are at the powershell.exe prompt you can easily change to the cmd.exe prompt by executing

cmd.exe
and then return back to powershell.exe by executing a cmd.exe command
exit
I still do that occasionally when I just want the "tried and true" cmd.exe experience temporarily.
Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 12:38pm

If you really want a good grounding in PowerShell, read the book written by the designer of the PowerShell language, Bruce Payette:

"PowerShell in Action", second edition
https://www.manning.com/books/windows-powershell-in-action-second-edition
http://www.amazon.com/Windows-Powershell-Action-Bruce-Payette/dp/1935182137
September 13th, 2015 12:44pm

Thanks!

I just now finished taking my Python test and passed that.   So All I have left is my Technical writing class which is built on my Capstone project. 

Then I have my capstone project, but I wont have to study for thos at night I just have to write and I am already long winded so that should be a breeze.

Going to be nice not to have to set down every night that I am not working and study for college its much more fun learning when its not forced lol.

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 3:18pm

Btw, if English is not your first language and, or, you honestly did not know you was being impolite and did not mean anything by it. (only you know after all what's in your heart).

Then its fine and I forgive you. I really am not a touchy person I just don't want someone being mean to me.

Now if your my friend or just playing around and there is no animosity then you can bust my chops all day long I don't mind.  The only thing I do mind is when its done with ill intent and not from a position of being nice.

I never want to hurt anyone's feelings including yours and if I did that and it was just an issue of not communicating well then I apologize. 

I am happy person I cannot stay upset or have hurt feelings to long as its just not in me.

September 13th, 2015 8:54pm

Hello All,

If this is not asking too much of you all, I have written a powershell script posted at https://gallery.technet.microsoft.com/PwdLastSet-Lastlogon-e368e9f6, titled "PwdLastSet, Lastlogon & LastLogonTimestamp MenuBased Script file".

Could you all review the script and rate me if you like it. :)
Any questions you can ask me.
Link below:

PwdLastSet, Lastlogon & LastLogonTimestamp MenuBased Script file

https://gallery.technet.microsoft.com/PwdLastSet-Lastlogon-e368e9f6

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 9:43pm

I tried to pull up that post using what you pasted:

https://gallery.technet.microsoft.com/PwdLastSet-Lastlogon-e368e9f6

For some reasons its saying not found! I also tried searching under your name as well and didn't see the post title.

September 13th, 2015 10:52pm

Well did the first 4 Modules of the CBT Nuggets I have to say I do like the Don Jones Videos easy to listen to and so far they have all been superb. Its not exciting stuff, but I think its stuff that will get me going I posted my notes below as its good info.

I have a ProLiant 380P G7 with around 100GB of RAM and a couple of processors and like 5TBs that I setup with VMware Cloud, and then installed Three - Four Server 2012 Enterprise, and Two windows 8.1 Enterprise and one windows 7 Enterprise as well as  a few other OS.  Connected it all up to the some Cisco Switches and setup network access to the internet, as well as a Sandbox network to work as my Lab.

I have a few more things besides PowerShell that I want to work with but PowerShell is now one of my priorities.

Anyway below is my notes, not something you can just watch and then move on so the first four videos took way longer than just the 20+ minutes as I had to stop them work on things and rewind them as needed.

CBT NUGGETS POWERSHELL NOTES:

Good to get your font changed when working on a PowerShell console.   Consolas is good and then increase font size to 18 or so.

Next go to layout and to Window size and change windows size height: to around 150 it will stretch out screen.  However on screen buffer size change to match the window size height.  If you do not then you will get an annoying scroll bar which can be a pain to work with.

Importing modules and snapins; Searching for commands

Extend the Shell with snapin (legacy not used much now)

Get-PSSnapin Registered

Add-PSSnapin Name <somename>

Another way is as follows: (note this is a per window if you opened up a new window or close the current one it goes away.)

Get-Module ListAvailable

Import-Module -Name <TroubleshootingPack>

: You can use command to get command but also if you want to filter it you can use the commandtype see below:

Get-Command -Name *pack* -CommandType Cmdlet, function

: naming conversion is Verb  singular Noun example service, log, not services or logs.

Get-Command -Verb Get -Noun *serv*

Get-Command -Verb get -Noun proc*

Get-Command -Verb stop -Noun proc*

Get-Command -Verb stop

: cmdlet is a search word that is specific to powershell, can use something like bing to search for cmdlet and then the command.

HELP:

Use Get-Help command along with the Name of what you want help with.   Example: 

Get-Help -Name dir

:  if you dont like it that you have to scroll up you can use just the help command which pipes it to the more and you can then hit space bar to look at each screen:

Help -Name dir

:you can use the help command or get-help command  with wild cards the difference is that help does not have a Verb or a Noun parameter its only searching on the name, and its just doing a string pattern match. Its also not searching for command names its searching for help file names. For the most part its a one to one mapping meaning every command maps to a help file.

help *service*

:there are some help files not about commands kind of like power shell user manual/help files for example:

help about*

:once find the file you want you can run the following command

Get-Help -Name about_Hash_Tables

:Now if PowerShell cannot find a help file it will search inside the actual files.  For example there is no file or cmdlet called breaking if you did help *breaking* it would search the files and pull up any files with that string in them.

:you could also have it pull it up if there was only one with that name by using the wild card

Get-Help -Name about_H*

:If windows powershell cannot find a help file that has the string or word in it then it will check the content of the file for it here is an example using breaking which is not a file.

Get-Help *breaking*

:If you want all the details then you can ask for full help

Get-Help dir -Full (we talk about this later but notice we are doing positional parameter here where we left out the -Name)

:To get the most up to date information use the  -Online command which will open up web page straight to the internet.

Get-help dir -Online

:First thing you see looking at the description below is that there is two parameter sets(I marked second one with yellow) Once you go down the path of one set then you cannot use parameters from the other set.

You should note some of the following things.  If it has a minus sign in front of it then its a Parameter. Lets look at the Parameter [-LogName] you see <String> in brackets afterwords.  This is the value of the Parameter.   Next look at [[-instanceId] <Int64[]>] you see that the Parameter and its value are surrounded with square brackets this means its optional.  If you look at the first one you see that [LogName] <String> is not surrounded by brackets, so its not optional.  

SYNTAX

    Get-EventLog [-LogName] <String> [[-InstanceId] <Int64[]>] [-After <DateTime>] [-AsBaseObject] [-Before <DateTime>] [-ComputerName

    <String[]>] [-EntryType <String[]>] [-Index <Int32[]>] [-Message <String>] [-Newest <Int32>] [-Source <String[]>] [-UserName

    <String[]>] [<CommonParameters>]

   

||||  Get-EventLog [-AsString] [-ComputerName <String[]>] [-List] [<CommonParameters>]

Now you might ask why is there brackets around the parameter [-LogName] This means the parameter is optional. This means you could type:    

Get-EventLog application -Newest 5

:See the Value for the Parameter can be used instead of the parameter in a way abbreviating it, because the Parameter is optional when used in this way. These are called positional paramters you can see that [-LogName] is in the first position as is its Value so when we put the Value in the first position PowerShell knows what we mean.  

We have did this already with such things as help dir , which is a positional parameter.  If we typed it out fully it would be: Help -Name dir

 : If youre going to use positional parameters its up to you to get them in the right order.  What you cannot do is something like:  Get-EventLog newest 5 Application Here you would be putting the logname value in the second position which is incorrect.

Best Practices is just to type out the full convention its not a lot of extra typing as you can use Tab completion to assist.

This brings up another important fact.  If you did something like  Get-EventLog Sec  and you tried to Tab complete you will not be able to, the reason being that the - only works with Parameters and you just tried to put it in front of a value.  So it can tell you when something is wrong as well.

Then what you can do is just fall back to the -, for example:  Get-EventLog -?  (see that I put a question mark there) it will then pull up the help so you can see the correct syntax so you can finish it correctly.

In PowerShell 3.0 and newer it does not ship with Help but you can update the help by typing in, you can use -force to make it update sooner as it normally checks every 24 hours.

Update-Help

:If you ever need to get help on a computer not connected to the internet you run the command:

Save-Help

:This will download the file to a PC with internet then you can move those files to the computer without internet(via shared network folder or some other means) and then when you run Update-Help, and specify an alternative  path using a parameter.

:Another really cool feature is the ability to use help and then popup a windows its cool because you can pop it up and then move it to the side as its a floating window and so you can use it while you work, there is a bit of a bug where if it has a lengthy description only the first paragraph of the description will show up.  In that case go back to the power shell windows and review the paragraph if there was something in it that you needed.  This looks like it may have been fixed now in powershell 4.0, but just be aware as it was mentioned in the video.

help -Name dir -ShowWindow

:Something similar to the above is using the show-command see below:

Show-Command -Name Get-EventLog

:This pops up a window that is gui based and you can actually see both parameter types. You would choose one, fill out the part you wanted then either run or copy.  If you copy it would paste to the powershell.

Also notice the following below [-List] there is no value listed for the parameter.  This means its a switch.  Its either there or its not, but it does not take a value.  Another thing notice on the [-ComputerName <String[]> those empty brackets  means it accepts multiple values.

Get-EventLog [-AsString] [-ComputerName <String[]>] [-List] [<CommonParameters>]

:An example of using multiple values is as follows, here we pull event logs from two different servers:

Get-EventLog -LogName Security -Newest 5 -ComputerName DM2,DM3

PS C:\Windows\system32> Get-EventLog -LogName Security -Newest 5 -ComputerName DC2,DM2

   Index Time          EntryType   Source                 InstanceID Message                                                              

   ----- ----          ---------   ------                 ---------- -------                                                              

 3165081 Sep 13 22:04  SuccessA... Microsoft-Windows...         4634 An account was logged off....                                         

 3165080 Sep 13 22:04  SuccessA... Microsoft-Windows...         4624 An account was successfully logged on....                            

 3165079 Sep 13 22:04  SuccessA... Microsoft-Windows...         4672 Special privileges assigned to new logon....                         

 3165078 Sep 13 22:04  SuccessA... Microsoft-Windows...         4634 An account was logged off....                                        

 3165077 Sep 13 22:03  SuccessA... Microsoft-Windows...         4634 An account was logged off....                                        

  207663 Sep 13 22:02  SuccessA... Microsoft-Windows...         4634 An account was logged off....                                         

  207662 Sep 13 22:02  SuccessA... Microsoft-Windows...         4634 An account was logged off....                                        

  207661 Sep 13 22:02  SuccessA... Microsoft-Windows...         4624 An account was successfully logged on....                            

  207660 Sep 13 22:02  SuccessA... Microsoft-Windows...         4672 Special privileges assigned to new logon....                         

  207659 Sep 13 22:02  SuccessA... Microsoft-Windows...         4634 An account was logged off....                                        

PS C:\Windows\system32> 

: As you can see above it pulled 5 from each showing that you can pull from multiple values. 

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 11:17pm

Hi Soumyajyoti,

I found your link now I think:

https://gallery.technet.microsoft.com/scriptcenter/PwdLastSet-Lastlogon-e368e9f6

reading it now but probably check out more tomorrow as its getting late!

Ok I went ahead and checked that out.  That has to be a great learning tool for you!  I tested on my home server labs.

did you learn everything to do that just from the don jones stuff..... if so dang?   You could have probably made it a lot simpler and smaller, but for me I love how you did it because you created a script that adds so many items its a plethora of learning.

Great Job and very impressive.

September 13th, 2015 11:24pm

Hi Soumyajyoti,

I found your link now I think:

https://gallery.technet.microsoft.com/scriptcenter/PwdLastSet-Lastlogon-e368e9f6

reading it now but probably check out more tomorrow as its getting late!

Ok I went ahead and checked that out.  That has to be a great learning tool for you!  I tested on my home server labs.

did you learn everything to do that just from the don jones stuff..... if so dang?   You could have probably made it a lot simpler and smaller, but for me I love how you did it because you created a script that adds so many items its a plethora of learning.

Great Job and very impressive.

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 11:25pm

Hi Soumyajyoti,

I found your link now I think:

https://gallery.technet.microsoft.com/scriptcenter/PwdLastSet-Lastlogon-e368e9f6

reading it now but probably check out more tomorrow as its getting late!

Ok I went ahead and checked that out.  That has to be a great learning tool for you!  I tested on my home server labs.

did you learn everything to do that just from the don jones stuff..... if so dang?   You could have probably made it a lot simpler and smaller, but for me I love how you did it because you created a script that adds so many items its a plethora of learning.

Great Job and very impressive.

  • Edited by wilder7bc Monday, September 14, 2015 3:37 AM
September 14th, 2015 3:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics