Solved

Please help with this VB script -#Requires -version 3 what is that?

Posted on 2014-12-18
12
126 Views
Last Modified: 2014-12-29
Hi,
I am trying to run this script to import GPOs from the backup and it is failing with the errors because I need to specify the required parameter but don't know how and what they are. Could you please explain what I need to provide here.

Thank you!
#################################
## Script Options and Parameters
#################################

#Requires -version 3 (???? Not sure...
#Requires -modules ActiveDirectory,GroupPolicy (OK. I got this part)

#Version: 2.0 (???? I am not sure about this one)

#Define and validate parameters (What do I need to provide here???? and where??)
[CmdletBinding()]
Param(
      #The target domain
      [parameter(Mandatory=$True,Position=1)]
      [ValidateScript({Get-ADDomain $_})]
      [String]$Domain,

      #The source backup folder
      [parameter(Mandatory=$True,Position=2)]
      [ValidateScript({Test-Path $_})]
      [String]$BackupFolder,

      # Whether to reference a migration table (?????) How to provide it?
      [Switch]
      $MigTable,

      # Whether to import SOM information (??? )
      [Switch]
      $SomInfo,

      # Whether to import WMI filter information    (?????? should this me a path or somthing or domain???)
      [Switch]
      $WmiFilter
      )


#Set strict mode to identify typographical errors (uncomment whilst editing script)
#Set-StrictMode -version Latest



##########################################################################################################

##############################
## FUNCTION - Log-ScriptEvent
0
Comment
Question by:creative555
  • 7
  • 2
  • 2
  • +1
12 Comments
 

Author Comment

by:creative555
ID: 40508580
If you could please provide an example script, would be great.

THank you!
0
 

Author Comment

by:creative555
ID: 40508581
I am getting the following error :
PS C:\scripts> .\Import_GPOs.ps1 -Domain test.lab.com -BackupFolder "C:\GPOBackup\GroupPolicies\12-18-2014Lab"
Cannot process the "#requires" statement at line 94 because it is not in the correct format.
The "#requires" statement must be in one of the following formats:
 "#requires -shellid <shellID>"
 "#requires -version <major.minor>"
 "#requires -pssnapin <psSnapInName> [-version <major.minor>]"
At line:1 char:18
+ .\Import_GPOs.ps1 <<<<  -Domain test.lab.com -BackupFolder "C:\GPOBackup\GroupPolicies\12-18-2014Lab"
    + CategoryInfo          : ObjectNotFound: (:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 12

Expert Comment

by:SreRaj
ID: 40508599
Hi,

The error is triggered for a comment line which start with '#' character. Please try removing all the lines starting with '#' from the script and then try executing with the same format you tried.
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:creative555
ID: 40508628
Here is the line 94 below:
Should I delete the following ??
#Requires -modules ActiveDirectory,GroupPolicy

#################################
## Script Options and Parameters
#################################

#Requires -version 3
#Requires -modules ActiveDirectory,GroupPolicy

#Version: 2.0

#Define and validate parameters
[CmdletBinding()]
0
 
LVL 12

Expert Comment

by:SreRaj
ID: 40508633
Please delete lines starting with '#' only. Lines starting with '#' are comments and does not impact the script.

You should not be deleting following line.
[CmdletBinding()]
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40508898
This is not vbscript - it's a powershell script...the #requires line indicates that version 3 of powershell is needed as well as those indicated modules..  All other # lines are comments.
You will need to run powershell in order to launch this script.
0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 40508926
No, you shouldn't delete any of those lines.  Some are comments (which don't do anything except to explain the code), and some are restrictions on the script.
#Requires -version 3
is a valid statement.  It means you need to run the script with at least PS 3.0.  Make sure that there's nothing after the version number.  See the help for about_requires
You use the #Requires when there are features in the script that require your environment to meet certain prerequisites (otherwise the script will fail).  Make sure that there's nothing after the version number.

#Version: 2.0
Is only a comment.  Likely the second version of the script by the author.

#Set-StrictMode -version Latest
Set-StrictMode is a command, but this line is commented out so it won't do anything.

By the way, this is all PowerShell.  It has nothing to do with VBScript or Visual Basic, so for further questions I'd suggest not tagging or including them in those topic areas.
0
 

Author Comment

by:creative555
ID: 40522444
THank you. Looks like I have Powershell Version 2 and version 3 is required.

Downloaded and trying to install PS 3 now...but it tells me that update is not applicable to the  computer....I am trying to install it on Windows 2008 R2.

Will post if this resolves the issue
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 250 total points
ID: 40522539
From: http://technet.microsoft.com/en-us/library/hh847837.aspx

Install the full installation of Microsoft .NET Framework 4.0 (dotNetFx40_Full_setup.exe) from the Microsoft Download Center at http://go.microsoft.com/fwlink/?LinkID=212547.

Or, install Microsoft .NET Framework 4.5 (dotNetFx45_Full_setup.exe) from the Microsoft Download Center at http://go.microsoft.com/fwlink/?LinkID=242919.

Install Windows Management Framework 3.0 from the Microsoft Download Center at http://go.microsoft.com/fwlink/?LinkID=240290.
0
 

Author Comment

by:creative555
ID: 40522548
Thank you! Yes. I already installed it framework 4.5. and having issues with this Management Framework 3.0 but I saw it requires SP1 for Windows Server 2008 R2 which I dont have.

installing SP 1 and then powershell 3. Will let you know if this will work.

Other than version of powershell that script is complaining....is there anything else I need according to the errors?
0
 

Author Comment

by:creative555
ID: 40522942
Yes!!! It works now after I downloaded and installed Powershell version 3!!!
0
 

Author Closing Comment

by:creative555
ID: 40522946
Excellent! Thank you so much
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 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