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

Powershell 'where is AD user logged on' script

$
0
0

I'm trying to create login script that writes computer name user is logged on in some (no matter which) aduser property. Idea was to use set-aduser cmdlet with admins creds stored in a file but there are numerous security risks coming from there. Is there a way to delegate adusers rights to powershell (i already did that for their own properties on AD). Or (maybe even better) does anyone have any better idea? This is more something of experiment and I really want to use powershell (I know there's a vbscript that does exactly the same thing i would like to do).

Thank you and best regards!


Restricting Concurrent Logons

$
0
0

HI guys

I have a query . i just want to know is there a script where user can logon to a said domain one at a time

note this is windows server 2008

kindly help .


the devil

Event Log Trigger on New-Mailbox Event in MSExchange Management Event Log and Email in HTML Format

$
0
0
I created a custom event view and created "Attach Task to this custom view" task scheduler job based on the custom view. Whenever a new user is created a receive the email however, the body of the email is blank. I'd like to pass the event detail into the body of the email as HTML. Any assistance on how to create a script to accomplish is much appreciated.

How would i modal an entire vbs script?

$
0
0

How would i modal this script? (i dont want it to be able to access any other programs when its running) heres the code

http://gyazo.com/6d9fc35c9bed8a12e5edfa8fdbc2f156

Invoke-Sqlcmd : Incorrect syntax near ','.

$
0
0

Hi,

I am new to Powershell and have been trying to find out why I am getting this error.

I have read everything on the internet blogs and couldn;t find my answer.

Any help would be appreciate.

The part that I made bold in the $SQLVALUES is where I think my issue might be. 

Here is my code:

 #Don't forget to add ResourceType column
 #also make sure you add the latest FTE estimate column to populate that and historical data
#Make all birthdays that weren't provided NULL
#Add-PSSnapin SqlServerCmdletSnapin100
#Add-PSSnapin SqlServerProviderSnapin100

$DATA=IMPORT-CSV "C:\Users\pzd74f\Downloads\StaffTrackingFTE2015.csv"
$startDate = Get-Date "02/01/2015"
FOREACH ($LINE in $DATA)
{
    $ResourceName=$Line.("Resource Name")
    $ResourceName = $ResourceName -replace "'", "''"
    $ResourceName="`'"+$ResourceName+"`'"
    $CatwName=$Line.("CATW Resource Name")
    $CatwName = $CatwName -replace "'", "''"
    $CatwName="`'"+$CatwName+"`'"
    $FunctionalArea = "`'"+$Line.("Functional Area")+"`'"
   
    $y = 1
    While ($y -ne 13)
    {
        if(($Line.("HRS"+$y) -ne "$null") -and ($Line.("HRS"+$y) -ne ""))
        {
            if(($Line.("FTE"+$y) -ne "$null") -and ($Line.("FTE"+$y) -ne ""))
            {
            $ExpHrs = "0"
            $ExpFTE = "1"
            $Hrs = ($Line.("Hrs"+$y))
            $FTE = ($Line.("FTE"+$y))
                if(($Line.("ExpHrs"+$y) -ne "$null") -and ($Line.("ExpHrs"+$y) -ne ""))
                {
                    $ExpHrs = $Line.("ExpHrs"+$y)
                }
                if(($Line.("ExpFTE"+$y) -ne "$null") -and ($Line.("ExpFTE"+$y) -ne ""))
                {
                    $ExpFTE = $Line.("ExpFTE"+$y)
                }
                $SQLHEADER=”Use SP2010_EDCStaffing_AppDB INSERT INTO [dbo].StaffTrackingFTEData ([StaffTrackingID],[EstimateHours],[EstimateFTE]," +
                "[ActualHours],[ActualFTE],[Period])"
               
                $SQLVALUES=” VALUES ((select [ID] from StaffTracking where CATWResourceName = " + $CatwName + " and ResourceName = " + $ResourceName +
                " and FunctionalArea = " + $FunctionalArea + "), " + $StaffTrackingID + ", "  +$ExpHrs + ", " + $ExpFTE + ", " + $Hrs + ", " + $FTE + ", "+ ($startDate.addMonths($y)).ToShortDateString() +")"
  
                $SQLQUERY=$SQLHEADER+$SQLVALUES
                Invoke-Sqlcmd –Query $SQLQuery -ServerInstance localhost
            }
        }
        $y = $y + 1
    }
}

Reading Data from CSV File and Setting Variables in script

$
0
0

I am trying to accomplish a task and i don't know where to start unfortunately, hope you can assist me in the task.
I have a CSV file with 2 columns and i what to set 2 variables in my script that is based on that file.
I want to search a string in the 1st column and then based on the result set the 1st variable to be the string that i found in the 1st column and the 2nd variable i need it to be the string in the 2nd column right next to it.
So if i search a string and found it in row 33 i wish that the 1st variable will be the string in line 33 column 1 and the 2nd variable will be the string in line 33 column 2. 
hope you can assist me \ direct me in the right direction...

thanks in advance for your help in this matter. Cheers, 
Maor Kuriel


Mkuriel

Calculate elapsed time with VBS/PowerShell

$
0
0

I'm trying to calculate MDT task sequence execution time. What could be the best method for this? It can be PowerShell or VBS code.

Plan is to execute a script at the beginning of a task sequence that stores a start time in variable and at the end of task sequence execute another script that reads that start time from variable and calculates total time taken and saves it to another variable.

I have tried few VB scripts but I have had some odd results some times with them. We are using 24 hour clock and it might have caused some problems for my previous scripts.

 


backup outlook rules and alert remotely throw Powershell

$
0
0

Hey, Scripting Guy!,

 

Related to this topic : http://blogs.technet.com/b/heyscriptingguy/archive/2009/12/15/hey-scripting-guy-december-15-2009.aspx

 

I know it’s really old, but I’m working on script now that I will use to migrate users from machine to another machine on my Domain

 

I know about USMT ,and how it’s able to do a lot of things in migration process, but PowerShell is the target J

 

Throw PowerShell I make a lot of other task J

 

Question:

Can I export Rules and Alert from a remote machine by PowerShell?  For ex. Save it to REG or RWZ file that I can import to another machine

 

PowerShell V2

If solution can be functions and call it in the script

 

Ex. Export-Rules  –computer $machine  –outlocation $location

 

 

Thanks a lot


<mytubeelement data="{"bundle":{"label_delimitor":":","percentage":"%","smart_buffer":"Smart Buffer","start_playing_when_buffered":"Start playing when buffered","sound":"Sound","desktop_notification":"Desktop Notification","continuation_on_next_line":"-","loop":"Loop","only_notify":"Only Notify","estimated_time":"Estimated Time","global_preferences":"Global Preferences","no_notification_supported_on_your_browser":"No notification style supported on your browser version","video_buffered":"Video Buffered","buffered":"Buffered","hyphen":"-","buffered_message":"The video has been buffered as requested and is ready to play.","not_supported":"Not Supported","on":"On","off":"Off","click_to_enable_for_this_site":"Click to enable for this site","desktop_notification_denied":"You have denied permission for desktop notification for this site","notification_status_delimitor":";","error":"Error","adblock_interferance_message":"Adblock (or similar extension) is known to interfere with SmartVideo. Please add this url to adblock whitelist.","calculating":"Calculating","waiting":"Waiting","will_start_buffering_when_initialized":"Will start buffering when initialized","will_start_playing_when_initialized":"Will start playing when initialized","completed":"Completed","buffering_stalled":"Buffering is stalled. Will stop.","stopped":"Stopped","hr":"Hr","min":"Min","sec":"Sec","any_moment":"Any Moment","popup_donate_to":"Donate to","extension_id":null},"prefs":{"desktopNotification":true,"soundNotification":true,"logLevel":0,"enable":true,"loop":false,"hidePopup":false,"autoPlay":false,"autoBuffer":false,"autoPlayOnBuffer":false,"autoPlayOnBufferPercentage":42,"autoPlayOnSmartBuffer":true,"quality":"default","fshd":false,"onlyNotification":false,"enableFullScreen":true,"saveBandwidth":false,"hideAnnotations":false,"turnOffPagedBuffering":false}}" event="preferencesUpdated" id="myTubeRelayElementToPage"></mytubeelement><mytubeelement data="{"loadBundle":true}" event="relayPrefs" id="myTubeRelayElementToTab"></mytubeelement>

DNS Scavenging Powershell v4 Remove-NetTCPIP

$
0
0

Hi all I am trying to remove unwanted IP from a simple  text file list

$list = gc "c:\list.txt"

$list

172.10.20.1
172.10.20.2
172.10.20.3


Get-Content $list | foreach {$list in $lists} | Remove-NetIPAddress

At line:1 char:36
+ Get-Content $list | foreach {$list in $lists} | Remove-NetIPAddress
+                                    ~~
Unexpected token 'in' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Anyone ideas please ?


Yasar

Using WQL "one-liner" to extract a value from the registry

$
0
0

Can I extract a value from the registry using a "one-liner" WQL command?  Something like the following:

Under root\default:StdRegProv

               SELECT <Data> FROM "HKLM:SOFTWARE\Toto\Version"

Please note that I am aware of how this is done via script.  The problem is that I'm using a management system (SCOM), which only allows me to supply a simple WQL query to perform my evaluation.

Thanks,


Larry

Vbscript to remotely enumerate software updates (SCCM 2007)

$
0
0

Hi

Im trying to create a VBscript to initiate enumerate software updates.

The below link has a code to do this locally.

https://msdn.microsoft.com/en-us/library/cc145902.aspx

Is it possible to get this done remotely via VBScript or even Powershell? Prefer Vbscript, as some of the servers I am targeting are Windows 2003.

What I am trying to achieve is, once we have deployed our monthly patches to the server and has been rebooted, I want to run a a script to confirm what has worked and not. The idea is for the script to remotely initiate a software scan cycle on a target machine. Then the script will remotely initiate the enumerate software updates. If the result shows that nothing is required, then its good. However, if it lists some updates are to be installed, then this machine will be flagged as non compliant.

Thanks,

DM

How to Print SQL Azure V12 current DB Utilization SIZE.

$
0
0

Hi,

After upgrading SQL Azure Server from V11 to V12, I am not able to Print DB Size..

$dbname =Get-AzureSqlDatabase -ConnectionContext "Server credential" 

Write-Output $db.SizeMB

In V11 I am able to print current utilized Size in MB but after V12 I am not able to Print.

Pwershell script to Copy Complex Data - Remote Computer

$
0
0

Hello Folks,

I hava large number of log copy tasks for many remote virtual machines.

Logs are splitted  in 2 locations

c:\Data\Folder1\Folder2\logs (this I manage to integrate in my script without issuse via copy option)

and

c:\Users\<Username>\AppData\Roaming\The SDK\log

For this second ones I need to ONLY copy the files for users logged on the 16/03/2015 and only the Log files from 16/03/2015

Does anyone have a sample that could do this work?

Thanks in advance

Viliam

scheduling a PS

$
0
0
what is the best way (specifically) to schedule a PS to run every hour from a Domain Controller?

SharePoint - adding permissions to folders and subfolders in library from AD user info and manager info

$
0
0

We have a migration project that we have been working on for a little while now where we pulled HR related documents for 770 past and present employees (155 present employees).  We took the data and created a folder structure via Vb script and loaded it all in on a share and transferred it to SharePoint.  The structure now in SP2010 is a site with one document library and folders for employees there with multiple sub folders for the document types (ie, insurance, appraisals, retirement, etc.).  Top folder as employee Lname, Fname MI then, Insurance - sub1, sub2; Appraisals - sub1, sub2.  What I am trying to accomplish is use Powershell scripting and query active directory, get the user's name and match it to the folder, apply read permissions to that folder and all sub-folders for that user, and then take the user's manager in AD and apply read permissions to only certain sub-folders. The manager for that persons manager should also have read permissions for the same information.  This is the setup:  

  1. Doe, John L - Read (USER) 
    --Insurance - Read (USER)
    --Appraisals - Read (USER, Manager1, Manager2)
    --Contact Info - Read(USER, Manager1, Manager2)

Permissions in the specific folders should look like the flow in an org chart of users and managers and I only need the permissions to be applied to the 155 users currently in AD.  I am still fairly new to PowerShell and I am not that great at scripting unless it comes to site or library operations in a SP farm.  I have never had to query AD for anything in a script.   I hope I explained everything well and someone can lead me to some topics or information for querying AD user attributes and\or applying user permissions to subfolders in a document library like this.  
Also, after I get this to work on the current folders in SharePoint, management wants me to write another script to automate the folder structure creation for new AD users and apply all correct permissions and other information.  FUN FUN!!


David Hood


How do you create a taskbar notification in vbscript/javascript?

$
0
0

Hello.

I have been tasked with making a simple script that (among more interesting things) tosses a message to the user in a manner similar to the partial screenshot below:

Said script must work on machines that do not (and possibly cannot) have Powershell/Python/Perl/etc. installed. (which is why I am hoping for a vbscript/javascript method)

Thanks.

EDIT:  Ok, as it turns out, pasting a partial screenshot into the editor doesn't save, so here's a random one from the internets...

http://assets.paessler.com/common/img/manuals/ipcheck/en/image99_35.png

Script for Profile deletion

$
0
0

Below is my profile deletion powershell script,which should delete profile older then 7 days but on testing I found lots of error.

$path = "c:\users\"
$today = get-date
$folders = Get-ChildItem $path | where { $_.VersionInfo -notlike "File*" }
foreach ($folder in $folders)
{
    $start = $folder.LastAccessTime
    $age = (new-TimeSpan -start $start -end $today)
    if (($age.days) -gt "7" )
    {
        $rempath = "$path"+"$folder"
        Write-Host "$rempath to be deleted"
        # Uncomment below to remove items - otherwise list only
        Remove-Item $rempath  -recurse -force -Exclude Public
   
    }
    else
    {
        # Do Nothing
    }
   
}

Initial error was cannot delete C:\USers\..\Appdata as access denied. Then when I tried to delete it manually I get an error saying "The source files are larger then is supported by the File System. Try moving to a location which has shorter path name, or try renaming to shorter name(s) before attempting this operation"

Wondering how can we get this accompolished. Not that good in scripting, but try to get thing from here and there and manage to write some.

Any help on this will be highly appreciated.

Looking for a command to delete mx record from DNS

$
0
0

Hello,

I'm currently writing scripts to manage our public DNS Server but i'm now blocking on a script to delete mx record.

let's say i have a domain contoso.com

i have 2 mx Records for contoso.com

one with preference 10 pointing on mail1.contoso.com

and one with preference 20 pointing on mail2.contoso.com

if i use this command line :

Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "MX" -Name "@"  -Force


i can delete the two MX records at once

But i would like to be able to choose witch MX Record i want to delete.

i tried this command to delete the second MX record:

Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "MX" -Name "@" -RecordData "mail2.contoso.com"  -Force


but it ends with an error 

InputObject for resource record has an invalid value. Failed to remove the resource record on dns1.contoso.com server. Please check extended error for additional details.+ CategoryInfo          : InvalidData: (dns1.contoso.com:root/Microsoft/...rResourceRecord) [Remove-DnsServerResourceRecord], CimException+ FullyQualifiedErrorId : WIN32 13,Remove-DnsServerResourceRecord+ PSComputerName        : 10.0.0.10

has anyone an idea that could help ?

Thank you 

StephaneDe


Search for Keyword using powershell

$
0
0

Hello -

I have given a task to create a script that checks SQL scripts for strings and will give me the list of sql scripts that have the strings detected.

Currently, my CheckScript is as follow:

Get-ChildItem "D:\IDs" -recurse | select name >> "D:\CheckDBScripts\Schema.txt"

Get-ChildItem "D:\IDs" -recurse | Select-String -pattern "DROP TABLE|SCHEMA" -exclude "DROP TABLE #[A-Z]" | group path | select name >> "D:\CheckDBScripts\Schema.txt"


But this doesn't work.  Eventually, I would like to be able to search for Create, Alter, and excluding any temp table creation, deletion, and alteration.

Please advise.

Thank you!

Powershell Script in WinPE "Property cannot be found" problem

$
0
0

Hi Im trying to run the following powershell script in WinPE while doing an SCCM OSD and am getting an error. The script is as follows:

***********

$drive = gwmi Win32_Volume | where {$_.DriveLetter -eq ""}

$drive.DriveLetter = "Z:"

$drive.Put()
***********

The script is supposed to select the volume that has a blank drive letter then sets it to Z:.

When running the second line I get an error "The property 'DriveLetter' cannot be found on this object"


Any ideas??

Viewing all 15028 articles
Browse latest View live


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