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

Reopen last used tabs in Powershell ISE

$
0
0

Hi Scripting Guys

I use a lot of tabs in Powershell ISE console in my work, as an Administrator, and every time I close the ISE I need to reopen every tabs that I used before. So my question is:

When I open Powershell ISE can it automatically reopen last tabs, that I used? Can Powershell ISE remember that last used tabs like IE can remember last open browser session?

Best regards,

Thorkell


WMI Eventing Inconsistency

$
0
0

I'm not entirely sure whether this is the right forum for this question or not, so please point me elsewhere if it's not.

We're trying to set up some WMI filters to watch for malicious use of WMI to launch processes on remote machines.  If we create an event filter in the root\subscription namespace using this query:

SELECT * FROM MSFT_WmiProvider_ExecQueryAsyncEvent_Pre WHERE ObjectPath="Win32_Process" AND MethodName="Create"

Together with an appropriate NtEventLogEventConsumer and FilterToConsumerBinding, we can use the InputParameters.CommandLine property of the extrinsic event to extract the called command line, as long as WMI (the Invoke-WMIMethod powershell cmdlet specifically) is used to call Win32_Process.Create().  However, we see some strange behavior if we use CIM to invoke Win32_Process.Create() (Invoke-CIMMethod).

In that case, the InputParameters object returned by the MSFT_WmiProvider_ExecQueryAsyncEvent_Pre event is either entirely populated with null values (if the Invoke-CIMMethod cmdlet is the first one run in the session) or populated with the values from the previous event (if the Invoke-WMIMethod cmdlet was called earlier).

Does anyone on here have a potential explanation for this inconsistent behavior?  Or can recommend an alternate method for capturing the process creation event that will yield the called command line in all cases?

 

Lotus Notes team room and distribution list access

$
0
0

Hi,

Is there any way that we can have script to access team room and distributed list in ibm lotus notes

PowerShell to Create table on sql databse in multiple instance.

$
0
0

Hello,

I am new  to powershell scripting.

Can some help me with the script to create  a table in sql server database  using powershell in 20 servers  at a time.

Thanks in advance!

Generating Message on Empty Input in CSV

$
0
0

Hi Folks,

I am writing a PS script that imports values from a Csv file. I need a way to generate a message if the Input value is not right or is empty.

Can you please suggest what code should I write for that -

The testfile.csv has 3 headings namely name, description, title

Here's an example code - 

$Input = Import-Csv "C:\testfile.csv"

ForEach ($Item in $Input)

$Name = $Item.name

$Desc = $Item.description

$Title = $Item.title

if($Title -contains "" -or $Title -isnot "Director" -or $Title -isnot "VP")
{
    Write-Host "User is a Normal Employee"
}

So on and so forth. The exception that gets generated says something like -

"Cannot convert the "Agent   " value of type "System.String" to type "System.Type""

I gave it an input with spaces at the end in the title column of the Csv file.

Please advise.


ICALCS or something else?

$
0
0

Hello,

I wonder if 1 thing is possible to be done by ICALS.

On my FS (main folder and all subfolders with files)  I need to change all permission for all groups and users from write to read excluding administrators group.

But I dont want to change anything else, if they have listening they should still have the listening, not the read. Just need to change from write to read.

Thx for any help in that subject

MLub

PowerShell Trim,TrimStart() method not working on a String

$
0
0

Hi ,

The Trim, TrimStart methods is not able to eliminate space in a string .Please help out with the suggestions .

Thanks in Advance !!

Number of virtual processor.

$
0
0

Hi friends 

is there any script to find the count of virtual processor in each socket.

i have created below script to find the same .

please suggest whether  i can continue with below script.

$proccessorcount = (Get-WmiObject -class Win32_Processor).numberoflogicalprocessors
$sum=0
foreach($pcount in $proccessorcount)
{
$sum+=$pcount
}

write-host "virtual processor count : $sum"


JITHIN.R


Behavior of Powershell in SQLAgent on SQLServer 2014 running Win2012 server

$
0
0

I have a Powershell program that deletes old backup files from various Instances that are older than say 30 days.

This works perfectly well on a SQL server 2008R2 running on a windows 2008.

When it was moved to SQL2014 running on a 2012 server this does not work.

It seems the following part barfs as the $startingpath is an UNC path

Get-ChildItem  $startingpath -recurse -filter *.bak | Sort-Object -Property LastWriteTime | ?{$_.lastwritetime -lt(get-date).adddays(-$numdays)}  | remove-item -force | out-null;

Any idea on how to overcome this issue?

Thanks

Jay

How to use EventLog commands in PowerShell 6

$
0
0

I have been using EventLogs commands in my scripts since al least version 3.  but with the new powershell 6 core, they don't seem to be available.  If not, why?  If they are, Where are they and how do I use them?

Thanks.

Too many backslashes

$
0
0

Hi, 

There is probably a really simple solution to this problem but I can't seem to find the answer.

I need to replace the UNC path in a file with another path but when I do I get four backslashes for the \\path and two backslashes for the path dividers in the output, see the script and output here;

Script:

$FilePath = "C:\folder"
$datlive = [regex]::Escape('dat-drive=\\server\folder\folder\')
$PFdatlive = [regex]::Escape('dat-drive=\\domain\dfsroot\share\folder\')
(Get-Content ($FilePath + "\file.ini")) | Foreach-Object {$_ -replace $datlive, $PFdatlive} | Set-Content  ($Filepath + "\file.ini")

Output:

dat-drive=\\\\domain\\dfsroot\\share\\folder\\

How can I stop this happening and make the path set as \\domain\dfsroot\share\folder\

Thank you

Greg

VB script to list all AD computers related to registry key

$
0
0

Hi,

I am looking for a VBS script which lists all AD comoputers (as txt or csv file output) related to any give registry key. The output file should include computer netbios or computer FQDN, IP address and registry ckeck status (yes or no).

Why not Powershell script?

Because we have many servers which has only Powershell 2.0, not the newer powershell versions. I could not list these servers using newer powershell version. Perhaps somebody has another idea?!

Best regards

Birdal 

Script error and says no files to process

$
0
0
HI

I have the followig script and it runs as in transferring files from the folders called test to split but then it keeps telling me there no files to process.

What have I done wrong as there are files in the folder called split.

Any Ideas?

Thanks

HTML Code:
Option Explicit

Private Sub SomeSub()
Dim fso
 
' Global variables
Dim strBaseDir, strDestDir
Dim objFSO, objFile
Dim arrFiles(), i
Dim lngFolderSize, intFolderNumber, strNextDir, intMoveFile

' Define paths to work with
strBaseDir = "C:\Users\g\Desktop\test"
strDestDir = "C:\Users\g\Desktop\split"
strPlayer = "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"

' Set maximum size of new folders
Const cMaxFolderSize = 4294967296#

' Define class that will hold file information
Class File
    Public lngSize
    Public strPath
End Class

' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Fully resolve paths
strBaseDir = objFSO.GetAbsolutePathname(strBaseDir)
strDestDir = objFSO.GetAbsolutePathname(strDestDir)
strPlayer = objFSO.GetAbsolutePathname(strPlayer)

' Make sure the folders exists, exit if not
If Not objFSO.FolderExists(strBaseDir) Then
    WScript.Echo "*ERROR* Folder does not exist: """ & strBaseDir & """."
    WScript.Quit
End If
If Not objFSO.FolderExists(strDestDir) Then
    WScript.Echo "*ERROR* Folder does not exist: """ & strDestDir & """."
    WScript.Quit
 End If
' Initialize array index variable
i = -1

' Load info for each file into array (using File class)
For Each objFile In objFSO.GetFolder(strBaseDir).Files
    ' Don't include any files with size greater than max allowed in a folder
    If objFile.Size > cMaxFolderSize Then
        WScript.Echo "*WARNING* Skipping file: """ & objFile.Path & """, size:""" & objFile.Size & """ exceeds maximum folder size:""" & cMaxFolderSize & """."
    Else
        ' Add another element to the array of type File class
        i = i + 1
        ReDim Preserve arrFiles(i)
        Set arrFiles(i) = New File

        ' Store the size and full path to the file
        arrFiles(i).strPath = objFile.Path
        arrFiles(i).lngSize = objFile.Size
    End If
Next

' If no files found then exit
If i = -1 Then
    WScript.Echo "*WARNING* No files found to process."
    WScript.Quit
End If

' Sort the files arrary by size in descending order
SortArray arrFiles

' Process all files moving to new subfolders until done
intFolderNumber = 0
Do
    ' Start a new destination folder and create it (MUST NOT ALREADY EXIST)
    lngFolderSize = cMaxFolderSize
    intFolderNumber = intFolderNumber + 1
    strNextDir = strDestDir & "\" & intFolderNumber & "\"
    objFSO.CreateFolder strNextDir

    ' Move files to dest folder until full
    Do
        ' Look for the largest file left that will fit in remaining space
        intMoveFile = GetFileToMove(arrFiles, lngFolderSize)

        ' If we found another file to move then move it
        If intMoveFile <> -1 Then
Dest:          [" & intFolderNumber & "] , Available: [" & lngFolderSize & "] , File: [" & arrFiles(intMoveFile).strPath & "] , Size: [" & arrFiles(intMoveFile).lngSize & "]
            objFSO.MoveFile arrFiles(intMoveFile).strPath, strNextDir
            lngFolderSize = lngFolderSize - arrFiles(intMoveFile).lngSize
            arrFiles(intMoveFile).lngSize = -1
        End If
    Loop Until intMoveFile = -1

    ' Add player file
    objFSO.CopyFile strPlayer, strNextDir

Loop Until AllFilesMoved(arrFiles)

End Sub

Function GetFileToMove(ByRef arrArray(), lngSize)
    ' Find next largest file to move that fits, -1 if none found
    Dim i
    GetFileToMove = -1
    For i = LBound(arrArray) To UBound(arrArray)
        If arrArray(i).lngSize <> -1 Then
            If arrArray(i).lngSize <= lngSize Then
                GetFileToMove = i
            End If
            Exit Function
        End If
    Next
End Function

Function AllFilesMoved(ByRef arrArray())
    ' See if all files have been moved
    Dim i
    AllFilesMoved = True
    For i = LBound(arrArray) To UBound(arrArray)
        If arrArray(i).lngSize <> -1 Then
            AllFilesMoved = False
            Exit Function
        End If
    Next
End Function

Sub SortArray(ByRef arrArray())
    ' Sort array of files by size, descending order (simple bubble sort)
    Dim i, j, intTemp
    For i = LBound(arrArray) To UBound(arrArray)
        For j = LBound(arrArray) To UBound(arrArray) - 1
'            If arrArray(j).lngSize < arrArray(j + 1).lngSize Then
            If LCase(arrArray(j).strPath) > LCase(arrArray(j + 1).strPath) Then
                Set intTemp = arrArray(j + 1)
                Set arrArray(j + 1) = arrArray(j)
                Set arrArray(j) = intTemp
                Set intTemp = Nothing
            End If
        Next
    Next
End Sub

PowerShell hashtable duplicate entries

$
0
0

Hi ,

Need some help to eliminate duplicate entries In a hashtable .

 Name                           Value                                                                                                                        
----                           -----                                                                                                                        
USERID                         08/03/2018                                                                                                                   
USERID                         09/03/2018                                                                                                                   
USERID                         10/03/2018                                                                                                                   
USERID                         13/03/2018                                                                                                                   
ADM_IBM                        23/03/2018                                                                                                                   
                                                                                                           
                                                                                                               

The hashtable is like this .

I need only the last entry of USERID to be kept and eliminate all the other values of USERID .



Powershell detect change to the registry

$
0
0

Hi

I’m looking for a command line method to detect a change to the registry and if detected notify the user

I’m looking for the script to do this by itself without needing to manually set audit policies using the windows GUI

The idea I’ve come up with is to watch for event id  4657  to  to occur in the registry

After researching online i am using

Auditpol /set /subcategory:@Registry@ /success:enable   # To set the audit policy to  ON  for the registry

 

Get-Winevent -Computername $env:ComputerName -FilterHasTable @{logname=’security’id=4657}  # To display the event 4657

 

I’ve noticed that no event   4657  has been generated when I manually filter the registry security logs after a few days

Is there a way using powershell to force this to on ?   Or is there an easy way to detect if any registry key has been changed ?

I’ve looked at exporting the reg to a file repeating then comparing the reg files but looking for an alternative

Thanks



confuseis


joining list with "," in powershell variable

$
0
0

I have two variable $server, $type, which both have the same amount of lines, I want to join them with a ',' delimiter. I'm struggling to use the correct combination or foreach and interation. below is examples of the output data and my code I've tried. I think I need a -join but I'm struggling to get it to work correct. How do I join these to variable to get my desired result below?

Example outputs from variables:

$server ------- server1 server2 $type ------ windows dnmp

Example code I've tried recently:

$agentserver = foreach($i in $server){foreach($j in $type){$i + ($j++)}}

Output I'm trying to get:

server1,windows

server2,ndmp


Script help to launch 2 programs at a same time

$
0
0
I have 2 applications where they need to launch one by one due to some memory API requirement. So installed the both applications on Server and wrote a cmd file as below 

c:\scripts\app1tray.exe.lnk
c:\scripts\app1.exe.lnk
"c:\scripts\app2.lnk"
exit

App 2 is in quotes as the shortcut have spaces. 

When the cmd script is launched I see cmd prompt starting and launching the  app1 and then hangs there until i close the program 1 , then program 2 launches . Same Script on old Server farm


I have also tired using VB script as follow 

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\scripts\app1tray.exe.lnk", 0, false
WshShell.Run "c:\scripts\app1.exe.lnk", 0, false
WshShell.Run "c:\scripts\app2.lnk", 0, False

When I use the VBS script , it launches the app2 first and when i close the app2 then it launches app1 . 

I am not fussed in using vb script or bat file. 

Legacy farm is on Server 2003 (bat file is used)
and new farm is on Server 2008 (not R2 due to application compatibility)


Pointers i am looking is for 
1.How to make this script working for 2 applications launch with out seeing the cmd prompt?

Please help me to solve the issue. Thanks in Advance.

Telnet multiple port testing script required one server

$
0
0

I have one requirement is like server example ip is 192.168.22.1 and port 50000 to 50119 how I write script for save my time.

Thanks in advance.


Thanks & Regards, Amol . Amol Dhaygude

how do you install an application, and once it completes installs a second application - new to scripting

$
0
0

Morning, 

I am new to scripting and my office has requested that 2 pieces of software (Mcafee antivirus and globalprotect vpn) be installed as part of our imaging process.  I have started the first portion but I do not know how to start the installer for the second program after the first program finishes.  also, how would I make a small box saying "installing...Mcafee/Global protect?

here is an example of the code I'm using to try installing: 

Function installMcafeeGlobalProtect

Option Explicit

dim commandLine, WshShell

set wshshell = wscript.createobject("wscript.shell")
wshshell.currentdirectory = "C:\temp\framepkg.exe""

   commandLine = "C:\temp\framepkg.exe"

   
   Set WshShell = CreateObject("WScript.Shell")
   Call WshShell.Run (commandLine,8,false)
   set WshShell=Nothing


Scripting file transfers between Windows 10 phone and PC

$
0
0

I very often connect my Lumia 950 phone to a PC for the purpose of transferring (moving) files from the phone to the PC.

I'd like to script that so that I don't have to open File Explorer, navigate to the phone's root, then to the phone's µSD, then to the appropriate folder, then select the files, and finally move them to the target location.

Can this be done, preferably in PowerShell?

Viewing all 15028 articles
Browse latest View live


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