Rāda ziņas ar etiķeti powershell. Rādīt visas ziņas
Rāda ziņas ar etiķeti powershell. Rādīt visas ziņas

otrdiena, 2019. gada 12. marts

Powershell script to Get all AD users in unicode UTF8 format



Script is mention to run on Domain Controller, otherwise you need to enable PowerShell and Import Active Directory Modules.
c:\temp directory must be created before running script
At first you need to read aut all properties to determine, which you want to see in final list.

Get-ADUser -identity giors -properties *|Export-CSV c:\tmp\giors.csv 

where giors is my username. I need to determine, which user accounts is expired so I add LastLogonDate and PasswordLastSet
Simple Export-CSV export in plain ANSI text, to convert to UTF8 add -Encoding UTF8

Get-ADUser -Filter * -SearchBase "DC=domain,DC=com" -properties *|select CanonicalName,SamAccountName,Name,LastLogonDate,LockedOut,PasswordLastSet,whenChanged|Export-CSV -Encoding UTF8 c:\tmp\allusersinUTF.
csv


trešdiena, 2018. gada 16. maijs

Get File Hash on Windows PowerShell

My instructions are for Windows 10, but I am sure it will work on every Windows wirh powershell.
It could be useful for security updates and suspicious executables.
Open PowerShell Windows key->Type PowerShell
Move to the folder where file are placed
cd c:\folder
where your file are located
Get-FileHash .\filename.extension -Algorithm SHA256
or 
Get-FileHash .\filename.extension -Algorithm SHA1
Lets say wou want to check Gimp downloaded in c:\temp
Get-FileHash -Path c:\temp\gimp-2.10.0-setup-2.exe -Algorithm SHA256

Thats it.

trešdiena, 2015. gada 3. jūnijs

MS SQL Express query changes of table and export to txt file and send by mail

Powershell script which makes sql query, compares result to previous result and in case of changes send result via mail. Link to ps1 file here. I have Microsoft SQL Express and a task to check one specific column and send message to security officer if column is changed. Because support are outsourced Database and server must be untouched as much as possible. SQL Express version does not have embedded mail sending and lot of other tools. If you want to do it via triggers, there are lot of .net functions that must be enabled and I am not sure is it really possible via sql express version.

ceturtdiena, 2013. gada 30. maijs

PowerShell script to show AD Domain group members

I needed a users in Active Directory Domain group, in nice columns, I did not found satisfactory examples so I had to write it myself. Besides I needed some properties of user. Command Get-ADGroupMembers <groupname> shows all standard parameters of user but I needed description and if user is enabled.


$Users = Get-ADGroupMember BLP_LDAP
foreach ($User in $Users)
{
 Get-ADUser $User.SamAccountName -Properties * | select Name,SamAccountName,Description,Enabled
}

ceturtdiena, 2013. gada 28. marts

How to add users to ou in domain via Powershell Windows 2008



Before to use PowerShell you have to allow powershell scripts via policy, while there are lot of policies I just allow scripts on separate DomainController with higher access restritions
So you have to type in  PowerShell terminal

Set-ExecutionPolicy Unrestricted

So here are powershell script itself

Import-Module ActiveDirectory 
$Users = Import-Csv -Delimiter ";" -Path ".\userslist.csv"  
foreach ($User in $Users)  
{  
    $OU = "OU=yourou,DC=yourdomain,DC=comorothersuffix"  
    $Password = $User.password 
echo $Password
    $SPassword = ConvertTo-SecureString $Password -AsPlainText -Force 
echo $SPassword
    $Detailedname = $User.firstname
    $SAM =  $User.Name 
    New-ADUser -Name $Detailedname -SamAccountName $SAM -DisplayName $Detailedname -AccountPassword $SPassword -Enabled $true -Path $OU  
} 

ceturtdiena, 2013. gada 14. marts

Powershell script ps1 to show inactive computer accounts in AD Active Directory


Today I needed a script to show inactive computers in Active Directory 2008, I found PowerShell script, but it shows active users so I changed filter from gt- greater that to lt- less than.


Import-Module ActiveDirectory

$today = Get-Date

$cutoffdate = $today.AddDays(-60)


Get-ADComputer  -Properties * -Filter {modifyTimeStamp -lt $cutoffdate} `
| Select Name,OperatingSystem,modifyTimeStamp,CanonicalName | Export-Csv C:\Users\Admgiors\Desktop\ActiveComputers.csv



Sory to say Anand  was wrong I dont know what MS people smoke but LastLoginDate shows First Login time.
Modified means computer password was changed. Computer account password expires in  2 months.

piektdiena, 2012. gada 16. novembris

Add bulk email addresses to users in Windows 2008 via PowerShell script

This script just add parameter email to every user in the csv list. Idea was taken from here http://social.technet.microsoft.com/Forums/en/winserverDS/thread/ade706c8-eef8-4c3a-b81d-e3af8677747b  I was looking for full solution and find this script, however there are not full description so I had to write my own, so here is full solution.

And script itself.

Import-Module ActiveDirectory 
$Users = Import-Csv -Delimiter ";" -Path ".\maillist.csv"  
foreach ($User in $Users)  
{  
    $POST = $User.Pasts  
    $SAM =  $User.Name 
    Set-ADUser -Identity $SAM -email $POST 
}

Script is looking for csv file in the same dirtectory where ps file. Dont forget to test user properties, whether email address appears. Of course, you can change other parameters too. Before run ps files on domain controller, security must be changed,