Показаны сообщения с ярлыком PowerShell. Показать все сообщения
Показаны сообщения с ярлыком PowerShell. Показать все сообщения

2009/12/23

Delete the WSUS Client ID's from registry by Powershell script

CURRENT CONFIGURATION: Microsoft Windows 2003 with Powershell 1.0; WSUS 3; OS distribution method is cloning (imaging) of computers or virtual machines copying.
OBJECTIVE: Fix the issue with computer name overlapping in WSUS
ISSUE: Computers override each other or not appear in WSUS console.
SOLUTION: When you clone (re-image) new computer from different either disk or clone image WSUS Client ID would be the same for either both or all recloned (reimaged) computers.
I wrote Powershell script to delete WSUS client ID's in registry.
DeleteWSUSid.ps1
# *****************************************************************************
# Windows Powershell script
# Author:  Vadim Zenin http://vadimszenins.blogspot.com
# Version:  1.00
# Date:     27/11/2009 13:47:06
# Purpose: Delete the WSUS Client ID's from the registry.
#
# Do not forget: Set-ExecutionPolicy RemoteSigned
#
# Arguments:
#
# Tested platform:
# Windows Powershell v 1.0,
# Windows 2003 R2 x64 SP2
#
# Version 1.00 revision:
#
# This code is made available as is, without warranty of any kind. The entire
# risk of the use or the results from the use of this code remains with the user.
# *****************************************************************************

Param(
)

# Require
# =============================================================================

# =============================================================================
# Function that returns true if the incoming argument is a help request
# =============================================================================
function IsHelpRequest
{
    param($argument)
    return ($argument -eq "-?" -or $argument -eq "-help");
}

# =============================================================================
# Function: Get-Usage
# Author: Vadim Zenin
# Created: 30/10/2009 13:01:21
# Purpose: Script usage explanation and examples.
# Arguments: none
# Returns:
# =============================================================================
function Get-Usage()
{
@"

USAGE:

NAME:
$ScriptNameOnly.ps1

SYNOPSIS:
Delete the WSUS Client ID's from the registry.

PARAMETERS:

EXAMPLES:
.\$ScriptNameOnly.ps1

"@
}

# =============================================================================
#  MAIN SCRIPT
# =============================================================================

$ScriptPath = $MyInvocation.MyCommand.Path
$ScriptNameOnly = [system.io.path]::GetFilenameWithoutExtension($ScriptPath)
#write-host " ScriptNameOnly: $ScriptNameOnly"

# Check for Usage Statement Request
$args | foreach { if (IsHelpRequest $_) { Get-Usage; exit; } }

write-host "Deleting the WSUS Client ID's from the registry"
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
$RegProperties = "AccountDomainSid", "PingID", "SusClientId", "SusClientIdValidation"
foreach ($RegProperty in $RegProperties) {
    remove-itemproperty -path $RegPath -name $RegProperty -erroraction silentlycontinue
}
#Get-ItemProperty $RegPath

Write-Host -ForegroundColor DarkGreen " Script $ScriptNameOnly has finished"
Download md5: 1bdfcbd25c3b78d204110ace9d89bb8e

2009/11/10

Powershell: Fix Active Directory Permission Inheritance


CURRENT CONFIGURATION: Microsoft Windows 2003 Active Directory, Windows 2003 R2 x64 SP2 Domain Controller with Windows Powershell v 1.0

OBJECTIVE: Delegate AD permissions for some OU.

ISSUE: Some OU, Users, Group and Computers in AD have unchecked permissions settings "Inherit from parent the permission entries that apply to child objects. Include these with entries explicitly defined here"

SOLUTION: I wrote a Powershell script AD_Permission_Inheritance_Enable.ps1
# *****************************************************************************
# Windows Powershell script
# Author:  Vadim Zenin http://vadimszenins.blogspot.com
# Version:  1.00
# Date:     10/11/2009 18:18:43
# Purpose: Restore Active Directory Permission Inheritance on Active
# Directory Objects
#
# Arguments:
# Args[0] OU distinguished Name
#
# Tested platform:
# Windows Powershell v 1.0,
# Windows 2003 R2 x64 SP2,
#
# Version 1.00 revision:
#
# This code is made available as is, without warranty of any kind. The entire
# risk of the use or the results from the use of this code remains with the user.
# *****************************************************************************
# http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_23214970.html
# http://www.powershell.nu/wp-content/uploads/2009/02/get-ad.ps1

Param($DN)
# Modify the string to exclude some classes
[string[]]$AllClasses = 'OrganizationalUnit','Computer','Person','Group'

# =============================================================================
#  FUNCTION LISTINGS
# =============================================================================

# =============================================================================
# Function that returns true if the incoming argument is a help request
# =============================================================================
function IsHelpRequest
{
    param($argument)
    return ($argument -eq "-?" -or $argument -eq "-help");
}

