Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all 6937 articles
Browse latest View live

PowerShell 4.0 deployment

$
0
0

Every once in a while I’m asked how to deploy PowerShell in the enterprise, and my answer is always: “It depends”. - It depends on the target machine’s operating system, the PowerShell version you want to install, and if you already have a deployment mechanism.

Read More 


For Each Loop Collection and CSV Export

$
0
0

Need Help i have an account creation script and i am auditing/validating the account creation at the end. The script creates multip users i have the following so far.

foreach ($user in $Users)
{
Get-QADUser -Identity $user.saMaccountname -IncludeAllProperties |
Select displayname,samaccountname,employeeid,email,creationdate,accountexpires,homedirectory |
Export-Csv C:\NewHire\LOGS\consultantcreation-$date.csv -NoTypeInformation

}

I need to do this for each user but the out put needs to all go in to one csv file. Any Ideas right now it will generate csv file for each user.

is it possbile and how ?

$
0
0

hey everyone, I don't know if it possible but I am looking for a script to do the following

- read a txt file of computers

-get the BL pin for that system

-pause BL if its present

- read the AD computer object description field

then export all to a txt file.

it sounds possible but I have no idea where to start or if there is a script like that around the site I can use and mod. Help Please!! 

Powershell to append to an OOO that is already set

$
0
0

Hello,

I'm somewhat new to PowerShell.  I know how to Get and Set MailboxAutoReplyConfiguration.  What I need is a script that can Get the OOO and then Add additional text to it.  If one isn't set, then just add "I'm no longer working here"

I know it's along the lines of Get-MailboxAutoReplyConfiguration, If already set, then Export Username and OOO Message.  Else Set-MailboxAutoReplyConfiguration "I'm no longer working for XYZ Company"

I hope this makes sense.

Thanks in advance!

Uploading High Resolution User Profile Pictures to Office 365 Using PowerShell

$
0
0

This is where PowerShell comes in handy. Here are the instructions to upload high resolution user profile pictures to Office 365 using PowerShell commands:

Read More

Introduction to PowerShell for SharePoint 2013 -1 (Developer)

Introduction to PowerShell for SharePoint 2013 -2 (Administration)

how to install applications using PowerShell OneGet

$
0
0

For the ones who do not know yet, PowerShell oneGet is a tool that will allow you to manage, your applications on a machine using Powershell.

Read More


PowerShell: New-Password Function

$
0
0

OK, so I’ve been off the grid for a while now. But that doesn’t mean I’ve not been busy. Quite the opposite in fact. I’ve taken a year out from work on paternity with my baby Son. During this time, I did a lot of training in my lab developing new skills and solidifying other more fundamental skills. I’ve also passed a couple of certified exams and have built a new lab from a new HP Micro-server that I juiced up. I’m currently planning to take the MCSA: Server 2012 R2 exam and have been training in my lab and doing a lot of PowerShell DSC based automation. Hopefully I’ll be able to share some if not all of this knowledge and experience soon. I thought it best to return with a simple post so here goes.

Read More

Air jordan11代 supl vofc elwz

$
0
0

李振國說完後,整個證券部又是一陣哈哈大笑,呂天嬌羞惱地瞪了李振國一眼後說道:愛留 紐巴倫慢跑鞋就留著吧,最好 紐百倫紐款鞋子型錄 一輩子不要擦掉!說完轉身離開了證券部。看著恆生指數跌到了3108點的時候,證券部的經理問李振國是不是該開始逐漸地平倉了,但是李振國搖了搖​​頭說道:再等等看吧!最後在下午香港股市收盤時,恆生指數定格在3107點,一天重挫239點。

就在證券部的人都走掉時候,趙剛突然跑過來興奮地和李振國說道:總裁, 新百伦官网為前幾天的行為向 紐百倫紐款鞋子型錄 道歉!李振國微笑著搖了搖頭,淡然地說道: 紐百倫紐款鞋子型錄 以後好好地學習, 紐百倫紐款鞋子型錄 也可以的!就是李振國今天的一句話,使得趙剛rì後成為了李振國成立的金融特戰隊的一員。在最後證券部的一個人趙剛離開後,李振國一個人走到證券部的一間辦公室後,打開裡面早已準備好的電腦,進入倫敦國際黃金期貨市場。

李振國輸入密碼進入自己的賬戶, 紐百倫紐款鞋子型錄看了看今天世界各地期貨市場上的走勢圖,再看了看今天倫敦黃金的開盤價是405.15美元/盎。隨著今天聯合國發布的661號文件對伊拉克的製裁,而不是馬上出兵進行干預驅逐伊拉克軍隊離開科威特境內,隨著時間的推移,金融機構就會覺得短期內海灣地區不可能再發生大規模的戰爭,那麼 紐百倫紐款鞋子型錄 覺得黃金價格肯定就會有所回落。

Add users into AD Security Group

$
0
0

I need to add from a list of users to an AD security group.
I now work in a new company and no one know PowerShell (I'm so alone)

I've google and have come up with the script below.

My CSV will have a header called "SamAccountName" and the user ID's below it.

Here are my questions.

1. If the person is already a member, will the script continue to work?  If not how do I make it continue?
2. How can I capture errors and send them to a file
3. How can I capture successful adds to the group and send them to a separate file (preferred if not it can be the same as with the errors)
4. How can I capture statements indicating the user is already a member of the group
5. The script currently will show users added, however, will is show errors on the screen?
6. Any suggestions to improve the script?

*******Code*******

Import-Module ActiveDirectory
  $adGroup = "MyADGroup"
Import-Csv "C:\Scripts\Users.csv" | ForEach-Object {
 $samAccountName = $_."samAccountName"
 Add-ADGroupMember $adGroup $samAccountName;
 Write-Host "- "$samAccountName" added to "$adGroup
}

Thank you

 

 

 

 

LastLogonDate not reporting correct information

$
0
0

I have this code that works.  

$machine = (Get-ADComputer -Filter * -SearchBase "ou=acme_workstations,dc=acme,dc=org").Name

$objs = foreach ($pc in $machine) 

{Get-ADComputer $pc -Properties LastLogonDate | select name, LastLogonDate} $objs | Export-Csv -NoTypeInformation -Path "C:\temp\LastReboot.csv"

 

I read this about LastLogonDate:  Powershell was nice enough to give us a third option to query by.  LastLogonDate is a converted version of LastLogontimestamp.  He was technically right.  It’s not a replicated attribute.  Instead, it’s a locally calculated value of the replicated value.  Most importantly, it gives us the ability to query using human friendly date formats!! (taken from this web page: http://social.technet.microsoft.com/wiki/contents/articles/22461.understanding-the-ad-account-attributes-lastlogon-lastlogontimestamp-and-lastlogondate.aspx)

 

So I looked at my LastReboot.csv file.  I looked at machines that had a LastLogonDate of today, 5/6/2015.   Now, we have  GPO that runs a PowerShell script and this script will write to the registry.   I spot checked many of the machines that have a LastLogonDate of today and half did have the registry keys created by the PowerShell script but half did not.   So on the machines that did not have the registry keys I wrote ran this script against each.

 

$pc = Read-Host "Enter the machine name"

Get-WmiObject win32_operatingsystem -ComputerName $pc | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}

 

The lastbootuptime is not today on all of the machines I checked.  why?   How come LastLogonDate is not accurate?  Or should I be using a different AD attribute?   

Email notification

$
0
0

Hi everyone ,

I have been trying to follow the blog on this site to send emails to multiple users with no Success. I hope someone could offer me some advice on how to change my scripts.

Currently have email notification working fine for 1 user with this script:

#############################################################################
# Add function to send e-mail
#############################################################################
Function Send-Email([String] $smtpServer, [String] $from, [String] $to, [String] $subject, [String] $body, [String] $userName, [String] $password)
{

if ($userName.Length > 0 ) {

$credential=New-Object System.Net.NetworkCredential -argumentList $userName,$password
Send-MailMessage -From $from -To $to -Subject $subject -Body $body -SmtpServer $smtpServer -Credential $credential
}
else
{
Send-MailMessage -From $from -To $to -Subject $subject -Body $body -SmtpServer
$smtpServer
}
}

 

 

 

and define SMTP details here.

###########################################
# Define the default SMTP server
###########################################
$smtpServer="10.xxx.xx.01"
$fromAddress="yyyyy.pppppp.com"
$toAddress="xxxxxx.tttttt.com"
$smtpUserName=""
$smtpPassword=""

Would really appreciate any advice on how to change the above to allow me to send to multiple addresses. As I mentioned I have tried amending the script my self with 100% failure so far. :-(

Many thanks everyone.

 

Functions within start-job scriptblock

$
0
0

I'm working on a process to archive (7zip) eventlogs that are archived to a network share.  I'm doing this because we are required to keep a year's worth of logs and as we upgrade systems to 2012, the amount of data increases.

For instance, a year ago, our domain controllers generated 5-6 80MB security eventlogs each day.  Now, there are over 40 192MB files for each.  We've already had to expand our SAN storage - eventlogs alone take almost 5TB.

I digress....

To start with, I create a queue:

$queue=[System.Collections.Queue]::Synchronized( (New-Object System.Collections.Queue) )

Then add to it:

gci \\Server\EventArchive -include archive-security* -recurse|?{$_.lastwritetime -le (get-date).adddays(-305)|group-object {$_.directory},{$_.lastwritetime.year},{$_.lastwritetime.month},{$_.lastwritetime.day}

 

The 'where' clause is just to limit the number of files to process while I'm working on it.

My script - that works if I run it as ".\archive-logs.ps1 $queue.dequeue()" is:

Param($item)

$folder=$item.values[0].fullname

$server=$item.values[0].name

$year=$item.values[1].tostring()

$month=$item.values[2].tostring().padleft(2).replace(" ","0")

$day=$item.values[3].tostring().padleft(2).replace(" ","0")

$files=@($item.group.fullname)

c:\7zip\7z.exe a -stl -mx9 -sdel -ms=off "$($folder)\$($server)_Security_$($year)$($month)$($day).7z" @files

 

If I run this in a background job, it seems that it loses where the files are.  In the job results, I get access denied errors point to "My Music" and other folders under my profile.

Where might this be reverting to looking in my profile?  I've tried using:

Start-job -filepath c:\powershell\archive-logs.ps1 -argumentlist $queue.dequeue()

Start-job -scriptblock {[code from script]} -argumentlist $queue.dequeue()

Start-Job -initializationscript {$variable containing code from script} -scriptblock {$variable} -argumentlist......

 

Results are all the same.  It's obviously a scoping problem, but I'm having trouble narrowing it down.  For what it's worth, when defined as a function I use function global:archive-logs.....

 

 

not reading corrent OU

$
0
0

I am trying to find out the last time machines rebooted by reading the local WMI of machines in select OUs.  I have this code:

$machine = (Get-ADComputer -Filter * -SearchBase "OU=24 Carrol,dc=Acme,dc=org").Name

foreach($pc in $machine) {

Get-WmiObject win32_operatingsystem -ComputerName $pc | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}  

}

24 Carrol is a sub-OU under Acme_Workstations.   There are many other sub-OUs under Acme_Workstations as well.    OU-24 Carrol has 7 machines within it.    When I run the above code it returns information about computers in a totally different OU and in fact does not return any data about machines in 24 Carrol.   Why on earth would it do that?  

 

I then tried just this code

$machine = (Get-ADComputer -Filter * -SearchBase "OU=24 Carrol,dc=Acme,dc=org").Name

$machine

and it also fails.  it is reading an OU called '1355 Rowland"  so I thought it had something to do with 1 coming before 2 (1355 vs 24) but we have other OUs with lower numbers like 1100 Rowland and it is not reading those.  

Is our AD jacked up?   

 


Need help reporting errors in a column on a CSV file

$
0
0

Running a script that queries servers for Network info.

Currently the script suppresses errors. I would like to report the errors and include them in the CSV file.

The end goal is a csv like this:

CN            IP Address    Subnet Mask      Error

Server1     10.10.10.2    255.255.255.0
Server2                                                      Access Denied
Server3     10.10.15.5    255.255.255.0
Server4                                                      RPC Server is unavailable 

 

My first attempt was to add a Write-Warning but that didn't work out so well. I need to add another object for the Error column but the output of the Write-Warning "Error occurred: $_" gave me 5 columns of info (IsFilter, StartPosition, File, Attributes, Module)

 

Thank you for your help.  Much appreciated.

 

Script:

 

[cmdletbinding()]

param (

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

    [string[]]$ComputerName = $env:computername

)            

 

begin {}

process {

 foreach ($Computer in $ComputerName) {

  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

Try

{

$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer -ErrorAction Stop | ? {$_.IPEnabled} 

}

Catch {      

Write-Warning "Error occurred: $_"

}

{

continue

}

foreach ($Network in $Networks) {

    $IPAddress  = $Network.IpAddress[0]

    $SubnetMask  = $Network.IPSubnet[0]

    $DefaultGateway = $Network.DefaultIPGateway

    $DNSServers  = $Network.DNSServerSearchOrder

    $IsDHCPEnabled = $false

    If($network.DHCPEnabled) {

     $IsDHCPEnabled = $true

    }

    $MACAddress  = $Network.MACAddress

    $OutputObj  = New-Object -Type PSObject

    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

    $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress

    $OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask

$OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value ($DefaultGateway -join ",")

    $OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled

    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value ($DNSServers -join ",")

    $OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress

    $OutputObj

   }

  }

 }

}            

 

end {}

Compact and repair mdb file

$
0
0

Hi, 

I need to repair mdb file (msaccess) from Powershell script.

Anyone have done it before ? Any ideas ?

Thanks,

Didi

What is the PowerShell App Deployment Toolkit?

$
0
0

The PowerShell App Deployment Toolkit provides a set of functions to perform common application deployment tasks and to interact with the user during a deployment. It simplifies the complex scripting challenges of deploying applications in the enterprise, provides a consistent deployment experience and improves installation success rates.

Read More

Weekend Scripter: Using PowerShell to Replace STSADM

$
0
0

Just like many other Microsoft server applications, SharePoint has had a fair number of command-line interfaces for administrating the product. STSADM.exe was one of these command line tools. Since SharePoint 2010, Windows PowerShell has become the preferred command-line administration tool.  However, there are certain instances where Windows PowerShell does not provide an exact replacement for tools such as STSADM.exe. In this post, we will explore one such command (enumallwebs) and attempt to replace that functionality with a Windows PowerShell script.

Read More

PowerShell script example for copying correct configs based on server machine name in multi server environment

$
0
0

As a complement to the previous article on Extending EPiServer MSBuild config transforms to provide server specific configuration for TCP EventReplication and Licenses I wrote a small Windows PowerShell script example on how you may copy the proper configuration files to the proper server automatically during deploy. 

Read More

Viewing all 6937 articles
Browse latest View live