sometimes you need to check does a server has a update, here the powershell script:
param ($myServer,$myHotFix)
$kb=$false
$myKBs=icm $myServer {get-hotfix}
foreach ($item in $myKBs)
{
if ($item.HotFixId -eq $myHotFix){
$item
$kb=$true}
}
if ($kb -eq $false) {write "No such KB"}
It can be checked from one line:
icm "servername" {get-hotfix|where {$_.HotFixId -eq "KBnumber"}}
Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts
Tuesday, May 17, 2016
Monday, February 08, 2016
Install .Net 3.5 on Windows 2012 R2 server
To install .Net 3.5 on Windows 2012 R2 server you need to mount Windows
2012 R2 dvd and point installation on "dvd"\sorce\sxs directory - in
Powershell it will be like this:
Add-WindowsFeature NET-Framework-Core -Source d:\sources\sxs
Tuesday, February 02, 2016
Make-USB-Bootable
# Before running the
script check USB key disk number with get-disk command, run the script from
# elevated shell
# tested only on
Powershell version 5.
# after you can use
robocopy to copy whatever you want to boot, the command options will be:
# robocopy
"source" "destination" /mir /xd "System Volume
Information" "$Recycle.bin"
param($disk_number,$DriveLetter)
Clear-Disk -Number
$disk_number -RemoveData
New-Partition
-DiskNumber $disk_number -UseMaximumSize -IsActive -DriveLetter $DriveLetter
Format-Volume
–FileSystem NTFS –DriveLetter $DriveLetter
set-location
$env:windir\system32
.\bootsect.exe /NT60
($DriveLetter+":")
Thursday, January 28, 2016
Dismount VM's DVD on Hyper-V Cluster
$myNodes="node1","node2","node3"
foreach ($node in $myNodes)
{
$dvd=get-vm -ComputerName $node |Get-VMDvdDrive
foreach ($item in $dvd)
{
if ($item.path -ne $null)
{
$myDVD=[array]$myDVD+$item
}
}
Foreach ($item in $myDVD)
{
Set-VMDvdDrive $item -path $null
}
}
foreach ($node in $myNodes)
{
$dvd=get-vm -ComputerName $node |Get-VMDvdDrive
foreach ($item in $dvd)
{
if ($item.path -ne $null)
{
$myDVD=[array]$myDVD+$item
}
}
Foreach ($item in $myDVD)
{
Set-VMDvdDrive $item -path $null
}
}
Wednesday, October 23, 2013
Powershell script to copy selected directories with use of robocopy
#The script to
Archive files from one share to another depending from the file last write time
(preserving the source directory structure and security)
$mySourceRoot="source
directory"
$myDestRoot="destination
directory"
set-location
$mySourceRoot
$myDir=Get-ChildItem
$mySortDir=@()
foreach ($arg in
$myDir)
{
$myType=$arg.GetType()
#write $arg.LastWriteTime
if ($mytype.Name -eq
"DirectoryInfo")
{
if ($arg.LastWriteTime -lt (get-date
2009-01-01))
{
write $arg.Name $arg.lastWritetime
$mySortDir=$mySortDir+$arg
}
}
}
set-location
c:\windows\system32
foreach ($arg in
$mySortDir)
{
$myPath=$arg.FullName
$myDestPath=$myPath.Replace($mySourceRoot,$myDestRoot)
.\robocopy.exe $myPath $myDestPath /mir
/sec /r:0 | Out-Null
}
Wednesday, October 17, 2012
Windows 7 Folder Redirection rename the Home folder in "My Documents
PowerShell script to fix the problem:
$myLocations="\\share1\allusers","\\share2\users","\\pshare3\AdminUsers"
foreach ($loc in $myLocations)
{
set-location $loc
$items=Get-ChildItem
foreach ($item in $items)
{
if ($item.getType().name -like "DirectoryInfo")
{
cd $item.name
if (test-path desktop.ini) {del .\desktop.ini -force}
cd ..
}
}
}
$myLocations="\\share1\allusers","\\share2\users","\\pshare3\AdminUsers"
foreach ($loc in $myLocations)
{
set-location $loc
$items=Get-ChildItem
foreach ($item in $items)
{
if ($item.getType().name -like "DirectoryInfo")
{
cd $item.name
if (test-path desktop.ini) {del .\desktop.ini -force}
cd ..
}
}
}
Friday, September 28, 2012
PowerShell - get users from OU
$ulist=get-aduser -filter * -SearchBase "ou=?,dc=?,dc=?"
foreach ($user in $ulist)
{
$user.samaccountname
add-content -path c:\temp\?.csv $user.samaccountname
}
foreach ($user in $ulist)
{
$user.samaccountname
add-content -path c:\temp\?.csv $user.samaccountname
}
Wednesday, August 15, 2012
SharePoint Search problem after migration
After migrating from WSS 3.0 to Foundation 2010 cannot search inside a document.
Basically it shows in the document property "Pending", so the document waiting for approval.
Created a small PowerShell script to approve all documents on a site:
________________________________________________________________________
Basically it shows in the document property "Pending", so the document waiting for approval.
Created a small PowerShell script to approve all documents on a site:
________________________________________________________________________
$mySite=Get-SPSite
"http://yoursite"
$myWebSub=$mySite.AllWebs
foreach
($myWeb in $myWebSub)
{
$myWeb=Get-SPWeb $myWeb.url
$myWeb.url
$myLIb=$myWeb.lists|where {($_.BaseTemplate
-eq "DocumentLibrary")}
foreach ($lib in $myLib)
{
$lib.Title
$myDocs=$lib.Items
foreach ($doc in $MyDocs)
{
$doc.name # only for information
$doc.file.level # only for information
if (($doc.file.level -eq
"Draft") -or ($doc.file.level -eq
"Pending")){$doc.file.Approve("script")}
$doc.file.level # only for information
}
}
}
Friday, April 06, 2012
Powershell script to enumerate SMTP addreses and alieses
I used the script to collect the information from Exchange 2003 for migration to Exchange 2010, but it can be used for collecting the information from Exchange 2010 (but it can be easy done with Poweshell snapin for Exchange). For setup PowerShell environment for Exchange 2010 you can try my blog page powershell-ms-exchange-part1.
To view the script click on "Read More"
Sunday, March 04, 2012
Exchange 2003 Powershell - Mailbox size
Really good script:
#
Author: Steven Peck - #">www.blkmtn.org
# Date:
06/15/2007
# Description:
Exchange 2003 output to file
#
Display Name, Store, Storage group, MB Size, and Date Absent in DS
# Changed by Boris Sirotin 3/4/2012 to include
external parameters for possible 3 exchange servers
#The syntax will be: .\thescriptname
server01 server02 server03
# Get date for file name
param ($server01,$server02,$server03)
$day = Get-Date -UFormat "%Y%m%d"
# Gets data through WMI from specified Exchange
mailbox servers
$computers = $server01, $server02, $server03
#
foreach ($computer in $computers) {
Get-Wmiobject -namespace
root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $server01 |
sort-object -desc MailboxDisplayName `
| select-object
MailboxDisplayName,StorageGroupName,StoreName,Size,DateDiscoveredAbsentInDS |
Export-Csv -Path c:\temp\$computer-$day.csv
}
Wednesday, February 29, 2012
PowerShell Exchange 2010 prerequisite script
Very good script for Exchange 2010 features installation:
http://www.ehloworld.com/152
http://www.ehloworld.com/152
Monday, July 12, 2010
PowerShell SharePoint 2010 Backup
I need to schedule SharePoint 2010 Backup (site):
First create a PowerShell script in Notepad:
Backup-SPSite -Identity http://wss-08r2 -Path "\\servername\sharepoint2010\one\wss-08r2.bak" -Force
First create a PowerShell script in Notepad:
Backup-SPSite -Identity http://wss-08r2 -Path "\\servername\sharepoint2010\one\wss-08r2.bak" -Force
name the file - backup.ps1
Second:
Under folder C:\Windows\System32\WindowsPowerShell\v1.0 create profile.ps1 file it will be default profile for all users on the SharePoint front end server, edit the file by adding -
Under folder C:\Windows\System32\WindowsPowerShell\v1.0 create profile.ps1 file it will be default profile for all users on the SharePoint front end server, edit the file by adding -
Add-PSSnapin Microsoft.SharePoint.PowerShell
And save the file.Third:
Create a scheduled job and in Action tab put:
Action: powershell.exe
Add arguments: -command "PATH\backup.ps1"
where is PATH - path to the script file.
Subscribe to:
Posts (Atom)