Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

Getting Unspecified Error when running a script

$
0
0

I found a script online that opens URLs in IE tabs. The example worked perfectly.

I replaced the example URLs with my work URLS and it worked fine until I put in 6 URLs.

Windows Script Host

Script: C:\Users\Mike\Desktop\URL.js

Line 25

Character 9

Error: Unspecified Error

Code: 80004005

Source: (null)

Can someone help me with correcting this code? I need it for work by Monday

Thanks

Mike

var navOpenInNewWindow = 0x1;

var navOpenInNewTab = 0x800;

var navOpenInBackgroundTab = 0x1000;

 

var intLoop = 0;

var intArrUBound = 0;

var navFlags = navOpenInBackgroundTab;

var arrstrUrl = new Array(5);

var objIE;

 

    intArrUBound = arrstrUrl.length;

 

    arrstrUrl[0] = "https://collaborate.wellpoint.com/sites/retentionresource/sitepages/home-reorg.aspx";

    arrstrUrl[1] = "https://callcare.wellpoint.com/ccb-wgs/login.asp";

    arrstrUrl[2] = "https://brokerportal.anthem.com/ehb/web/bkr/acc/login.htm?wlp-brand=anthem";

    arrstrUrl[3] = "https://paybill.princetonecom.com/cgi/wellpointEC-bin/vortex.cgi";

    arrstrUrl[4] = "http://hipaaapps.corp.anthem.com/airscorp/aspx/searchindividual.aspx";

    arrstrUrl[5] = "https://portal.056d.dedicated.lync.com/wellpoint/meet/jennifer.hoover/L1P87C47";

 

    objIE = new ActiveXObject("InternetExplorer.Application");

    objIE.Navigate2(arrstrUrl[0]);

 

    for (intLoop=1;intLoop<=intArrUBound;intLoop++) {

 

        objIE.Navigate2(arrstrUrl[intLoop], navFlags);

 

    }

 

    objIE.Visible = true;

    objIE = null;


Import dword via a decimal value in a .reg script

$
0
0

Using a .reg file registry script to import a dword value, it is possible to specify a decimal value instead of a hex value? e.g. ...

This --

;Hide the page file PAGE P:  (32768 = 00008000 hex)
[HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Explorer]
"NoDrives"=dword:32768 (specify that this is a decimal value in some manner?)

Instead of the usual hex default --

;Hide the page file PAGE P:  (32768 = 00008000 hex)
[HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Explorer]
"NoDrives"=dword:00008000

put the scripting language name in the title of a question

Replacing strings of text in template document, then replace source files

$
0
0

Good evening,

I began drafting up a script that allows my team to accomplish a somewhat specific goal, but I have hit a wall since I am trying to accomplish something I have not yet scripted in my lifetime.

We have hundreds of directories nested inside of one folder which each contain an .htm file. My goal is to use powershell to accomplish the following tasks, instead of manually editing each file. 

1.) Read specific strings of text inside of each .htm file to gather First Lastname, Phone Number(s), Job Title. 

2.) Read another .htm file named Template.htm and replace specific strings inside of this document with those that we extracted in step 1. The strings we need to replace in Template.htm can be found with the same regexes in step 1, except the line numbers are different.

3.) Output the modified Template.htm file and overwrite the source file from step 1. 

I have already implemented the regexes that make step 1 work, but am not sure how to proceed with step 2. Each source file has an arbitrary name, but will be stored in the variable $file. I am not sure if I am missing something simple, but would appreciate if someone could point me in the right direction to solve this problem. Script contents below:

#Define Regex for each field we want to capture
$NameRegex = '\>\w+\s\w+\<'
$TitleRegex = '(\B>)((\w+)\b\s*)*(<\B)'
$DirectRegex =‘\b\d{1,3}\.\d{1,3}\.\d{1,4}\s+\w+.\d{1,4}\b’
$PhoneRegex = ‘\b\d{1,3}\.\d{1,3}\.\d{1,4}\b’

#enumerates all htm files in the current working directory
$files = Get-ChildItem -Recurse *htm

foreach ($file in $files)

{

$line1 = Get-Content $file | Select -Index 42 | Select-String -Pattern $NameRegex | % { $_.Matches }
$line2 = Get-Content $file | Select -Index 42 | Select-String -Pattern $TitleRegex -AllMatches | % { $_.Matches }
$line3 = Get-Content $file | Select -Index 43 | Select-String -Pattern $DirectRegex -AllMatches | % { $_.Matches }
$line4 = Get-Content $file | Select -Index 44 | Select-String -Pattern $PhoneRegex -AllMatches | % { $_.Matches }
$line5 = Get-Content $file | Select -Index 45 | Select-String -Pattern $PhoneRegex -AllMatches | % { $_.Matches }

}

#Test the set of data from the last processed variable(s)

$result = $line1, $line2, $line3, $line4, $line5
echo $result

I also seem to be having trouble getting the Regex for First Lastname and Title to strip the characters ">" from the beginning and "<" from the end, but I can worry about tuning those expressions once I figure out the ideal way to replace the strings in Template.htm and Out-File to $file

Thank you for reading! I look forward to hearing ideas from other experts.


Alex Tester 




Need to Replace Active Directory Attributes from CSV File

$
0
0

Dear Sir,

I am facing some issues in an on-going project.

I am importing users in Active Directory from CSV file and after this i need to replace values of some custom attributes of all imported users and the Values needs to be imported from CSV file automatically.

Please send me your contact details so that i can further discuss with you on this issue.

Regards,
Shakeel Shahid.

how to compare the numbers e.g 1.6.0.20 and 1.6.0.25

$
0
0
I need to compare the numbers for example 1.6.0.20 and 1.6.0.25 using vb script and i need to check which one is big number among them.

Umeed4u

Powershell to uninstall the product(MSI installer)

$
0
0

Hi Everyone,

I require method by which we can use the PowerShell script to uninstall the MSI.

My requirement is that i need to search for the specific string in the registry hive (in valuename i.e  displayname) under the registry hive say for example given below

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

Under uninstall hive we have different GUID and we need to recurse the GUID and then locate the string ..After finding the String(i.e Displayname) we need to go back that GUID under which Product is installed and then use this GUID to uninstall the Product .

Appreciate your early response.


Umeed4u

Javascript/VBScript : Unable to open registry key "HKLM\\" for reading.

$
0
0

Hello All,

I'm creating an HTML Application (HTA) using Javascript/VBScript.

My task is to read a registry key "HKEY_LOCAL_MACHINE\\SOFTWARE\\<SomeKey>\\<SubKey>". I've created this <SubKey> manually as String with value set as 1. I tried to access this key using both Javascript and VBScript but faced the same error: Unable to open registry key "HKEY_LOCAL_MACHINE\\SOFTWARE\\<SomeKey>\\<SubKey>"for reading.

The Javascript code is given below:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head><title>Reading Registry Value</title><script type="text/javascript">
            function readValue() {

				var Shell = new ActiveXObject("WScript.Shell");
				var value = Shell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\<SomeKey>\\<SubKey>");
                               document.write("Value: " + value);
            }</script></head><body onload="javascript: readValue()"></body></html>

The VBScript i tried is :-

<html><head><title>Registry HTA Sample</title><HTA:APPLICATION
ID="Registry"
SCROLL="auto"
SINGLEINSTANCE="yes"></head><script language="VBScript">

Sub Window_onLoad
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\\<SomeKey>"
strValueName = "<SubKey>"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,strValue

OutText.innerHTML = "<b>" & strValue & "</b>"
End Sub</script><body><p>The current Stepnumber is: <span id="OutText"></p></body></html>

While i tried to access other values inside "HKLM" or other hives, they are being retrieved successfully, however only this value is not accessible. I also tried to perform the same operation with C# and it worked perfectly fine. Also, I've all the required permissions/rights to read the registry key but still faced the error.

Can anybody please post some suggestions to solve this issue?

Thanks in advance.



TECHIT_ASHISH


Script to get ad computer accounts and properties

$
0
0

Hello Team,

The below is the script I gave to pull the computer accounts and details for AD. But I get error as 

"

Get-ADComputer : The server has returned the following error: invalid enumeration context.
At C:\Temp\Scripts\All computer details.ps1:1 char:15
+ Get-ADComputer <<<<  -Filter * -SearchBase "OU=WP360,OU=P001,OU=CLI,OU=Data,DC=eric,DC=se" |select name -ExpandProperty Name |out-file c:\temp\output\com11.txt
    + CategoryInfo          : NotSpecified: (:) [Get-ADComputer], ADException
    + FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.C 
   ommands.GetADComputer

"

My Script is below:

***********************************

  

Get-ADComputer -ldapFilter (objectclass=computer) -SearchBase "OU=WP360,OU=P001,OU=CLI,OU=Data,DC=erics,DC=se" | select name -ExpandProperty Name |out-file c:\temp\output\com11.txt

$array = Get-Content c:\temp\output\com11.txt

foreach ($a in $array)
{

$q = $a | foreach {$_[2]}

if ($q -ge 48 -and $q -le 57)
{

$x=$a|out-file c:\Temp\output\xxxx.txt -Append

}

else 
{
}

}
$computers = get-content c:\Temp\output\xxxx.txt

foreach ($comp in $computers)
{
get-adcomputer -identity $comp -properties * | select cn,distinguishedName,dnshostname,dscorepropagationdata,employeeID,InstanceType,lastlogoff,lastlogon,lastlogontimestamp,logoncount,msds-authenticatedAtDC,name,objectcatehory,operatingSystem,Operatingsystem servicepack,operatingsystemversion,Samaccountname,samaccounttype,serial,streetAddress,whenchanged,whencreated |Export-Csv c:\Temp\output\computerdetails.csv

}

So I want all the attributes listed for the computer that starts with two character followed by a number (eg: AH965645). 

Note : There are more than a lakh of computer object in this OU

Please help me to correct the script so that I can use it to pull the information required.

Regards,

Suman Rout

Match user with ADgroup and remove user from group

$
0
0

Scripting guy,

I've got a task to delete specific users from specific ADgroups. I have a csv file containing ADgroup and user that is member of this group.

Column A: ADGroupName

Column B: User account (Member of the group mentioned in Column A)

What I would like to do with powershell is to import the CSV file and read for example cell A2 and remove the user mentioned in cell B2. No other user can be removed except the user mentioned in column B.

Example of CSV file:

ADgroup1               User2

ADGroup2              User5

ADGroup3              User16

Can you help me out?

Thanks in advanced.

Powershell Rename Files in Folders and Subfolders to Date and Time Stamp

$
0
0
I need a script that will rename all the files in a folder and subfolder to the file's original date and time stamp. 

Automatically Batch Renaming files with their creation date time as a prefix

$
0
0

I have at folder "Z:\Testing" that has several subfolders each holding camcorder video files "*.MOD". I want to prefix the filenames of all of them with the date and time they were created so they can be gathered and sorted in chronological order.

The end result being ideally:

yyyy-mm-dd-hh-mm + existing filename.MOD

Browsing through some other posts on the forum I came up with this:

Get-ChildItem Z:\Testing\*.MOD -Recurse | Rename-Item -newname {$_.CreationTime.toString("dd-MM-yyyy-HH-mm") +  ".MOD"}

This gets me part way there but two issues remain:

  1. This gives me the CreationTime of the Renaming  but I want the CreationTime of the ChildItem Original File
  2. I can’t figure out how to include the original file name in the Newname

I think I know what I have to do but cannot figure out how:

  1. extract the Filename and  CreationTime from the original file
  2. concatenate the OrigCreationTime + OrigFileName  + “.MOD” into the Rename

I grew up on ForTran, Hex and MSDOS batch files – but that was an eternity ago. I have lost the knack and never learn VB, +C style scripting. Algorithmically I understand what to do – just can’t figure out how to code it.

Get next file ending with “.MOD”

Extract OrigFileName

Extract OrigCreationTime

Rename file as OrigCreationTime + OrigFileName + “.MOD”

Loop until all files renamed

Exporting multiple mailboxes to PST from Office 365

$
0
0

Hi

I was wondering if anyone has a Powershell script that will enable me to export mailboxes to separate PST files from a specific OU or list of user accounts on Office 365.

Thanks

Populate Shadow Group based on several OU's on remote AD using alternate credentials and PowerShell V1

$
0
0

I've been searching for a simple method to populate and maintain a shadow group of all users on several OU's on a Remote AD, while not having to install anything extra on the computer that will run the script. 

The login I use for the script have read-access to the whole AD, and inherited write access to the the OU containing the shadow group.

I've been looking at the accepted answer by Richard Mueller at (social.technet.microsoft.com/Forums/scriptcenter/en-US/8b2d9a43-a406-4d7c-b72f-53fddff048bf/powershell-help-populating-groups-and-searching-ad?forum=ITCG).It looks like the way I'd like to have this implemented, as I'd like to have this solution in one file, without having any dependencies to install on the computer that runs the script. It relies on PowerShell V1 using the [ADSI] and [ADSISeacher].

The base OU's I'd like to add all users in the subtree from could be a list like this:

OU=Accounts,OU=Aarhus,OU=RS,OU=EMA,OU=AAA,DC=MyCompany,DC=com
OU=Accounts,OU=Atlanta,OU=RS,OU=AMR,OU=BBB,DC=MyCompany,DC=com
OU=Accounts,OU=Xian,OU=COR,OU=AP,OU=CCC,DC=MyCompany,DC=com

And I'd like them to end up in a named Security Group.

As far as I can see, the following is needed, and the users needs to be filtered using (sAMAccountType=805306368).

$ShadowGroup = [ADSI]"LDAP://IP:PORT/CN=DevlTool-Global-Users,OU=Development,OU=Security Groups,OU=Groups,OU=foo,OU=bar,OU=Country,OU=Division,DC=domain,DC=org"

$UserOUs = ("OU=Accounts,OU=Aarhus,OU=RS,OU=EMA,OU=AAA,DC=MyCompany,DC=com","Accounts,OU=Atlanta,OU=RS,OU=AMR,OU=BBB,DC=MyCompany,DC=com","Accounts,OU=Xian,OU=COR,OU=AP,OU=CCC,DC=MyCompany,DC=com")

$Domain = New-Object System.DirectoryServices.DirectoryEntry "LDAP://IP:PORT/DC=domain,DC=org", "domain\user", "pass!word"

I've tried modifying the script provided by Richard Mueller, with the info above, but can't get it to work (I know, bad error description, but in short my PowerShell experience is very novice!).

Can you help me to update the script to run through the array of OU's I have provided, and also make it log in with the right credentials?

I'm looking forward for your answer.


Stream Output For SupportsShouldProcess

$
0
0

Hi guys, 

I'm using CmdletBinding() within some of my custom Powershell Functions which I've into modules. I've just used Dave Wyatt's Get-CallerPreference to resolve the passing of common parameters to ensure -Verbose and -Debug are supported as I have logging functions which write to file. 

I'm able to log everything to file. Verbose, Debug, standard output, warnings and errors are all written to file successfully with some stream redirection for commands like Invoke-SQLCmd. 

I've got SupportsShouldProcess set to $True for some functions where the ConfirmPreference is more than Medium. What I'm finding is when I try and write the output to file, a boolean is returned, presumably because $PSCmdlet.ShouldProcess is enclosed within an If statement like below:

if ($pscmdlet.ShouldProcess($ENV:COMPUTERNAME, "Remove this file"))
{

}

What I'm looking for is to be able to write the confirm and whatif statements to file for auditing purposes. Does the ShouldProcess statement use Write-Host and the output is lost or am I missing something?

Is there a way I could have found this information and answered this for myself?

Thanks


New Task with trigger options in powershell

$
0
0

Hello, i am trying to create a new task but i am not able to configure the advanced options like:

- Trigger options: Repeat task every *** for a duration of *** 

I know i have to use the "-RepetitionDuration & -RepetitionInterval' but whenever is use the following input:
-RepetitionInterval  (New-TimeSpan -Minutes 30)

I get an error:

New-ScheduledTaskTrigger : Parameter set cannot be resolved using the specified named parameters.

At line:9 char:20

+         $trigger = New-ScheduledTaskTrigger -Daily -At 12:00 -RepetitionDuration ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [New-ScheduledTaskTrigger], ParameterBindingException

    + FullyQualifiedErrorId : AmbiguousParameterSet,New-ScheduledTaskTrigger

What should i type to get these triggers to work?


Clear Autocomplete Cache OWA 2007

$
0
0

Hi Guys,

I'm looking for script that can clear autocomplete cache in OWA 2007, or plugin that can run inside IE and as soon as user launches OWA 2007 it will clear their cache.

Thanks,

G


gurvinder

Powershell command to delete content from usermailbox Office365

$
0
0

Hi Folks,<o:p></o:p>

i am trying to delete the items from the deleted items of user mailbox but unable to get the command.I tried Search- Mailbox - Search Query option but it will only delete the mail with specific subject or content . Is there any way by which we can delete all the emails under deleted items folder.I am looking for the parameter where we can specify the folder name and it will delete all content of that folder.<o:p></o:p>

Pagefile settings

$
0
0

I am automating the deployment of Windows Server/Hyper-V and have run into an issue with trying to modify the pagefile setting.  In my deployment, I am using a VHD with native boot.  Therefore, I copy host.vhdx to the physical drive and use bcdboot to create a boot entry.  This causes the host.vhdx file to have the drive letter C: on boot, and the physical disk has drive letter D: 

Basically, what I need to be able to do is set pagefile settings for drive D:  Win32_PagefileSetting sees and allows me to set the min/max pagefile size on C:.  But it does not see D:  I can see D:\pagefile.sys with Win32_PagefileUsage, but that does not let me set any values.  If I go in through the GUI, I can set min/max on both C: and D:, but I have not been able to figure out how to see D: so I can set values via Win32_PagefileSetting.  I need to set D: because Windows is looking for pagefile.sys on this drive during the boot process before it has loaded host.vhdx.  Because it was automanaged, now that I turned off automanaged, I get a message every time I log in telling me that Windows has changed my pagefile settings.

Here is the code that works fine for setting the value on C:  What I need is some way to set the values for D: before I reboot the system to have all the changes take effect, just like what would happen if I were using the GUI.  I just can't figure out how to get to D:  I don't think this would be an issue if I were not using native VHD boot.

$computerSystem = Get-WmiObject -Class Win32_ComputerSystem -EnableAllPrivileges
    $computerSystem.AutomaticManagedPagefile = $false
    $computerSystem.Put() | Out-Null
$pageFileSetting = Get-WmiObject -Class Win32_PageFileSetting
    $pageFileSetting.InitialSize = 1024
    $pageFileSetting.MaximumSize = 4096
    $pageFileSetting.Put() | Out-Null
After I use the GUI to set min/max for both C: and D: and reboot, I can then see both C:pagefile.sys and D:pagefile.sys with Win32_PagefileSetting.  So if I can use the GUI to do this, it seems like I should be able to use PowerShell/WMI, but I can't figure out what I need to do to get to D:


. : | : . : | : . tim

Get-ADUser : The server has returned the following error: invalid enumeration context.

$
0
0

I'm running a powershell command to add the email (AD mail) attribute to users in a specific OU.  It seems to work then will bomb out with the error in the title.

I'm using a "scripting guy" command that I've altered with my specfic OU/domain information however, I'm pasting in the more "generic" version :: Get-ADUser -LDAPFilter "(!(mail=\.name*))" -resultSetSize $null -searchbase "ou=test,dc=nwtraders,dc=com"| % {set-aduser -identity $_.distinguishedname -email ($_.samaccountname + "@nwtraders.com")}

I work for a school district and this command is being used to add the mail attribute to the student's accounts.  I think about 2/3 of the students are completed but the script/command bombs and I'm not sure where or why.  I've resubmitted the command several times but I'm not sure whether it's starting from where it bombed or if it's starting again at the beginning and essentially re-doing the ones already completed.

Can someone point me in the direction of a work around or a resolution to the Get-ADUser error?

Thanks!!

Viewing all 15028 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>