Alright Guys, i have a question regarding powershell script. I would like to run powershell script on multiple PCs (obviously using remoting), the problem is that i am in a workgroup enviorment hence I HAVE TO USE $cred. i have created few scripts and i was able to emebed $cred = get-credential within the script by gussing where it should go (cannot find a website where i can obtain more info about"pshell scripting within workgroup environment" following example shows $cred!
$strComputer = get-content c:\Scripts\ip.txt
$cred = Get-Credential $colItems = get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" ` -computername $strcomputer -credential $cred foreach ($objItem in $colItems) { write-host "Caption: " $objItem.Caption write-host "Description: " $objItem.Description write-host "Identifying Number: " $objItem.IdentifyingNumber write-host "Installation Date: " $objItem.InstallDate write-host "Installation Date 2: " $objItem.InstallDate2 write-host "Installation Location: " $objItem.InstallLocation write-host "Installation State: " $objItem.InstallState write-host "Name: " $objItem.Name write-host "Package Cache: " $objItem.PackageCache write-host "SKU Number: " $objItem.SKUNumber write-host "Vendor: " $objItem.Vendor write-host "Version: " $objItem.Version write-host }
myabe i just go lucky with that, but my question is how and where do i need to add get-credential bit within a script to run the script with a different user (WORKGROUP)... i really need to understand that concept because i need to run few more scripts that require authentication, i.e. .............
# Original posting on how to access a remote Registry from The Powershell Guy # # http://thepowershellguy.com/blogs/posh/archive/2007/06/20/remote-registry-access-and-creating-new-registry-values-with-powershell.aspx # # This script will Query the Uninstall Key on a computer specified in $computername and list the applications installed there # $Branch contains the branch of the registry being accessed # '# format of Computerlist.csv # Line 1 - NameOfComputer # Line 2 etcetc etc etc etc An Actual name of a computer$COMPUTERS= Get-content c:\Scripts\ip.txt FOREACH ($PCin$COMPUTERS) { $computername=$PC.NameOfComputer# Branch of the Registry $Branch='LocalMachine'# Main Sub Branch you need to open $SubBranch="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"$registry=[microsoft.win32.registrykey]::OpenRemoteBaseKey('Localmachine',$computername)$registrykey=$registry.OpenSubKey($Subbranch) $SubKeys=$registrykey.GetSubKeyNames()# Drill through each key from the list and pull out the value of # “DisplayName” – Write to the Host console the name of the computer # with the application beside it Foreach ($keyin$subkeys) { $exactkey=$key$NewSubKey=$SubBranch+"\\"+$exactkey$ReadUninstall=$registry.OpenSubKey($NewSubKey) $Value=$ReadUninstall.GetValue("DisplayName") WRITE-HOST $computername, $Value } }