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

Scripting repadmin /showutdvec or Get-ADReplicationUpToDatenessVectorTable

$
0
0

Hi all,

I'm trying to write a script to do some rudimentary AD replication checking. At the moment I'm running a repadmin /replsummary which identifies domain controllers that are failing inbound replication.

What I'd like to do is use Repadmin /showutdvec to check outbound replication (in a sense) as /replsummary only checks connection objects that the KCC has created, and not for instances where the KCC hasn't created any connection objects. For this I'd like to use /showutdvec then check the date it reports back is listed as today, for those non-GUID entries.

So the code would look something like:

Get all domain controllers in the forest (multi-domain forest)

For each in the list, run:

                repadmin /showutdvec serverName "dc=domainName,dc=co,dc=uk"

Check the output and highlight any valid entries e.g. not GUIDS, or those lines without a  \ in the name field as non-GUIDs come back as siteName\serverName, and highlight those which don't report todays date.

There is the PowerShell equivalent now which I'd be happy to use if we could highlight what I've mentioned above:

Get-ADReplicationUpToDatenessVectorTable

Thanks!


Delete Files listed on a Text file across many directories

$
0
0

I've got a txt file with approx 60 files names and I need to delete the file across approx 300 folders.  The folders are all located under a single data directory (ex C:\data).

I found the below code a ran it, but it took over an hour to run.  Is there a better and faster way to accomplish this?

gc C:\cleanup.txt  | % {gci "C:\data" -Include $_ -Recurse} | % {Remove-Item $_ }

Thanks,

Kevin

Length

$
0
0
How do I show the files greater than 260 characters to edit them?
Get-ChildItem -Path $pathToScan -Recurse -Force | Select-Object -Property LastWriteTime, FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}}

How do i fix output data from traling off at the end like "...."

$
0
0

Hello,

Platform Windows 8.1 x64

Domain\production environment

let me provide a little insight to my environment.

We have in our environment set up that when a machine sits inactive for a set period of time it is automatically moved to a OU "inactive-workstations" and these are disabled on the domain. Also the source OU that the machine was originally in is added to the computer account description. 

Example:

Description: [SOURCE_OU:OU=US-Dallas Call Center,OU=North America,OU=Workstations,DC=enterprisenet,DC=org]Gary Williamson - Dallas Remote - HP

I am trying to write a script that I can use to query this OU "inactive-workstations" for all machines at my location that are in this OU.

Here is my current powershell command:

Get-ADcomputer -Filter * -Properties CN, Description -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" | Format-Table -AutoSize -hidetableheaders CN, Description

This shows me the computer name and description of every machine in the OU "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" but they all show like in the example below. which I usually out put the data to a file and make it into a table in excel then do a text filter that "contains" "dallas" which is my location.

Example:

