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

backing up event logs, then send to a choice of two central servers, based on site.

$
0
0

Hello,

here goes. I need a PS script to backup event logs of windows 2008R2 servers and Win7 clients. Once backed up, based on which site the host is in, send to the central server in that site. If down, send to the other site. The hostname has the site ref in the name. eg Site1Host1, send to Site1CentralLogServer, if down send to Site2CentralLogServer. So there are many stages of the script, which in total, is beyond me.

I have used this so far (found on net) for the backup of the logs:

 

Function Clear-Eventlogs {            

 Param(

  $Computername = $ENV:COMPUTERNAME,

  [array]$EventLogs = @("application","security"),

  $BackupFolder = "C:\BackupEventLogs2\"

  )            

 Foreach ( $i in $EventLogs ) {

If(!( Test-Path $BackupFolder )) { New-Item $BackupFolder -Type Directory }

 $eventlog="c:\BackupEventLogs\$i" + (Get-Date).tostring("hhmm_ddMMyyyy") + "_" + $Computername + ".evt"

 (get-wmiobject win32_nteventlogfile -ComputerName $computername |

  Where {$_.logfilename -eq "$i"}).backupeventlog($eventlog)            

 Clear-EventLog -LogName $i            

 } end Foreach            

}end function            

Clear-Eventlogs

 

I still have to find a way to determine the central log server and then the best way to send the evt files......

Any help would be really appreciated, as I am only used power shell for basic stuff..

 

thanks

 

 


Rename multiple files based on their content

$
0
0

I am very much novice on powershell but I am trying to find(learn) a solution in powershell to rename several text files based on their content:

For eg:

I have a file with content in first line something like: CAT35;BAT46:A;RABBIT36:B;DOG32:C;SN00014,

I need to rename the file based on its content from 2nd (only alphanumeric: BAT45 from above example) and anything on last column before comma(SN00014 from above example) in its first line. So new name of the file should be BAT45SN000014.txt. (probably I need to use regex here).

Thank you very much for any help,

JBR

Script for NAV 3-tier troubleshooting (PowerShell)

$
0
0

This PowerShell script is designed to help troubleshooting Dynamics NAV 3-tier installations by extracting the information that is typically used, rather than looking around in Active Directory to find it manually.

Read More

Windows Server 2012 Users Should Not Uninstall .NET Framework

$
0
0

Microsoft this week warned Windows Server 2012 users against uninstalling older .NET Framework versions.

For organizations upgrading their servers, removing the old .NET Framework might seem like the right thing to do. In some cases, removing it may be listed as a requirement by Microsoft in order to use Windows Server 2012 and Window Server 2012 R2. However, Microsoft's support team is saying that IT pros just shouldn't do it.

Read More

powershell script to remove duplicate key

If Statement to Return No User Logged in on Remote Computer

$
0
0

I've been struggling with this one and need some help. The Get-WmiObject command below returns the DOMAIN\Logged_In_User on a remote computer. I would like an "If Statement" to return "No Logged User" if there are no user logged in on the remote computer.

#Provide Custom Code for events specified in PrimalForms.
$btnStatus_OnClick=
{
#TODO: Place custom script here

$sBar.Text = $txtComputer.Text + ": " + (GetStatus($txtComputer.Text))


$lblRunningAs_DATA.Text = Get-WmiObject -computername $txtComputer.Text -class win32_computersystem | select -ExpandProperty username


}

Powershell Goodies

$
0
0

If you haven’t seen some of the other blog post, or the Microsoft Powershell Blog, Microsoft recently release Script Browser  for Powershell ISE.   This little addin allows you to quickly search and import Powershell scripts directly from TechNet Script Center.     Currently the database section has 577 scripts in the repository, with over 9100 in the total repository.  There’s a pretty good chance that someone has a script for what you want to do.  Alternatively, if you are just getting started with Powershell, this is a great way to review others scripts and learn.

Read More

Extracting Specific String that follows known text

$
0
0

I have a string of text in a file that looks like this (without the extra row space):

{"id":"https://logme.com/id/00DG000000ph8qkrAA/005G00000048CX6IAn","issued_at":"1398557853700","token_type":"Bearer","instance_url":"https://mycompany.my..com","signature":"Oo8VCM9LYJmGEl01VPyJ0OKHbrtsbIsx+LpUCxF8pHU=","access_token":"00DG0000000h8qk!AQQ1QNYIbEAjB63lLkRAA7LsOudy0BoS06K7M08bX2Wm_KXufLA1CHiSet1WStyNSwRlBk38sWQYF6ZIVrrKG5g1CdiHxU_U"}

 

I need to be able to extract JUST the text that follows "access_token": that is in quotes, ie,  

