Archive

Archive for the ‘Script’ Category

Track Local Network Shares on SCCM 2007

Hi,

If you need to find all the local shares that users create on their computer this post might be good for you,

The first thing you need to do is to edit the sms_def.mof file for the client to start reporting of his local shares\

  1. Open the file …\Microsoft Configuration Manager\Inboxes\clifiles.src\hinv\sms_def.mof with your notepad
  2. search for   SMS_Group_Name (“Shares”), 
  3. You can change all the FALSE parameters to TRUE, or just the SMS_Report, Name and Path
  4. Now you need to wait, it can take some time that the client will start reporting about his shares

The second thing to do is to build a small report, you can use a basic report that show all the shares

SELECT TOP (100) PERCENT dbo.v_GS_SHARE.ResourceID, dbo.v_R_System.Name0 AS Hostname, dbo.v_GS_SHARE.Name0 AS ShareName,
dbo.v_GS_SHARE.Path0 AS Path
FROM dbo.v_GS_SHARE INNER JOIN
dbo.v_R_System ON dbo.v_GS_SHARE.ResourceID = dbo.v_R_System.ResourceID

Or you can use some filter to disable administrative shares

SELECT TOP (100) PERCENT dbo.v_GS_SHARE.ResourceID, dbo.v_R_System.Name0 AS Hostname, dbo.v_GS_SHARE.Name0 AS ShareName,
dbo.v_GS_SHARE.Path0 AS Path
FROM dbo.v_GS_SHARE INNER JOIN
dbo.v_R_System ON dbo.v_GS_SHARE.ResourceID = dbo.v_R_System.ResourceID
WHERE (dbo.v_GS_SHARE.Name0 NOT LIKE ‘_$’) AND (dbo.v_GS_SHARE.Name0 <> ‘admin$’) AND (dbo.v_GS_SHARE.Name0 <> ‘ipc$’)

I’m done here , on my next post I’ll show how to generate report of permission of those shares.

Advertisements

PowerShell: Get Active Directory groups membership for a user

22/10/2013 2 comments

Hi,

When you have to document every change  Because you’re committed to SOX regulation, you need to extract the data fast

This PowerShell script receive an AD username and export .csv with all Active Directory groups (for Fast Copy&Past).

import-module ActiveDirectory
$name = Read-Host ‘What is the username?’
$csvvv = “.csv”
Get-ADPrincipalGroupMembership $name | select name | Export-CSV ($name+$csvvv)

Save it as .ps1 and run it from the powershell command line,

Sending a reminder to users with password is about to expire (PowerShell Script)

11/07/2013 2 comments

One of the most annoying thing in user support is that they never notice the “consider changing your password” balloon, and sometimes they are locked out after their password expired,

To overcome this difficulty with users, I programmed This in PowerShell:

 

  • First, I pull out the users that their password ending soon –

import-module ActiveDirectory

$date1 = ((Get-Date).AddDays(-56)).ToString()
$date2 = ((Get-Date).AddDays(-61)).ToString()

//the default domain password expiration is 60 days

get-ADUser -server “YOURDC” -SearchBase “OU=Divisions,DC=DOMAIN,DC=COM” -Filter {(enabled -eq “TRUE”) -and (PasswordLastSet -lt $date1) -and (PasswordLastSet -gt $date2) -and (PasswordNeverExpires -eq “false”) -and (EmailAddress -notlike ‘\S’)} -Properties * | select EmailAddress, DisplayName, PasswordLastSet | Export-CSV c:\List1.csv

//Please notice that i export only 3 field for each user (EmailAddress, DisplayName, PasswordLastSet)

  • Now we delete the first row, and load the file into $list

get-content c:\list1.csv | select -skip 1| set-content c:\list2.csv

$list = import-csv “c:\list2.csv”

 

  • Now for the loop, it will go to each row and take the user information and send him an email to consider changing his password

ForEach ($row in $list) {
$Subject = “Dear “+$row.DisplayName+”, Your Domain Password Set On “+$row.PasswordLastSet+” And About To Expire”
$Body = “To change youre password press Control+Alt+Delete and choose Change Password `nThis is an automatic message, Please DO NOT reply ……”

send-mailmessage -to $row.EmailAddress -from “<me@domain.com>”  -subject $subject -body $body -smtpServer “smtp.domain.com”
}

You can consolidate all the script parts to one file .ps1 type

This is it, I hope you liked it….

Yair