USLCNU1360JP9             [SOURCE_OU:OU=US-Dallas Call Center,OU=North Ameri...

My questions is: How do I get the output to not trail off at the end like in the example below. I am already using the -autosize parameter in format-table but it still does it. I need to be able to see all the text because there is usually a user name at the end we have most of our computer accounts in my location Dallas modified with the users name in the description. This is vary helpful in identifying who the machine belongs to or what station he machine is in our call center.

Example:

USLCNU1360JP9             [SOURCE_OU:OU=US-Dallas Call Center,OU=North Ameri...

I need it to show me like example below:

[SOURCE_OU:OU=US-Dallas Call Center,OU=North America,OU=Workstations,DC=enterprisenet,DC=org]Gary Williamson - Dallas Remote - HP

Need help with Powershell query

$
0
0

Hello,

I am trying to run a command to find all machines in an OU with "dallas" in the description string. My command is as follows:

Get-ADcomputer -filter 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" |
 Select-Object Name, Description |
 Export-Csv C:\SW_Share\Scripts\Script_Output\inactive.csv -NoType

The problem I am having is that the file that is outputted has the correct machine names but the description is blank.

Example:

NameDescription
USLCNU1360JP9
UST003730152853

USDHL4PDX1

I need both...

any help would be appreciated as I am not the best powershell scripter.

how to get the password expires details for all users in office 365 exchange

$
0
0

We can trace user account with last password change but we are not getting password expire account details.

So we required power shell script to generate user details with password expire details for all users.

Permissions not assigning correctly

$
0
0

Hi,

I need help with a script to create multiple folders and assign permissions.

I have to create department folders and assign various permissions on the folders, in a department some users should have 'Read' only, others have permission to create folders and files, etc.

i have created a CSV file with the following attributes 'Path', 'User', 'Permission', ' Rule', i then use the script to loop through the CSV to create the folders and assign the permissions, i have modified a script i found on the internet.

My goal is to create the folders and assign the permissions, but the folders i am creating must not inherit their parents permissions, only the subfolder and files that will be manually created by the users should inherit their Parent folder permissions.

the script below creates the folders and add the users correctly, but does not assign the permissions. all the users that are added to the folder have no permissions assigned to them.

the problem is similar to the one described here https://blog.netnerds.net/2007/07/powershell-set-acl-does-not-appear-to-work/, but the solution does not resolve my issue.

below is the script i use.

$Folders = Import-csv -Path "D:\folders.csv" -header("Path","User","Permission","Rule")

 foreach ($row in $Folders)
 {
 ##Below I prepare my variables to be used.##

    $Path = $row.Path
    $User = $row.User
    $Permission = $row.Permission
    $Rule = $row.Rule

# Check if the folder Exists

    if (Test-Path $Path) {
        Write-Host "Folder: $Path Already Exists" -ForeGroundColor Green
    } else {
        Write-Host "Creating $Path" -Foregroundcolor Green
        New-Item -Path $Path -type directory | Out-Null
    }




    # Get ACL on FOlder

    $GetACL = Get-Acl $Path

    # Set up AccessRule

    $Allinherit = [system.security.accesscontrol.InheritanceFlags]"None"
    $Allpropagation = [system.security.accesscontrol.PropagationFlags]"None"
    $AccessRule = New-Object system.security.AccessControl.FileSystemAccessRule($User, $Permission, $AllInherit, $Allpropagation, $Rule)

    # Check if Access Already Exists

    if ($GetACL.Access | Where { $_.IdentityReference -eq $User}) {

        Write-Host "Modifying Permissions For: $User" -ForeGroundColor Green

        $AccessModification = New-Object system.security.AccessControl.AccessControlModification
        $AccessModification.value__ = 2
        $Modification = $False
        $GetACL.ModifyAccessRule($AccessModification, $AccessRule, [ref]$Modification) | Out-Null
    } else {

        Write-Host"Adding Permission: $Permission For: $User"

        $GetACL.AddAccessRule($AccessRule)
    }
    $GetACL = Get-ACL -Path $Path

     $GetACL.SetAccessRuleProtection($True, $False)

    $GetACL.AddAccessRule($AccessRule)

    Set-Acl -aclobject $GetACL -Path $Path

    Write-Host "Permission: $Permission Set For: $User" -ForeGroundColor Green
}

Thanks in advance for anny assistance.

Thabo.

VBscript for enable/disable windows-update sevice in domain network.

$
0
0

Hi,

Any one can share the VBscript for enable/disable windows-update sevice in our domain network.


Batch rename files

$
0
0

I wondered if someone could help me with the below...

I have around 25k video files in around 600 folders that I would like to batch rename.

The file names look like this:

file_20150101_dubai_2_27535.mp4
file_20150308_london_13_4_1_26893.mp4
file_20150103_london_12_1_24466.mp4
file_20150213_new_york_2_1296.mp4
file_20150709_abu_dhabi_7_3849.mp4
file_20150424_doha_1_12_10921.mp4
file_20151102_berlin_6_3_417.mp4

To simplify the file names I would like to keep just the video number (with the underscore) which is the string of digits just before the extension (_27535, _26893, _24466, etc...) and everything in front of the underscore replace with "video" word.

The final out put would look like this:

video_27535.mp4
video_26893.mp4
video_24466.mp4
video_1296.mp4
video_3849.mp4
video_10921.mp4
video_417.mp4

Regards

Max

PowerShell : Get MemberOf values for AD Group

$
0
0
I have a powershell script to give me the members of an AD Group, [get-distributiongroupmember AD_Group_Name], but I also want the code so I can get what Groups the AD Group in question also belongs to. This way when I re-create the group in question I can ensure it has all the correct members and is also a member of all the groups it needs to be.

Please advise.............

Jason

DriveSpec validation takes more than 20 seconds!

$
0
0

Hi Guys,

I use the following VBA code fragment to validate a user entry for a network share.  It generally works as expected.  When the entry is valid, the code executes without issue.  But, if the entered value for "ArchivePath" doesn't exist (or isn't reachable on my home network) execution of this little fragment takes more than 20 seconds!  To be sure, after the 20 second delay, it results in error 76 - Path not found - as I'd expect.

For clarity, mapped drive names validate quickly.  It appears that the long delay I experience occurs when using network share names.  For example: ArchivePath = "\\Archive\Share\" works just fine.  But, if I misspell the name (e.g. "\\Archvie\Shrae\") then the long delay occurs before the correct/expected error status is returned.

   Set fso = CreateObject("Scripting.FileSystemObject")
   On Error Resume Next
   Set d = fso.getdrive(fso.GetDriveName(ArchivePath))
   ValidateInputs = Err.Number
   On Error GoTo 0
   If ValidateInputs <> 0 Then ...

Is there any way to revise this validation logic to avoid the long delay when invalid data is provided?

Thanks,

cw

Get-DistributionGroup with managers and full name

$
0
0

Hello,

Our usernames in our AD are employee numbers. I am trying to get a report of all Distribution Group Owners with their FULL NAME. Not the employee number.

I am trying to use this script but it keeps erroring. Any ideas on how to do this? I need a simple Excel report. DistGroup name, and Owner Full Name. That is all

[PS] C:\Windows\system32>get-distributiongroup | ForEach-Object {$gname = $_.Name, $Manager = Get-AdUser $_.ManagedBy, $
ManagerName = $manager.DisplayName}
ForEach-Object : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by
 parameter 'Identity'. Specified method is not supported.
At line:1 char:39
+ get-distributiongroup | ForEach-Object <<<<  {$gname = $_.Name, $Manager = Get-AdUser $_.ManagedBy, $ManagerName = $m
anager.DisplayName}
    + CategoryInfo          : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.ForEachObjectCommand

[PS] C:\Windows\system32>

Event log archive script in progress

$
0
0

Below is the script followed by the error output... We do not want to use winzip (wzzip) we want to use the .zip program built within the Microsoft 2012 R2 OS yet I can not find a program name, switches, etc for this... any help would be great. Also What should I use besides "$output_path"

cd $output_path
$files_to_zip = dir "C:\Windows\System32\winevt\Logs\Archive-Security-*"
$zip_file_name = $output_path + $ENV:COMPUTERNAME + "_evts_" + $date_stamp + ".zip"
wzzip -whs -p -r -m $zip_file_name $files_to_zip

Start-Transcript question

$
0
0

This one is just too simple, but it isn't working for me.

I issue this cmdlet from within a script file.

Start-Transcript-Path$shareLogs\$computername.txt

It works fine if the output file name is not present.  The help file states "By default, if a transcript file exists in the specified path, Start-Transcript overwrites the file without warning."  But if the file is present, I get the error that Start-Transcript cannot start transcription.

Both variables are properly defined.  I'm opening a file on a share to which I have already connected.  I tried putting a -Force switch on just to see if that would make a difference, but it didn't.  (Didn't expect it to).


. : | : . : | : . tim

Help with trimming resulting text

$
0
0

Hello to all,

I need help with the following task. I interact with an application server name BigFix. In my environment this server is used for patch management tasks. This server creates these custom tasks or baselines to deploy patches. From these baselines I was able to extract the partial code below by using Powershell Select-String and a regex expression targeting the sha1 name. The regex for the sha1 is as follow "sha1:\b[0-9a-f]{5,40}\b" and the select-string I am using is the following: "Select-String -Path .\Customtaskfilename.txt -Pattern "sha1:\b[0-9a-f]{5,40}\b" -allmatches. As results I get hundred of lines of code similar to the sample below. I am interested in only two items the Sha1 value and the Windows KB file name but I cannot find a way to prune the code to obtain only those two items. I tried targeting multiple patterns by using array regex expressions but no luck. I alway land to a similar code as the sample below. My ultimate goal is to match the Microsoft KB filename with its respective sha1 value. Can that be done using PowerShell? 

Any help is much appreciated, please feel free to ask more information if my description of the problem is not as accurate I think it is.

Very Respectfully,

Alex 

Sample Code --------------------------------------------------------------------------------------------------------------------------

ActionScript MIMEType="application/x-Fixlet-Windows-Shell"><![CDATA[prefetch Windows6.1-KB2978742-x86.msu sha1:ad7b31025c839af6b6cc2da26cca3478e069bfc2 size:424414 http://download.microsoft.com/download/C/F/8/CF82AF63-21D4-4F6D-A5D5-A41720FF1B53/Windows6.1-KB2978742-x86.msu sha256:10e9726f2d39b442406714fcf3d2854693f554e0b124cab110829b2a2027feb0
-------------------------------------------------------------------------------------------------------------------------------------------


Alex Alas


Text Inside a file

$
0
0

I have an existing portion of a script that creates a .job file. It is scripted so that it lists the file path and the name of the file. What I would like to do is eliminate the file path and just put the name of the file inside the .job file. Any suggestions would be appreciated. 

Get-ChildItem -Path "\\jg.sgsystems.com\omafiles\ProductionDatabases\POM\TEST\*.pdf" | ForEach { [System.IO.File]::WriteAllText("\\jg.sgsystems.com\omafiles\ProductionDatabases\POM\TEST\" + $_.Name + ".JOB", $_.FullName)}

Here are the current contents of the .job file:

\\jg.sgsystems.com\omafiles\ProductionDatabases\POM\TEST\DOC011.P9999000.C0108.pomrpt.DAT.pdf

Here is the desired contents of the .job file:

DOC011.P9999000.C0108.pomrpt.DAT.pdf

Thanks again!

Powershell GUI to find and replace the text in wordfile

$
0
0

Hi

I am new user of Powershell script. I have managed to put together a script (from internet sources) that would find and replace the text in a word file using parameters. I have two parameters find (the text that has to be found) and filename (filename of the doc in which text has to be changed).

i am trying to create a GUI such that one can input the parameters like first filename of the word file and followed by find text and finally replace text.

here is the script i have so far.

Since the replace text is a path of the current folder i have my word document i used current directory to get the replace text (so i am not using it has a param)

for example find string is  "$tfs\try\find\release"

and replace string is "c:\documnet\files\myfile.doc"

param(
$Find,
$Myfilename
)
 
$CurrentDir = $(get-location).Path + "\" + $MyFileName

$objWord = New-Object -ComObject word.application
$objWord.Visible = $True
$objDoc = $objWord.Documents.Open($CurrentDir)
$objSelection = $objWord.Selection

$FindText = $Find
$ReplaceText = Split-Path -parent $MyInvocation.MyCommand.Definition
$ReplaceAll = 2
$FindContinue = 1
$MatchCase = $False
$MatchWholeWord = $True
$MatchWildcards = $False
$MatchSoundsLike = $False
$MatchAllWordForms = $False
$Forward = $True
$Wrap = $FindContinue
$Format = $False

$objSelection.Find.Execute($FindText,$MatchCase,
  $MatchWholeWord,$MatchWildcards,$MatchSoundsLike,
  $MatchAllWordForms,$Forward,$Wrap,$Format,
  $ReplaceText,$ReplaceAll)
     
If ($objSelection.Find.Found)
{
    Write-Host("The search text was found.") } Else {
    Write-Host("The search text was not found.") }

any help would be much appreciated.

Thanks,

SRIDAN

WMF 5.0 question

$
0
0

Good day,

I have a script that uses the "write-zip" cmdlet. This is a PSCX cmdlet. I downloaded the Pscx 3.2.0 and it says that the .msi fixes some issues with WMF 5.0 September release... What version of WMF 5.0 is released? Where is the download link? Does the most recent version of 5.0 already have the write-zip cmdlet?

If username starts with... logoff!

$
0
0

Hi there!

I need guidance to write a simple script.

Basically, during a logon:
"If user starts with XYZ, then logoff"

I could not find any example to help me :(

Thanks in advance!


Emilio MANSUR - MCSE:Security; MCSE+I, MCT - http://www.mansur.eti.br

Powershell script to gather failed logon attempts by event id and type from the security events log

$
0
0

I need to export the information from the Failed logins within the Domain Controller Security events log. I need to then export it into an excel spreadsheet. Anyone know where to start and should I be doing this via vbscript or Windows Powershell.

Viewing all 15028 articles
Browse latest View live


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