# =============================================================================
# Function: Get-Usage
# Author: Vadims Zenins
# Created: 30/10/2009 13:01:21
# Purpose: Script usage explanation and examples.
# Arguments: none
# Returns:
# =============================================================================
function Get-Usage()
{
@"

USAGE:

NAME:
$ScriptNameOnly.ps1

SYNOPSIS:
Restore Active Directory Permission Inheritance on Active Directory Objects:
 'OrganizationalUnit', 'Computer', 'Person', 'Group' under either OU or
 Active Directory root
To exclude some class of object just modify next line on the top:
 $AllClasses = 'OrganizationalUnit','Computer','Person','Group'

PARAMETERS:
`t"OU distinguished Name"

EXAMPLES:
Enable Active Directory Permission Inheritance for "OU=TestOU,DC=MyCompany,DC=local"
.\$ScriptNameOnly.ps1 "OU=TestOU,DC=MyCompany,DC=local"
.\$ScriptNameOnly.ps1 "OU=TestOU,DC=MyCompany,DC=local" > report.log

Enable Active Directory Permission Inheritance for AD root
.\$ScriptNameOnly.ps1 "DC=MyCompany,DC=local"
.\$ScriptNameOnly.ps1

"@
}

# =============================================================================
#  MAIN SCRIPT
# =============================================================================

$ScriptPath = $MyInvocation.MyCommand.Path
$ScriptNameOnly = [system.io.path]::GetFilenameWithoutExtension($ScriptPath)

# Check for Usage Statement Request
$args | foreach { if (IsHelpRequest $_) { Get-Usage; exit; } }

$yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
$no = new-Object System.Management.Automation.Host.ChoiceDescription "&No",""
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
$caption = "Question..."

# Prompt user if argument is empty to start search from AD root
if ($DN -eq $null) {
    $message = "Would you enable Active Directory Permission Inheritance for root?"
    $result = $host.ui.PromptForChoice($caption,$message,$choices,0)
    if($result -eq 0) {
        Write-Host "You answered YES"
        $DN = ([ADSI]"").distinguishedName
    } else {
        Get-Usage
        exit
    }
}

Write-Host "Started in: $DN"

$ds = new-Object System.DirectoryServices.DirectorySearcher([ADSI]"LDAP://$DN")

foreach ($aa in $AllClasses) {
    Write-Host "= $aa ="
    $ds.Filter = "(objectClass=$aa)"
    $AllItems = $ds.FindAll()
    foreach($ii in $AllItems) {
            $item = $ii.GetDirectoryEntry()
#        Write-Host "Processing $aa: $($item.sAMAccountName)"
            Write-Host "Processing $aa : $($item.distinguishedName)"
#            Enable Permission Inheritance on an Active Directory Object
            $item.psbase.ObjectSecurity.SetAccessRuleProtection($false,$true)
            $item.psbase.CommitChanges()
    }
}

Write-Host " Script $ScriptNameOnly has finished"


Download md5: f03b9338d5267977d5c6c16a7c7981f9

2009/06/16

Fixing space in Public Folder name issue in Excahnge 2007 built-in scripts

CURRENT CONFIGURATION: Exchange 2007 Standard with Public folders

OBJECTIVE: Remove or add user permissions from or to Exchange Public folder and all folders under it (recursive) with Exchange built-in PowerShell scripts RemoveUserFromPFRecursive.ps1 and AddUsersToPFRecursive.ps1.

ISSUE: Scripts RemoveUserFromPFRecursive.ps1 and AddUsersToPFRecursive.ps1 don't work if Exchange Public Folder name contains space(s).

SOLUTION:
Create vbackup copy of original RemoveUserFromPFRecursive.ps1 and AddUsersToPFRecursive.ps1 scripts.

In scripts RemoveUserFromPFRecursive.ps1 and AddUsersToPFRecursive.ps1

find
"get-publicfolder -identity $TopPublicFolder -Recurse -resultsize unlimited"
replace by
#Fixing name with space problem:
'get-publicfolder -identity "$TopPublicFolder"-Recurse -resultsize unlimited'

find
$permission | remove-PublicFolderClientPermission -identity $_.Identity -server $_.OriginatingServer
replace by
#Fixing confirmation problem
$permission | remove-PublicFolderClientPermission -identity $_.Identity -server $_.OriginatingServer -Confirm:$false

DOWNLOAD:
Download AddUsersToPFRecursive_vz.zip md5: 2bc7416556e60958b25a4d9f9648111f
Download RemoveUserFromPFRecursive_vz.zip md5: f247fd6c7951309b9b8d0d0e4b37dff0

2009/06/11

BlackBerry activation email goes to Junk E-mail folder

CURRENT CONFIGURATION: Microsoft Exchange 2007 Standard SP1 with enabled "Content Filter Agent", Blackberry Professional Server

OBJECTIVE: Activate BlackBerry Bold device

ISSUE: Activation emails from RIM appear in Junk E-mail folder in Microsoft Outlook as spam. RIM server EVERY time sends activation emai with DIFFERENT from DOMAIN address. User can not make either email sender or domain to Safe Sender List in Microsoft Outlook.

SOLUTION:
On Exchange 2007 execute next commands in Exchange Power Shell

Add-ContentFilterPhrase -Phrase "This message is used to carry data between the BlackBerry handheld and an associated server" -Influence GoodWord

Set-ContentFilterConfig -BypassedSenderDomains *.blackberry.net

LINKS: Microsoft Technet
How to Configure Allow Phrases for Content Filtering
How to Specify Recipient and Sender Exceptions for Content Filtering