"00DG0000000h8qk!AQQ1QNYIbEAjB63lLkRAA7LsOudy0BoS06K7M08bX2Wm_KXufLA1CHiSet1WStyNSwRlBk38sWQYF6ZIVrrKG5g1CdiHxU_U"

 

I have this code currently to reorganize it:

$header = "ID", "Issued At", "Token Type", "Instance URL", "Signature", "Access Token"

cat token.txt

$t = import-csv token.txt -header $header

$t > token.txt

cat token.txt

------

ID           : {"id":"https://login.salesforce.com/id/00DG0000000h8qkMAA/005G00000048CX6IAM"

Issued At    : issued_at:"1398557853700"

Token Type   : token_type:"Bearer"

Instance URL : instance_url:"https://hpservice.my.salesforce.com"

Signature    : signature:"Oo8VCM9LYJmGEl01VPyJ0OKHbrtsbIsx+LpUCxF8pHU="

Access Token : access_token:"00DG0000000h8qk!AQYAQNYIbEAjB63lLkRAA7LsOudy0BoS06K7M08bX2Wn_KXufLA1CHiSet1WStyNSwRlBk38sWQYF6ZIVrrKG5g1CdiHxU_U"}

but it is not getting me to what I need, which is just that last bit, in a file, WITHOUT the quote (the access token).

 

Any hits on how to extract code "after" a matching, known string?

 

thx

pk

 


copy-item fails

$
0
0

$grab = get-childitem "C:\Temp" -recurse | where {$_.extension -eq ".txt"} | % { Write-Host $_.FullName } 

 

 foreach ($item in $grab) {Copy-Item $item -destination "c:\Find"}

 

When I run that above script it fails with this error.

Copy-Item : Cannot bind argument to parameter 'Path' because it is null.

 

If I Remove the $grab = and the foreach line then it works fine and returns all of the .txt files I have in my c:\temp folder.   

 

What did I do wrong?

 

Formating Word Document

$
0
0

I have a simple script that adds a title, date and sample table.  I can align the title and date but once I apply a style to the table I would like  to center the table.  I have tried to find the properties/methods for this to no avail.  See below:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

$fDATE = Get-Date -Format "dddd, MMMM dd,yyyy"
$word = New-Object -ComObject word.application
$word.visible = $true
$word.application.DisplayAlerts = 0
$doc = $word.documents.add()
$selection = $word.selection
$selection.Font.Name = "Arial"
$selection.Font.Size = 14
$selection.Font.Bold = $true;
$selection.typeText("This is a Test")
$selection.paragraphFormat.Alignment = 1
$selection.TypeParagraph()
$selection.Font.Name = "Arial"
$selection.Font.Size = 10
$selection.paragraphFormat.Alignment = 2
$selection.Font.Bold = $false;
$selection.TypeText($fDATE);$selection.TypeParagraph()
$selection.Font.Name = "Arial"
$selection.Font.Size = 11
$selection.paragraphFormat.Alignment = 1
$selection.TypeParagraph()
$number_Of_Rows = 3;$number_Of_Columns = 3
$paragraph = $doc.Content.Paragraphs.Add()
$Range = $paragraph.Range
$Table = $doc.Tables.Add($Range,$number_Of_Rows,$number_Of_Columns)
$Table.Borders.Enable = $true;$Table = $doc.Tables.item(1)
$Table.Cell(1,1).Range.Text = "COL 1"
$Table.Cell(1,2).Range.Text = "COL 2"
$Table.Cell(1,3).Range.Text = "COL 3"
$Table.Cell(2,1).Range.Text = "A Value"
$Table.Cell(2,2).Range.Text = "B Value"
$Table.Cell(2,3).Range.Text = "C Value"
$Table.Cell(3,1).Range.Text = "D Value"
$Table.Cell(3,2).Range.Text = "E Value"
$Table.Cell(3,3).Range.Text = "F Value"
$Table.AutoFormat(19)
$selection.EndKey(6,0)

Unable to update to Powershell 4

$
0
0

I have windows 8 pro but I am not able to update. Why?

My OS is in Spanish Language and I downloaded

Windows8-RT-KB2799888-x64.msu (recommended)      17.5 MB

and the result is:

the update does not apply to equipment

 but my version of powershell is 3.0

 

Home drive and looking for blanks

$
0
0

Back again, with a change of direction. Another project has befallen me. Id rather take a ring to Mordor to be honest. LDAP is useful but so unreadable so again i look to powershell.

from many thousands of users i would like to find all ad users in a certain OU without a profile path set.

Using get-QADUser -searchroot i gather all the people/items. and i see i can filter them however this seems backwards to me. would it not be better to get all users without the path rather than all users then filter. can it be done?

tried test path home drive doesnt work and -filter "" doesnt work 

Feeling woefully inadequate. Been here 6 months now i should have powershell down to an art...

or not

 

Windows PowerShell 4.0 Quick Reference Guides are Available for Download

$
0
0

Are you a frequent user of PowerShell, but always find yourself wishing you had a great quick reference sheet available? Then you will definitely love this bit of news! Microsoft has released an updated set of PowerShell quick reference guides so that you always have the information you need within easy reach!

Read More

Creation of Ad users

$
0
0

Gentlemen,

This little script is working however the password and the user wont be "enabled" and "pswd never expires" won't be true after running script, could you please drop me a hint why?


The code:
Import-CSV c:\Scripts\Content.csv | New-ADUser
 -EmailAddress $_.EmailAddress
 -GivenName $_.GivenName
 -Surname $_.Surname
 -DisplayName $_.DisplayName
 -Name $_.Name
 -SamAccountName $_.SamAccountName
 -Description $_.Description
 -Department $_.Department
 -EmployeeID $_.EmployeeID
 -Path $_.Path
 -Password $_.Password
 -Enabled $True -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force)
 -PasswordNeverExpires $true

Example of the CSV file:
GivenName,Surname,Name,DisplayName,SamAccountName,Description,Department,EmployeeID,Path,Enabled,EmailAddress,Password,PasswordNeverExpires
First01,Secon01,Player01,Incredible_Hulk,Player01@uku.group,Player,Psngame,12312,"OU=TestUsers,DC=psn,DC=group",$True,hello01@psn.group,p@ssword,$True

get data on same line

$
0
0

I have this code.

 

 

$OSDArchitecture = "OS Architecture"

$GetInfo1 = (get-ItemProperty hklm:\SOFTWARE\Microsoft\MPSD\OSD).OSDArchitecture 

Echo $OSDArchitecture  $GetInfo1 >> "c:\windows\MGH\BuildLog.txt"

 

It works but when it writes to my .txt file it write the data line this.

OS Architecture

x86

I want it to write like this:
OS Architecture  x86
how do you format that?

 


Cannot Set-AdUser -Manager due to "user must change password at next logon"

$
0
0

Hi.

I have about 200 users who haven't changed password yet.

I have made and testet a script that sets the Manager for all users. For some reason the script cannot find the Manager for the 200 users that have the "user must change password at next logon" set.

I also noticed that the "Get-Aduser -Identity johnDoe" returns "Cannot find an object with identity: JohnDoe under 'dc,=xxx'

However, if I remove the "user must change password at next logon" in dsa.msc + press ok and then set the "user must change password at next logon" again, then I can suddenly FIND the user with the "Get-AdUser -Identity JohnDoe".

Company policy does not allow me to remove all "user must change password at next logon" for users found with the command "Get-ADUser -Filter {pwdLastSet -eq 0} | Select-Object SamAccountName,Name". I also do not understand how powershell can return correct values here (John Doe) and and at the same time cannot find a specific user eg JohnDoe.

Any suggestions?

Regards the PS newbee

Invoke Command = Press Enter on an EXE

$
0
0

Hi there

I'm calling an exe via powershell using the Invoke command and i seem to get error one machine and not the other. The only difference i can see is the Program Files path

This works

Invoke-command -computername $server -ScriptBlock `

               { write-host "Server : $env:computername" 

   & "C:\Program Files\APPS\Desk Move Watch Service\DeskMoveWatchService.exe"

$wshell = New-Object -ComObject wscript.shell;

$wshell.AppActivate('Apps.Systems.DeskMoveWatchService')

Sleep 1

$wshell.SendKeys('~')

} -credential $cred -erroraction 'stop' 

---------------------------------------------------------------------------------------------------------------

But this doesn't

Invoke-command -computername $server -ScriptBlock `

               { write-host "Server : $env:computername" 

   & "C:\Program Files (x86)\APPS\Desk Move Watch Service\DeskMoveWatchService.exe"

$wshell = New-Object -ComObject wscript.shell;

$wshell.AppActivate('Apps.Systems.DeskMoveWatchService')

Sleep 1

$wshell.SendKeys('~')

} -credential $cred -erroraction 'stop' 

 

Please could anyone share some advise

Trying to invoke script from two levels up

$
0
0

I need to execute a script that is in a path structure that is two folders up (back) from my current location.  I can not move either script.  I have tried

invoke-expression -command ".\<script name> with params but get an error saying <script name> is not a cmdlet.

can I use ..\..\?  what is the correct format?

Thanks

Use PowerShell Remoting to Manage SQL Servers Efficiently

$
0
0

In all the years I've worked as a server administrator, I've always logged into each server I work on to gather data or make changes. On Windows servers, the standard way to do this is to use Remote Desktop (RDP), which gives you keyboard and monitor access to the server, and allows you to get work done. Sadly, this method has two problems: (1) only two people can be connected via RDP to any server at one time; and (2) the resources used by RDP are enough that performance of the server can be affected.

Read More

Powershell SQL

Viewing all 6937 articles
Browse latest View live