Monday, August 6, 2007

.psbase or when what you see isn't what you want to see

so i have been seeing the .psbase thing in posh scripts and blindly using it because it works in the scripts that seem to need it but understand what it is and why it is used?????

i finally read Tobias' 'ADSI Connecting to Domains/Computers and Binding to Objects' where he does a nice job of explaining .psbase and why you use it

in fact his MASTERING POWERSHELL IN YOUR LUNCH BREAK: series is well worth your time

what i think i have learned is that you use .pbase when you need more information than is provided by get-member you need to do this because the info provided by get-member is sometimes filtered by posh

here some examples from dat 6


$domain get-member
$domain.psbase get-member
$computer get-member
$computer.psbase get-member


$domain = [ADSI]" "
$domain.psbase.children % {
"Name: " + $_.name
"DistinguishedName: " + $_.distinguishedName
"Class: " + $_.objectClass[$_.objectClass.count -1]
"========================================"

}

bottom line when i run an object through get-member and don't see what i am looking for i'll do that object.psbase thing before posting a ?

thanks tobias

Saturday, August 4, 2007

misc tips not yet classified

Powershell - Ying Li at myITforum.com
PowerShell script to assign symantec antivirus parent server to multiple clients based on their default gateway
Powershell script to get Symantec Antivirus Client version and virus definition date
PowerShell script to get Computers Chassis Types
Windows Powershell Profiles
Powershell script to manipulate string.
Powershell script to manipulate string
Powershell script to check folder size

PowerShell script to update DNS Search Order on a particular NIC on multiple remote machines - Ying Li at myITforum.com
How to enter password as secure string
The Comlet to record a PowerShell session
One step further - PowerShell script to modify multiple users' property in Active Directory



PowerShellers How to easy format date-time
Windows PowerShell Get-Process Piped to Dir
Windows PowerShell Editing your Profile file

Windows PowerShell How does Select-String work with Pipelines of objects

PowerShellers Spring-cleaning of a PowerShell profile
James Manning's blog Quick test to see which URL's are still valid
Windows PowerShell Sunday morning drive with my hair on fire Types-Community-Synthetic types-Democracy-Cool XML tricks

James Manning's blog using PowerShell for Outlook automation

James Manning's blog why share-able functions shouldn't be in your PowerShell profile
James Manning's blog Various PowerShell scripts
James Manning's blog using PowerShell for Outlook automation

Wednesday, August 1, 2007

move an sms 2003 collection

# powershell script to move a sms 2003 collection from one parent collection to another then
# request refresh of the parent collections

# replace the collection IDs with your own

# collection to move and its original and new parents collection IDs
$origParent = "C0100026" # collectionID of original parent of the collection to be moved
$coll2Move1 = "C01000B8" # ollectionID of the collection to be moved
$newParent = "C01002BC" # collectionID of the new parent of the collection to be moved
$collectionarray = $origParent,$newParent

$Computer = "your sms site server" # replace with your data
$CollectionClass = "SMS_Collection"
$collectToSubCollectionClass = "SMS_CollectToSubCollect"
$smsNameSpace = "root\SMS\your sms site code" # replace with your data
$Method = "RequestRefresh"

$c = Get-WmiObject -class $collectToSubCollectionClass -namespace $smsNameSpace -computerName $Computer
Where-Object {
$_.parentCollectionID -match $origParent -and $_.subCollectionID -match $coll2Move1
}
$c
# set new parent relationship
foreach ($item in $c)
{
Write-Host $c.parentCollectionID
Write-Host $c.subCollectionID
$c.parentCollectionID = $newParent
$c.put()
}
# delete old relationalship
$c = Get-WmiObject -class $collectToSubCollectionClass -namespace $smsNameSpace -computerName $Computer
Where-Object {
$_.parentCollectionID -match $origParent -and $_.subCollectionID -match $coll2Move1
}
$c.Delete()
#refresh collections
#adapted from SMS_Collection Method : RequestRefresh method script generated by PowerShell WmiExplorer
#
# /\/\o\/\/ 2006
# www.ThePowerShellGuy.com
#
foreach ($memb in $collectionarray)
{
write-host "The value in the current element is $memb"
# SMS_Collection. Key Properties :
# $CollectionID = $memb
$filter="CollectionID = '$memb'"
$MC = get-WMIObject $CollectionClass -computer $Computer -Namespace $smsNameSpace -filter $filter
# $MC = [Wmi]"\\$Computer\Root\CimV2:$Class.$filter"
$InParams = $mc.psbase.GetMethodParameters($Method)
$InParams.includesubcollections = $false
# "Calling SMS_Collection. : RequestRefresh with Parameters :"
$inparams.PSBase.properties select name,Value format-Table
$R = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)
"Result :"
$R Format-list
}

projects

this section will be where i will post scripts that i have used in my job.
for while i may have written these scripts they are authored by the suggestions from the community to whom i, and if you find the scripts valuabe, ow a greate debt of thanks