AD SCRIPT THAT PROMPTS FOR GROUP NAME AND OUTPUTS FILE

U.S.
U.S. used Ask the Experts™
on
Attempting to create a script that prompts for a specified AD group name to verify if user accounts are disabled and create an output file with the output displayed from PowerShell.  So far this is what I have but I am receiving an blank output.

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$group = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter group name", "Group", "$env:username")

Get-ADGroupMember -identity "$group" | get-aduser | Where {$_.Enabled -eq $false} | format-table name -autosize

Out-File -Force "C:\AD_output.txt"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Because you're writing nothing to the file (and the LoadWithPartialName is deprecated - use Add-Type instead).
Try it like that, for example:
Add-Type -AssemblyName Microsoft.VisualBasic
$groupName = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter group name", "Group", "$env:username")
$groupMembers = Get-ADGroupMember -Identity $groupName | Get-ADUser -Property DisplayName | Where-Object {-not $_.Enabled}
$groupMembers | Format-Table -Property Name -AutoSize
$groupMembers | Select-Object -Property SamAccountName, Name, DisplayName | Export-Csv -NoTypeInformation -Path "C:\AD_output.csv"

Open in new window

U.S.Infrastructure Engineer

Author

Commented:
Awesome this works beautifully! Thanks for helping out a newbie to PS.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial