• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Quick PowerShell Help

DeaconFrost

[H]F Junkie
2FA
Joined
Sep 6, 2007
Messages
11,610
I have a list of similar cmdlets to run, each one outputting a text file. The cmdlet runs fine by itself. Is there a way to have the list run as a script (ps1) that runs each line and generates each file, so I don't have to copy and paste each one manually?

The cmdlet is Get-ADGroupMember -Identity 'Group Name' | Select Name | Out-File "File Path".

So I would have the following:

Get-ADGroupMember -Identity 'Group1' | Select Name | Out-File "C:\Temp\Group1.txt"
Get-ADGroupMember -Identity 'Group2' | Select Name | Out-File "C:\Temp\Group2.txt"

...and so on, so that in the end, if I had 35 lines, I'd end up with 35 text files.
 
Yep, use the Powershell ISE that's included in Windows, put the commands on separate lines and save as a PS1.

Actually, just use the ISE for everything. Has a ton of help features and cmdlet autocomplete etc built in.
 
I have yet to venture into the ISE, but I think I get the drift. Thanks for the info!
 
Don't bother with ISE, get VS Code and install the preview version of the PowerShell extension.

Also:
PHP:
$groups = @(
    "Group1",
    "Group2",
    "Group3"
)

foreach ($g in $groups)
{
    Get-ADGroupMember $g | Select-Object Name | Out-File "C:\Temp\$g.txt"
}

And maybe consider just getting the groups dynamically if possible? Like you can just grab all the groups in a certain OU with Get-ADGroup.
 
Last edited:
Back
Top