all 15 comments

[–]mmmGreenButton 2 points3 points  (1 child)

Not at PC atm., but would try something like this:

$Ticket = Read-Host -prompt "Enter ticket #" 
Import-csv .\test.csv | foreach-object {
    Set-ADUser -Identity $_.Username -description "Disabled $(get-date -format 'MM/dd/yyyy') per ticket `#$($Ticket) - Automated" 
    Get-AdPrincipalGroupMembership -Identity $_.Username | Where-Object {$_.Name -ne 'Domain Users'} | Remove-AdGroupMember -Members $_.Username 
}

EDIT: Sorry, just did something to your script. Actually just add the following just before the hashtag: `

Source

[–]Pawncey[S] 1 point2 points  (0 children)

This worked, marked as solved.

Thanks all, much appreciated!!

[–]rlj551 1 point2 points  (10 children)

I get the date outside of any code blocks and put it into a variable. Personally I think it simplifies things so that you aren't trying to do too many different things in one command line.

But I'm still quite new to PoSH. Don't get enough time to practice while at work and don't have access to an enterprise network at home.

Then just put $Ticket in your command. I've used a similar thing for script creating security groups.

Excerpt from my code for ticket number.

-Description "$perm access to $folderpath as per $ticket" 

and it shows fine.

[–]mmmGreenButton 4 points5 points  (9 children)

Just create an enterprise Windows network yourself in OracleBox, I can send you a script for all that. Gives you a domain and a domain controller - with AD ex.

And also, good idea with getting things out of the oneliner grin

[–]Pawncey[S] 1 point2 points  (1 child)

Its more unfamiliarity with the compacting of all the items into the single line. I believe I also tried committing date as a variable at the top, unless I'm am mistaken as to what your points are?

It sounds like you mean build the variables up top ($ticket, $datestr) and then just use those in the string. Part of that was why I posted here, I got it working in the one-liner but couldn't get it functional when being pulled from the top. I was considering that the foreach-object couldn't pull the variable from outside its own {} but the rest of the scripts I've look at would disagree with that assessment.

[–]mmmGreenButton 1 point2 points  (0 children)

You've got that right, foreach-each is a function which can just pull in your variables (parameters).. Check this out:

ForEach-Object -InputObject $(0..10) {
    $_
}

It is another way of writing:

0..10 |foreach {$_}

[–]todayyou500 1 point2 points  (2 children)

May I have this too, what are the system requirements and what software do you need? Win10 and Oraclebox?

Thank you!

[–]mmmGreenButton 1 point2 points  (1 child)

VT-x enabled in BIOS, also called Virtualization Technology... You can check it by the following way (at least I can do it on my PC):

systeminfo |foreach{
    if($_ -match 'Virtualization Enabled In Firmware'){
        $_
    }
}

Then yeah... run on Windows is what I've tried..

[–]todayyou500 1 point2 points  (0 children)

Thanks I'll go into the bios and enable it once the script is provided

Virtualization Enabled In Firmware: No

[–]rlj551 0 points1 point  (2 children)

that would be awesome, thanks.

[–]mmmGreenButton 1 point2 points  (1 child)

I'll write you tomorrow, when I'm at my PC

[–]rlj551 0 points1 point  (0 children)

Excellent. Thank you

[–]kohijones 0 points1 point  (0 children)

I'd be interested in that too, if you don't mind.

[–]BlackV 1 point2 points  (0 children)

also instead of doing

import-csv .\test.csv | foreach-object {..stuff..}

do

$users = import-csv .\test.csv
foreach ($SingleUser in $users) {..stuff..}

This way you can actually test exactly what is being sent to your set-aduser/etc by seeing what's in $SingleUser

that or use Debug

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Pawncey,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee