Solved

GetReportsForGPO.wsf  need to Need to make a change to output name in script

Posted on 2008-06-25
2
696 Views
Last Modified: 2010-04-21
Weekly I generate a report useing the GetReportsForGPO.wsf file in the Program Files\GPMC\Scripts (thanks lauren)

I am going to schedule this script to run weekly, but the problem is that the report always generates the same filename, so it replaces the last one. Lauren suggested I modify the wsf file to include the date in the report name (so that each time it runs, it wil save the filename with the date) but i dont know how to modify the code to make it work.
I am attaching the script in the Microsoft wsf file, Does anyone know how to modify this to append the date to the filename?


'////////////////////////////////////////////////////////////////////////////
'// Copyright (c) Microsoft Corporation.  All rights reserved
'//
'// Title:		GetReportsForGPO.wsf
'// Author:		mtreit@microsoft.com
'// Created:		8/29/2002
'// Purpose:		Generates XML and HTML reports for a given GPO
'// Revision:		Ported from JScript->VBScript by dtsaltas (December 2002)
'//
'////////////////////////////////////////////////////////////////////////////
 
'///////////////////////////////////////
'// Initialization
'///////////////////////////////////////
<job>
 
' Include necessary libraries
 
<script language="JScript" src="Lib_CommonGPMCFunctions.js"/>
<script language="VBScript">
 
' Create global objects for use by the rest of the script
Dim GPM       : Set GPM = CreateObject("GPMgmt.GPM")
Dim Constants : Set Constants = GPM.GetConstants()
 
'///////////////////////////////////////
'// Main script
'///////////////////////////////////////
 
' Handle command line arguments
Dim ArgumentList     : Set ArgumentList = ProcessCommandLineArguments()
Dim szGPOName        : szGPOName        = ArgumentList.Item("GPOName")
Dim szReportLocation : szReportLocation = ArgumentList.Item("ReportLocation")
Dim szDomainName     : szDomainName     = ArgumentList.Item("Domain")
 
' Validate the path given
Dim bValidPath	: bValidPath = ValidatePath(szReportLocation)
 
If bValidPath = false Then
	WScript.Echo "The path '" & szReportLocation & "' could not be found."
	WScript.Echo "Verify the path exists."
	WScript.Quit
End If
 
' Initialize the Domain object
Dim GPMDomain : Set GPMDomain = GPM.GetDomain(szDomainName, "", Constants.UseAnyDC)
 
 
' Generate the reports
GetGPOReports szGPOName, szReportLocation, GPMDomain
 
'///////////////////////////////////////
'// Function Definitions
'///////////////////////////////////////
 
' Generates reports for all GPOs in the specified domain to a given file system location
Function GetGPOReports(szGPOName, szReportLocation, GPMDomain)
 
	Dim szReportName : szReportName = ""
 
	' Get the GPO object requested
	Dim GPMGPO
	On Error Resume Next
 
	Set GPMGPO = GetGPO(szGPOName, GPMDomain)
	If GPMGPO Is Nothing Then
		WScript.Echo "Could not find GPO " & szGPOName & " in domain " & GPMDomain.Domain & "."
		Exit Function
	End If
 
	' We could get back a collection of multiple GPOs instead of just one
	' If so, warn the user
	
	On Error Resume Next
        Err.Clear
 
	Dim iGPOCount
        iGPOCount = GPMGPO.Count
 
        If Err.Number <> 0 Then
   		iGPOCount = 0
	End If
 
        On Error Goto 0
	If iGPOCount > 0 Then
		WScript.Echo "There are multiple GPOs with the name '" & szGPOName & "'"
		WScript.Echo "Please pass in the unique ID (GUID) of the GPO you want to back up."
		Exit Function
	End If
 
	' Generate the XML report
	On Error Resume Next
	Err.Clear
	szReportName = GPMGPO.DisplayName & ".xml"
		
	' Get rid of any invalid file name characters
	szReportName = GetValidFileName(szReportName)
		
	WScript.Echo vbCrLf & "Generating XML report for GPO '" & GPMGPO.DisplayName & "'"
	Set GPMResult = GPMGPO.GenerateReportToFile(Constants.ReportXML, szReportLocation & "\\" & szReportName)
 
	If Err.Number <> 0 Then
			WScript.Echo vbCrLf & "The attempt to generate the XML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
			Exit Function
	Else
 
		' Call the OverallStatus method on the GPMResult. This will throw an exception if there
		' were any errors during the actual operation.
		GPMResult.OverallStatus
	
		If Err.Number <> 0 Then
			' If we were able to get a GPMResult object, print any status message errors
			WScript.Echo GPMResult = null
 
			If Not GPMResult Is Nothing Then
				PrintStatusMessages GPMResult
			End If
 
			WScript.Echo vbCrLf & "The attempt to generate the XML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
			Exit Function
		End If
	End If
        On Error Goto 0
 
	' Print any status message warnings
	PrintStatusMessages GPMResult
 
	' Generate the HTML report
	Err.Clear
	
	szReportName = GPMGPO.DisplayName & ".html"
 
	' Get rid of any invalid file name characters
	szReportName = GetValidFileName(szReportName)
 
	WScript.Echo "Generating HTML report for GPO '" & GPMGPO.DisplayName & "'"
	Set GPMResult = GPMGPO.GenerateReportToFile(Constants.ReportHTML, szReportLocation & "\\" & szReportName)
 
	If Err.Number <> 0 Then
			WScript.Echo vbCrLf & "The attempt to generate the HTML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
			Exit Function
	Else
		' Call the OverallStatus method on the GPMResult. This will throw an exception if there
		' were any errors during the actual operation.
		GPMResult.OverallStatus
	
		If Err.Number <> 0 Then
			' If we were able to get a GPMResult object, print any status message errors
			If Not GPMResult Is Nothing Then
				PrintStatusMessages GPMResult
			End If
 
			WScript.Echo vbCrLf & "The attempt to generate the HTML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
		End If
	End If	
 
	' Print any status message warnings
	PrintStatusMessages GPMResult
 
End Function
 
' Returns a dictionary object
' containing the named arguments and values that were passed in
Function ProcessCommandLineArguments()
 
	Dim szGPOName        : szGPOName        = ""
	Dim szReportLocation : szReportLocation = ""
	Dim szDomainName     : szDomainName     = ""
 
	' Check if this is cscript. If not, print an error and bail out
 
	If UCase(Right(WScript.FullName,11)) = "WSCRIPT.EXE" Then
		WScript.Echo "You must use cscript.exe to execute this script."
		WScript.Quit(-1)
	End If
 
 
	If WScript.Arguments.Length < 2 Then
	
		WScript.Arguments.ShowUsage
		WScript.Quit(-1)
	End If
	
	Dim Result : Set Result = CreateObject("Scripting.Dictionary")
 
	'get the parameters
	szGPOName        = WScript.Arguments(0)
	szReportLocation = WScript.Arguments(1)
 
	If WScript.Arguments.Named.Exists("Domain") Then
	
		szDomainName = WScript.Arguments.Named("Domain")
	End If
 
	' Get the current domain if none was specified
	If szDomainName = "" Then
		szDomainName = GetDNSDomainForCurrentUser()
	End If
 
	Result.Add "GPOName"        , szGPOName
	Result.Add "ReportLocation" , szReportLocation
	Result.Add "Domain"         , szDomainName
	
	Set ProcessCommandLineArguments = Result
 
End Function
 
</script>
 
<!-- Usage and command line argument information -->
<runtime>
 
<description>
Given a GPO name or GUID, saves XML and HTML reports for that GPO to the specified file system location
</description>
 
<unnamed name="GPOName" helpstring="GPO name or ID" type="string" required="true" />
<unnamed name="ReportLocation" helpstring="File system location to save the reports to" type="string" required="true" />
<named name="Domain" helpstring="DNS name of domain" type="string" required="false" />
 
<example>
Example: GetReportsForGPO.wsf TestGPO c:\myGPOReports /domain:mydomain.com
</example>
 
</runtime>
 
</job>

Open in new window

0
Comment
Question by:neoptoent
2 Comments
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 500 total points
ID: 21865745
The attached should do it.
'////////////////////////////////////////////////////////////////////////////
'// Copyright (c) Microsoft Corporation.  All rights reserved
'//
'// Title:		GetReportsForGPO.wsf
'// Author:		mtreit@microsoft.com
'// Created:		8/29/2002
'// Purpose:		Generates XML and HTML reports for a given GPO
'// Revision:		Ported from JScript->VBScript by dtsaltas (December 2002)
'//
'////////////////////////////////////////////////////////////////////////////
 
'///////////////////////////////////////
'// Initialization
'///////////////////////////////////////
<job>
 
' Include necessary libraries
 
<script language="JScript" src="Lib_CommonGPMCFunctions.js"/>
<script language="VBScript">
 
' Create global objects for use by the rest of the script
Dim GPM       : Set GPM = CreateObject("GPMgmt.GPM")
Dim Constants : Set Constants = GPM.GetConstants()
 
'///////////////////////////////////////
'// Main script
'///////////////////////////////////////
 
' Handle command line arguments
Dim ArgumentList     : Set ArgumentList = ProcessCommandLineArguments()
Dim szGPOName        : szGPOName        = ArgumentList.Item("GPOName")
Dim szReportLocation : szReportLocation = ArgumentList.Item("ReportLocation")
Dim szDomainName     : szDomainName     = ArgumentList.Item("Domain")
 
' Validate the path given
Dim bValidPath	: bValidPath = ValidatePath(szReportLocation)
 
If bValidPath = false Then
	WScript.Echo "The path '" & szReportLocation & "' could not be found."
	WScript.Echo "Verify the path exists."
	WScript.Quit
End If
 
' Initialize the Domain object
Dim GPMDomain : Set GPMDomain = GPM.GetDomain(szDomainName, "", Constants.UseAnyDC)
 
 
' Generate the reports
GetGPOReports szGPOName, szReportLocation, GPMDomain
 
'///////////////////////////////////////
'// Function Definitions
'///////////////////////////////////////
 
' Generates reports for all GPOs in the specified domain to a given file system location
Function GetGPOReports(szGPOName, szReportLocation, GPMDomain)
 
	Dim szReportName : szReportName = ""
 
	' Get the GPO object requested
	Dim GPMGPO
	On Error Resume Next
 
	Set GPMGPO = GetGPO(szGPOName, GPMDomain)
	If GPMGPO Is Nothing Then
		WScript.Echo "Could not find GPO " & szGPOName & " in domain " & GPMDomain.Domain & "."
		Exit Function
	End If
 
	' We could get back a collection of multiple GPOs instead of just one
	' If so, warn the user
	
	On Error Resume Next
        Err.Clear
 
	Dim iGPOCount
        iGPOCount = GPMGPO.Count
 
        If Err.Number <> 0 Then
   		iGPOCount = 0
	End If
 
        On Error Goto 0
	If iGPOCount > 0 Then
		WScript.Echo "There are multiple GPOs with the name '" & szGPOName & "'"
		WScript.Echo "Please pass in the unique ID (GUID) of the GPO you want to back up."
		Exit Function
	End If
 
	' Generate the XML report
	On Error Resume Next
	Err.Clear
	szReportName = GPMGPO.DisplayName & Replace(FormatDateTime(Date()),"/","-") & ".xml"
		
	' Get rid of any invalid file name characters
	szReportName = GetValidFileName(szReportName)
		
	WScript.Echo vbCrLf & "Generating XML report for GPO '" & GPMGPO.DisplayName & "'"
	Set GPMResult = GPMGPO.GenerateReportToFile(Constants.ReportXML, szReportLocation & "\\" & szReportName)
 
	If Err.Number <> 0 Then
			WScript.Echo vbCrLf & "The attempt to generate the XML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
			Exit Function
	Else
 
		' Call the OverallStatus method on the GPMResult. This will throw an exception if there
		' were any errors during the actual operation.
		GPMResult.OverallStatus
	
		If Err.Number <> 0 Then
			' If we were able to get a GPMResult object, print any status message errors
			WScript.Echo GPMResult = null
 
			If Not GPMResult Is Nothing Then
				PrintStatusMessages GPMResult
			End If
 
			WScript.Echo vbCrLf & "The attempt to generate the XML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
			Exit Function
		End If
	End If
        On Error Goto 0
 
	' Print any status message warnings
	PrintStatusMessages GPMResult
 
	' Generate the HTML report
	Err.Clear
	
	szReportName = GPMGPO.DisplayName & Replace(FormatDateTime(Date()),"/","-") & ".html"
 
	' Get rid of any invalid file name characters
	szReportName = GetValidFileName(szReportName)
 
	WScript.Echo "Generating HTML report for GPO '" & GPMGPO.DisplayName & "'"
	Set GPMResult = GPMGPO.GenerateReportToFile(Constants.ReportHTML, szReportLocation & "\\" & szReportName)
 
	If Err.Number <> 0 Then
			WScript.Echo vbCrLf & "The attempt to generate the HTML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
			Exit Function
	Else
		' Call the OverallStatus method on the GPMResult. This will throw an exception if there
		' were any errors during the actual operation.
		GPMResult.OverallStatus
	
		If Err.Number <> 0 Then
			' If we were able to get a GPMResult object, print any status message errors
			If Not GPMResult Is Nothing Then
				PrintStatusMessages GPMResult
			End If
 
			WScript.Echo vbCrLf & "The attempt to generate the HTML report failed for GPO " & GPMGPO.ID
			WScript.Echo Hex(Err.Number) & " - " & Err.Description
		End If
	End If	
 
	' Print any status message warnings
	PrintStatusMessages GPMResult
 
End Function
 
' Returns a dictionary object
' containing the named arguments and values that were passed in
Function ProcessCommandLineArguments()
 
	Dim szGPOName        : szGPOName        = ""
	Dim szReportLocation : szReportLocation = ""
	Dim szDomainName     : szDomainName     = ""
 
	' Check if this is cscript. If not, print an error and bail out
 
	If UCase(Right(WScript.FullName,11)) = "WSCRIPT.EXE" Then
		WScript.Echo "You must use cscript.exe to execute this script."
		WScript.Quit(-1)
	End If
 
 
	If WScript.Arguments.Length < 2 Then
	
		WScript.Arguments.ShowUsage
		WScript.Quit(-1)
	End If
	
	Dim Result : Set Result = CreateObject("Scripting.Dictionary")
 
	'get the parameters
	szGPOName        = WScript.Arguments(0)
	szReportLocation = WScript.Arguments(1)
 
	If WScript.Arguments.Named.Exists("Domain") Then
	
		szDomainName = WScript.Arguments.Named("Domain")
	End If
 
	' Get the current domain if none was specified
	If szDomainName = "" Then
		szDomainName = GetDNSDomainForCurrentUser()
	End If
 
	Result.Add "GPOName"        , szGPOName
	Result.Add "ReportLocation" , szReportLocation
	Result.Add "Domain"         , szDomainName
	
	Set ProcessCommandLineArguments = Result
 
End Function
 
</script>
 
<!-- Usage and command line argument information -->
<runtime>
 
<description>
Given a GPO name or GUID, saves XML and HTML reports for that GPO to the specified file system location
</description>
 
<unnamed name="GPOName" helpstring="GPO name or ID" type="string" required="true" />
<unnamed name="ReportLocation" helpstring="File system location to save the reports to" type="string" required="true" />
<named name="Domain" helpstring="DNS name of domain" type="string" required="false" />
 
<example>
Example: GetReportsForGPO.wsf TestGPO c:\myGPOReports /domain:mydomain.com
</example>
 
</runtime>
 
</job>

Open in new window

0
 

Author Closing Comment

by:neoptoent
ID: 31470559
Thanks so much
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question