Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Wizard of the Deep
Sep 25, 2005

Another productive workday
It really depends on what you want to accomplish. Off the top of my head, I'd suggest some basic Azure training (when Microsoft gets their certification path figured out), which uses PowerShell for 93.3% of what you want to do.

Adbot
ADBOT LOVES YOU

Wizard of the Deep
Sep 25, 2005

Another productive workday
Reading through that script, it doesn't look like it accepts any passed information. Is there something specific you need it to do?

If you just have one domain, you should be able to use something like the below to get your Win7 count:

code:
Get-ADcomputer -server $yourFavoriteDC -filter {((OperatingSystem -like '*7*')) -and (LastLogonDate -ge $SomeReasonableTimeframe)} -properties * | select Name,DistinguishedName,LastLogonDate,OperatingSystem,operatingsystemversion,enabled | export-csv $whereTheCSVShouldGo -notypeinformation -noclobber
Use "Get-ADComputer -Name <one specific name> -Properties *" to see all the properties you can select.

Wizard of the Deep
Sep 25, 2005

Another productive workday
You were using it right, I just gave you the wrong switch. Replace -name with -identity, I think.

Use "get-help get-adcomputer" to get a better idea of how to use the command. You may have to run update-help from an elevated/administrator PowerShell instance.

Wizard of the Deep
Sep 25, 2005

Another productive workday
For identifying active Win7 machines in the domain, I'd filter against PwdLastSet < 90 days. I think PwdLastSet syncs to all DCs, where LastLogonDate might not. I don't have an AD environment available right now to verify, though.

Wizard of the Deep
Sep 25, 2005

Another productive workday
If you're trying to pass by pipeline, I think you should be using "Get-AzureADUser".

Wizard of the Deep
Sep 25, 2005

Another productive workday
I couldn't find a direct reference to any book in the OP, but you should get Learn PowerShell in a Month of Lunches, 3rd Ed. poo poo's changed a lot since the OP was last updated in 2010, and a bunch of that stuff is even easier now.

Wizard of the Deep
Sep 25, 2005

Another productive workday

Ah, I see it now. If anything, get the 3rd edition, because the first edition linked in the OP is a dozen years old. I haven't read it, though. Don't take this as a recommendation.

Wizard of the Deep
Sep 25, 2005

Another productive workday
How is the WinRM trusted hosts list distributed? Can you verify that they're the same on all servers?

Wizard of the Deep
Sep 25, 2005

Another productive workday
Depending on what you're trying to accomplish, you could make a variable for your csv, then at the end do the get-history | export-csv $variable -append, which may meet your objective.

There's also Start-transcript which may also do what you want. I haven't used it in many years, so I don't know exactly how it's changed.

Maybe auditing could be set up to log specific commands, but I've never done that. I think you can flag specific things to be audited? I think it's in GPOs, maybe?

Adbot
ADBOT LOVES YOU

Wizard of the Deep
Sep 25, 2005

Another productive workday
I'm still not seeing what exactly you're trying to accomplish. Do you need to submit some kind of report of when you do a specific task? In that case, I'd honestly just auto-start a transcript as part of your profile.ps1, then grab the relevant data whenever you need to submit the report. Combine that with a Posh theme that auto-timestamps your prompt and you're probably golden.

If you're trying to capture specific output from a command/script, adding | export-csv -NoClobber (or -Append) -NoTypeInformation -Path '$path\command-{$get-date}.csv' or similar code directly into your script is probably the right way to go.

Wizard of the Deep fucked around with this message at 09:24 on Apr 16, 2024

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply