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

test-path where a directory in the path is variable

$
0
0

My company has a series of fax lines and associated file shares. Faxes are processed & then dropped off into these file shares. From that point a service runs about every 60 seconds to look for files in these directories to import into a database.

If there is a problem with the import then the service moves the file to a "HOLD" folder & files remain there until human intervention.

I am trying to create a script that will find the HOLD directory in each of these folders and look for the existence of files, then email a group of users alerting them if there are.

So there are several things I'm trying to accomplish.

1. Look for files in a path where a folder in the middle of the path is variable.

2. Send and email that will inform the recipient that there are files in the HOLD folder(s) and tell them WHICH ones

Here's what I am starting with but it isn't working as expected.  There are files in at least one of these.  I also thought to try using some kind of foreach loop but it's eluding me.  Probably because it's late in the day for me.

$folder = get-content -Path "\\child.domain.com\netlogon\scripts\ps\numbers.txt"

if(Test-Path -Path "\\Server\scan import\fax\$folder\Hold" -include *.pdf, *.tif, *.jpg) {write-host "Files exist at $folder"} Else {write-host "No files in the hold folders"}


# When I wrote this script only God and I knew what I was doing. # Now, only God Knows!


Need Help - Batch File

$
0
0

This Script works well on Clean install but if it has an old version and I want it to check the variable gets broke someone in batch... I can type it in Command line and it works.

Script:

@echo off
REM Install / Upgrade 20-20 to Version 10.4.0.39

ECHO -- Verifying that Viewfinity 5.0.32.718 Agent is Installed --

if exist "C:\Program Files\Viewfinity\Agent\vf_agent.exe" GOTO VFCHECKVERSION

GOTO VFINSTALLAGENT

:VFCHECKVERSION
set VFCURRENTVERSION=5.0.32.718

FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files\\Viewfinity\\Agent\\vf_agent.exe" get version /format:value') DO SET VIEWFINITYVERSION=%%G

IF %VIEWFINITYVERSION%==%VFCURRENTVERSION% GOTO CHECK2020VERSION

:VFINSTALLAGENT
ECHO -- Installing / UPgrading Viewfinity Agent to Version 5.0.32.718 --
   msiexec /i "%~dp0\Viewfinity\VFAgentSetupX64.msi" /qn

PING 127.0.0.1 -n 15

GPUPDATE /FORCE

GOTO CHECK2020VERSION
 
:CHECK2020VERSION
if exist "C:\Program Files (x86)\20-20 Technologies\Design\Bin\System\Design.exe" GOTO 2020CHECKVERSION

GOTO 2020INSTALL

:2020CHECKVERSION
set 2020VERSION10_0=10.0.4.1049
set 22020VERSION10_1=10.1.1.23
set 2020VERSION10_2=10.2.0.37
set 2020VERSION10_3=10.3.0.31
set 2020CURRENTVERSION=10.4.0.39

FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files (x86)\\20-20 Technologies\\Design\\Bin\\System\\Design.exe" get version /format:value') DO SET 2020VERSION=%%G

IF %2020VERSION%==%2020CURRENTVERSION% (GOTO Complete)
else IF %2020VERSION%==%2020VERSION10_0% (GOTO Uninstall_10.0.4.1049)
else IF %2020VERSION%==%2020VERSION10_1% (GOTO Uninstall_10.1.1.23)
else IF %2020VERSION%==%2020VERSION10_2% (GOTO Uninstall_10.2.0.37)
else IF %2020VERSION%==%2020VERSION10_3% (GOTO Uninstall_10.3.0.31)


:Uninstall_10.0.4.1049
ECHO -- Uninstalling 20-20 Design 10.0.4.1049 --
MsiExec.exe /X{1715404F-C357-480C-B62E-D498B352DCB3}
ECHO -- Uninstalling 20-20 CodeMeter 4.5 --
MsiExec.exe /X{DCC1DE01-B633-4CEE-8B6D-35B0BBA6AEE6}


:Uninstall_10.1.1.23
ECHO -- Uninstalling 20-20 Design 10.1.1.23 --
MsiExec.exe /X{A66E0B8B-0110-4F5B-92A6-F605E845D874}


:Uninstall_10.2.0.37
ECHO -- Uninstalling 20-20 Design 10.2.0.37 --
MsiExec.exe /X{C9134328-87B4-4A5A-805F-6D79EB721A6C}


:Uninstall_10.3.0.31
ECHO -- Uninstalling 20-20 Design 10.3.0.31 --
MsiExec.exe /X{0647EB56-58CA-46C2-8E05-4884CF34EB35}


:2020INSTALL
ECHO -- Installing 20-20 Design 10.4.0.39 --

:CheckSentinelVersion
if exist "C:\Program Files\Common Files\SafeNet Sentinel\Sentinel System Driver\SetupSysDriver.exe.exe" GOTO SentinelDriverCHECKVERSION

GOTO SentinelDriverINSTALL

:SentinelDriverCHECKVERSION
set SentinelCURRENTVERSION=7.5.0.1

FOR /F "tokens=2 delims==" %%G IN ('WMIC DATAFILE WHERE NAME^="C:\\Program Files\\Common Files\\SafeNet Sentinel\\Sentinel System Driver\\SetupSysDriver.exe.exe" get version /format:value') DO SET SentinelVERSION=%%G

IF %SentinelVERSION%==%SentinelCURRENTVERSION% (GOTO Install2020CurrentVersion)

:SentinelDriverINSTALL
"%~dp0\Perequesites\Sentinel Protection Installer 7.5.0.exe" /S /v /qn
PING 127.0.0.1 -n 30

:Install2020CurrentVersion

"%~dp0Setup.exe" /exelang 1033 /qb /norestart

PING 127.0.0.1 -n 60

ECHO -- Opening 20-20 Design 10.4.0.39 For First Time Use --

CD "C:\Program Files (x86)\20-20 Technologies\Design\Bin\System"
Design.exe

ECHO -- Waiting for Application to Close --
PING 127.0.0.1 -n 30

"%~dp0install sensio catalog-v10 english.exe"

:CHECKFOLDERREDIRECTION
FOR /F "skip=2 tokens=2,*" %%A IN ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "DESKTOP"') DO set "path=%%B"

if "%path%" == "%USERPROFILE%\Desktop" (goto Complete) else (goto REGIMPORT)

:REGIMPORT
REM IMPORT REGISTRY KEY DEFAULT SAVE LOCATION
REG IMPORT "%~dp020-20Pref.reg

:Complete
Echo You are Running the Latest Version of 20-20 10.4.0.39

:END
ECHO -- 20-20 Design 10.4.0.39 Has Been Successfully Installed --

Pause

The Error I receive is:  Look at the IF Statement or even if I echo it keeps stripping off %2 (first 2 characters)

VB Script to move a file with date in name

$
0
0

I'm so stuck but I know Im close.  So its friday and I'm brain dead and I'm asking for some help please.

I have FILES starting with dates

140729HDF0.835

140730HES0.835

140731UHG0.835

and I need to move the files that are dated in the file's 2 days back.

Dim ObjFso 
Dim SourceLocation 
Dim DestinationLocation 
Dim FileName
Set ObjFso = CreateObject("Scripting.FileSystemObject")  
dteYesterday = DateAdd("d", -1, Date) 
SourceLocation = "c:\835old" 
DestinationLocation = "c:\835new" 
FileName = (Year(dteYesterday), 2) & Right("0" & Month(dteYesterday), 2) & Right("0" & Day(dteYesterday), 2) & ".835"
ObjFso.MoveFile SourceLocation & "\" & FileName, DestinationLocation & "\"

It's something in my FileName= because if I simply change it to

FileName = "*.835"
its works.  Can anyone help please??

Adding child nodes to existing nodes in XML using Powershell

$
0
0

I have the following XML structure:

<ovf:Envelope>
  <References>
  </References>
  <DiskSection>
  </DiskSection>
  <NetworkSection>
  </NetworkSection>
<vmw:IpAssignmentSection>
    <Info>Supported IP assignment schemes</Info>
</vmw:IpAssignmentSection>
</ovf:Envelope>  

I want to add another node <Info> as a child node to <DiskSection> with Text as "Disk Section".

Can someone please help me with the correct code sequence in powershell to achieve that? Urgent!

PowerShell Workflow: Returning $PSCredential from function

$
0
0

Greetings All,

When using PowerShell Workflows, I have a function which returns a $PSCredential object, and workflow code that assigns the return to a variable.  The function call enters and exits wonderfully with just about any other value, primitive or complex type, but the minute you try to return something of type PSCredential, the workflow hangs indefinitely.  See below for example.  Thoughts?

workflow wf {
function f1 {return "Value from f1"}
function f2 {return (New-Object [PSCredential]("User","Password"))}

$f1Return = f1
Write-Output $f1Return

#Code will not get past the next line.  Workflow hangs.
$f2Return = f2
Write-Output $f2Return
}

oShell.run query

$
0
0

Hi all

Go easy on me - trying to make move from batch to *.vbs. It's going ....ok.... so far. Most of the *vbs is working except:


Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "ren c:\backup\*.btt ABC1.xml"
Set oShell = Nothing
If I run 
ren c:\backup\*.btt ABC1.xml

from a CMD line it works fine... if I run the *.vbs I get "Line 3 Character 1 System cannot find file specified" 

What am I doing wrong?

Qaz



Schedule Task within script

$
0
0

I am trying to create a task with very specific options:

This is how I create it from a CMD line:

schtasks /create /tn "Taskname" /tr "\"C:\Program Files\Program1\Program2\Start.exe\"/T" /sc daily /st 01:45:00 /ru "System"

It seems quite complicated to use Set objNewJob = objWMIService.Get("Win32_ScheduledJob") -

(for me anyway) so I was cheating and calling a CMD line but this doesn't work either.

I'm guessing its the " but can't figure it out... 

Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /c schtasks /create /tn "Taskname" /tr "\"C:\Program1\Program2\Start.exe\"/T" /sc daily /st 01:45:00 /ru "System""
Set objShell = Nothing

Any advice gratefully received.  




VB Script error - when try to execute a command on windows shell

$
0
0

Hi ,

I had to create a scheduled task on a specific date - I tried using schtasks It worked well!.

SCHTASKS /create /tn "Mytask" /tr "cscript "C:\Remove.vbs"" /sc ONCE /sd 08/02/2014 /st 14:25 /RL HIGHEST /RU SYSTEM

But when I try to embed this in VBscript it throws me below error.

Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /C SCHTASKS /create /tn "Mytask1" /tr "cscript "C:\Remove.vbs"" /sc ONCE /sd 12/04/2015 /st 12:00 /RL HIGHEST /RU SYSTEM

samp.vbs(6, 72) Microsoft VBScript compilation error: Expected end of statement

Can you please help.


Sai Krishna


VBScript Update Multiple Reg Keys

$
0
0

Hi

I am looking to develop a vbscript that first check if the registry keys exist, and second if the value exist ignore to do any updates. But, if the values do not exist to perform an update.

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv")
Set Shell = CreateObject( "WScript.Shell" )

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop"
strValueName = "\\servername\sharename\" & UserName & "\Desktop"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites"
strValueName = "\\servername\sharename\" & UserName & "\Favorites"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData"
strValueName = "\\servername\sharename\" & UserName & "\AppData"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData"
strValueName = "\\servername\sharename\" & UserName & "\Local AppData"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Music"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Music"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Pictures"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Pictures"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Videos"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Videos"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Documents"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Documents"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Documents"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then
'Shell Folders
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop", "\\servername\sharename" & UserName & "\Desktop", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites", "\\servername\sharename" & UserName & "\Favorites", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\AppData", "%USERPROFILE%\AppData\Roaming", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Downloads", "%USERPROFILE%\Downloads", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Local AppData", "%USERPROFILE%\AppData\Local", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Music", "\\servername\sharename\My Documents" & UserName & "\My Music", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Pictures", "\\servername\sharename\My Documents" & UserName & "\My Pictures", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Video", "\\servername\sharename\My Documents" & UserName & "\My Videos", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal", "\\servername\sharename\" & UserName & "\Documents", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Documents", "\\servername\sharename" & UserName & "\My Documents", "REG_SZ"
'User SHell Folders
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop", "\\servername\sharename" & UserName & "\Desktop", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites", "\\servername\sharename" & UserName & "\Favorites", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData", "%USERPROFILE%\AppData\Roaming", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Downloads", "%USERPROFILE%\Downloads", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData", "%USERPROFILE%\AppData\Local", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Music", "\\servername\sharename\My Documents" & UserName & "\My Music", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Pictures", "\\servername\sharename\My Documents" & UserName & "\My Pictures", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Video", "\\servername\sharename\My Documents" & UserName & "\My Videos", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal", "\\servername\sharename" & UserName & "\My Documents", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Documents", "\\servername\sharename" & UserName & "\My Documents", "REG_EXPAND_SZ"
Else
    Wscript.Echo "The registry key exists."
End If


Event Log Content Email through Scheduled Task in Windows 2012

$
0
0

Hi,

I am Using Attached Event to Task Scheduler on Many Windows 2008 Servers , When Someone logged in through remote desktop , I am getting an email with Server Name , User Name and Machine IP from User Logged in. Now in Windows 2012, this feature has been deprecated so i can not use that , What I need to get the contents of specific Event ID and then email that contents to my email ID , If somebody can help me on this.

Regards

Usman Ghani


Usman Ghani - MCITP Exchange 2010

Powershell export

$
0
0

Morning,

Sorry I am new to using powershell - it is a simple script to provide me a folder structure and files in a particular drive. I am struggling to work out why anything I try it will not export my results. The script is as follows so any help someone can offer would be appreciated:

Get -ChildItem -Force "G:\Blah Blah Blah" -Recurse

Thanks



How do I know if the user is belong to Mail Restricted Group/s? Do anyone know how to do this in Powershell?

$
0
0

Hi Guys,

Good day, I'm new in powershell scripting. Will someone can help me about my problem?

Thanks.

Schedule Task within script for import module

$
0
0

Hi,

Unable to powershell script in Scheduled task. I have added the import AD module in the powershell script.Every time I need to login into Windows 2008 R2 server and then the script runs successfully.. if I log off the server it doesn't runs..

Do you have any solutions for without login on server the script runs sucessfully

Regards

KunalR

Problem importing a module and finding it's commands?

$
0
0

Hi,

I have a problem. I'm trying to import the DFSR module and use it's commands in my PS session.

But, I can't get the commands to show.

I've looked in my system32 directory and I can see the DFSR module folder.

But when I run the command to import the module nothing happens, and it's not showing in my Module window in the ISE.

What could be going wrong?

Thanks

convert lastlogon date value (1/1/1970)

$
0
0

how to convert lastlogon value

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile")
Dim objLastLogon

ForEach objItemin colItems
if (objItem.UserType = "Normal Account") Then

Wscript.Echo objItem.Name & " " & objItem.LastLogon
endif
Next


Support@Mytechnet.me


VBScript to read from Excel, search AD and put a value back into Excel

$
0
0

I have an Excel spreadsheet that contains a list of hired and terminated Employees. What I would like to do is take the employeeid from only the terminated employees, search AD, and return whether the account is locked/unlocked, disabled/enable, distinguishedName and expiration date.

So far, it all works until after "Do Until objExcel.Cells(intRow, 1).Value = """.  If I comment out "on error resume next", the script never responds with "Wscript.Echo objRS.Fields("distinguishedName")".  I've also tried "Wscript.Echo objRS.Fields("distinguishedName").Value", and that also produces an error (Item cannot be found in the collection corresponding to the requested name or ordinal). 

Any assistance to get my script working would be greatly appreciated!

Const ADS_SCOPE_SUBTREE = 2
Const ADS_UF_ACCOUNTDISABLE = 2
On Error Resume Next

' Get the domain string ("dc=domain, dc=local")
strDomain = GetObject("LDAP://rootDSE").Get("defaultNamingContext")
' ADODB connection to AD
Set objConnection = CreateObject("ADODB.Connection")
' Connect
Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
objCommand.Properties("Cache Results") = False
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim shell : Set shell = CreateObject("Shell.Application")
Dim file : Set file = shell.BrowseForFolder(0, "Choose a file:", &H4000)

strTermString = "Termed"
strFilePath = objFSO.GetParentFolderName(strFile)
strFileName = objFSO.GetFileName(strFile)

Set objFile = objFSO.GetFile(strFile)
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strFile)
Set objWorksheet = objExcel.ActiveWorkbook.Worksheets(1)

Set objRange = objWorksheet.UsedRange
Set objTarget = objRange.Find(strTermString)

If Not objTarget Is Nothing Then
	WScript.Echo objTarget.AddressLocal(False,False)
	strRowStart = objTarget.Row
	strFirstAddress = objTarget.AddressLocal(False,False)
End If

Do Until (objTarget Is Nothing)
	Set objTarget = objRange.FindNext(objTarget)
	strHolder = objTarget.AddressLocal(False,False)
	If strHolder = strFirstAddress Then
		Exit Do
	End If
	WScript.Echo objTarget.AddressLocal(False,False)
Loop

'objExcel.Visible = True
' add one or else we search for termed
intRow = strRowStart + 1
intCol = 1
intID = 0

Do Until objExcel.Cells(intRow, 1).Value = ""

	strEmployeeID = objExcel.Cells(intRow,intCol)
	WScript.Echo strEmployeeID
	objCommand.CommandText = "SELECT * FROM 'LDAP://" & strDomain & "' WHERE employeeid = '" & strEmployeeID & "' AND objectClass = 'user'"
	Set objRS = objCommand.Execute
	While Not objRS.EOF
             intUAC=objRecordset.Fields("userAccountControl")

             Wscript.Echo objRS.Fields("distinguishedName")
             If intUAC AND ADS_UF_ACCOUNTDISABLE Then
                 objExcel.Cells(intRow, 20) = "Disabled"
                 objExcel.Cells(intRow, 1).EntireRow.interior.ColorIndex = 4

             End If
	Wend
	intRow = intRow + 1
Loop


Change CDROM drive letter based on objItem.DeviceID

$
0
0

Good start was in: http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/14/change-drive-letters-and-labels-via-a-simple-powershell-command.aspx
but does not actually seem to work (Win 7 x64)

Get-WmiObject Win32_CDROMDrive

does not actually display much, but could just use it like:

$drive = get-WmiObject win32_cdromdrive -filter "Caption = 'ELBY CLONEDRIVE SCSI CdRom Device'"

but then the following one fails:

PS C:\Windows\system32> Set-WmiInstance -inputobject $drive -Arguments @{Drive="U:"}
Set-WmiInstance : Provider is not capable of the attempted operation
At line:1 char:16
+ Set-WmiInstance <<<<  -inputobject $drive -Arguments @{Drive="U:"}
    + CategoryInfo          : InvalidOperation: (:) [Set-WmiInstance], ManagementException
    + FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance

Anybody having any good idea how to get it going?

Thanks

Seb

System DSN not visible in ODBC Control panel

$
0
0

I am creating system dsn at run time using VB code to connect to database. My vb code makes entries in following registry key to create the dsn HKLM\SOFTWARE\ODBC\ODBC.INI. 

But I cannot see the actual system dsn in ODBC window. My application gets connected to database but the dsn is not visible in "ODBC Data Source Administrator" panel. 

I used code example from here;

http://gallery.technet.microsoft.com/scriptcenter/635ff2a1-4188-4664-8cd8-4bd3bf832592#content

When I run the same code via QTP, it shows system dsn in ODBC window, but the same codes does not show when I save this file as "dsn.vbs" file and double click to run it. However it does write in registry key correctly. I tried running the vbs file as an "Administrator", but no luck.  I am using windows 7. I appreciate your help.


How to stop the rename the cn again if it had meet the condition

$
0
0

How to stop to rename the CN in Active directory if running the script.

This is my script:

$objSearch = New-Object DirectoryServices.DirectorySearcher
$dateNow = Get-Date
$DomainDNS = "server2008.server1.com" #server 2008
$ADpath = [ADSI]"LDAP://$DomainDNS/ou=power shell test,dc=server1,dc=com"
$objSearch.Filter = '(&(objectClass=user)(objectCategory=person)(!samaccountname=user1))'
$objSearch.SearchRoot = $ADpath
$objSearch.PageSize = 1000
$objSearch.SearchScope = "subtree" 
$objResults = $objSearch.Findall()

write-host 'objResults: ' $objResults

foreach($objResult in $objResults){  

$objuser = $objResult.GetDirectoryEntry()
$name = $objuser.cn
write-host "name:" $name

if (($objuser.cn -notcontains "DA$name")){
    $changeName = "DA" + $name
    write-host 'CHANGE NAME: ' $changeName
    $objuser.rename("cn=$changeName")
    $objuser.CommitChanges()
  }

  else {
    continue
  }

}


The result I get is :

what I want the result is:

How to change dns setting using powershell

$
0
0
Hi every one, I am really confused where to start from I would like to populate just two fields in network adapter setting. those two fields are preferred DNS and alternate DNS. The ip will be allocated dynamically using DHCP. At the moment I fill the two fields manually but i want a powershell script to do this. I searched over internet but its really confusing. Can some one please help
Viewing all 15028 articles
Browse latest View live


Latest Images

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