Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter results of existing script and modify look of output in CSV

Status
Not open for further replies.

lerrus

Technical User
Oct 12, 2014
2
PL
Hey,

below is a script to export security settings from GPO, most important for me is filter result to see only "PasswordComplexity" don't care about other security settings,

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPO")
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "GUID Name: " & objItem.GUIDName
Wscript.Echo "ID: " & objItem.ID
Wscript.Echo "Access Denied: " & objItem.AccessDenied
Wscript.Echo "Enabled: " & objItem.Enabled
Wscript.Echo "File System path: " & objItem.FileSystemPath
Wscript.Echo "Filter Allowed: " & objItem.FilterAllowed
Wscript.Echo "Filter ID: " & objItem.FilterId
Wscript.Echo "Version: " & objItem.Version
Wscript.Echo
Next

after execution result are one after another :

Key Name: PasswordComplexity
Precedence: 1
Setting: True

Key Name: ClearTextPassword
Precedence: 1
Setting: False

Key Name: ForceLogoffWhenHourExpire
Precedence: 1
Setting: False

Key Name: RequireLogonToChangePassword
Precedence: 1
Setting: False

Key Name: LSAAnonymousNameLookup
Precedence: 1
Setting: False

would be great to have it in this order:

columne 1 columne 2 columne3 columne3
row a: server name key name: Precedence: Setting:
 
Your code does not match your sample results. Anyhow, to filter you can use a WHERE statement:

Code:
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPO [highlight #FCE94F][b]WHERE Name = 'PasswordComplexity'[/b][/highlight]")
 
Dear God, sorry I posted wrong script, anyway guitarzan big thanks your way to filter it works perfect :)

correct script with filter:

Code:
strComputer = "."
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_SecuritySettingBoolean [highlight #EF2929]Where KeyName='Passwordcomplexity'[/highlight]")
For Each objItem in colItems
    WScript.Echo "Computer Name: " & strComputerName
    Wscript.Echo "Key Name: " & objItem.KeyName
    Wscript.Echo "Setting: " & objItem.Setting
    Wscript.Echo
Next

so only one thing left to do, get output in CSV where column1 is Computer Name, next column is Password complexity and last column is value for password complexity, I will be grateful for share how this should be done

peace
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top