Hey there Nick,
I'm glad you were able to root out the problem! I'm always glad to give a nudge when needed.
Webmaster. PowerShell Junkie and MVP.
Blog: http://lastwordinnerd.com
Hey there Nick,
I'm glad you were able to root out the problem! I'm always glad to give a nudge when needed.
Webmaster. PowerShell Junkie and MVP.
Blog: http://lastwordinnerd.com
So with everyone's assistance I was able to get this to actually work, as expected, now I need to make this work on 500+ computers
(pre){#Set variable for registry query, where Any match of "HCI APS", Select property "UninstallString" – Working
$apsInst = Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall|
Get-ItemProperty | Where-Object {$_.DisplayName -match "SLOOBAPP"}|
Select-Object -Property UninstallString
$uninst = "Silverlight.Configuration.exe -uninstallApp 165905322.SLOOBAPP.somewebsite.com"
ForEach ($aps in $apsInst) {
If ($aps.UninstallString){
Set-Location -Path "c:\Program Files (x86)\Microsoft Silverlight\5.1.30514.0"
Start-Process -FilePath cmd.exe -ArgumentList '/c', $uninst -wait
}
} }(/pre)
You're passing formatted data (Format-Table) to Write-Host, which won't work. For example, this will work:
PS C:\Windows\system32> $paths = Get-ChildItem -path 'c:\scripts' | Sort-Object CreationTime -Descending | Select-Object -First 1 | Format-Table -Property CreationTime, LastWriteTime, FullName, Length PS C:\Windows\system32> $paths CreationTime LastWriteTime FullName Length ———— ————- ——– —— 5/12/2015 7:28:54 PM 5/12/2015 7:48:32 PM C:\scripts\cmerrlogBuild.csv 8914923
But if you pass it to write host:
PS C:\Windows\system32> Write-Host $paths Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.P owerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Com mands.Internal.Format.FormatEndData
I'd recommend creating a PSCustomObject instead of formatting the data. It's a lot more flexible. Or better yet, build out your script as a function without limiting the data being passed and use Select-Object in the pipe naturally. But if you're looking for a report kind of script, then PSCustomObject is probably a better way to go.
Webmaster. PowerShell Junkie and MVP.
Blog: http://lastwordinnerd.com
$rootdir = "\\somenetworkpath\folder" $directories = @( "\somefolder1\TMP" "\somefolder2\Diff" "\somefolder3\Diff" "\somefolder4\Diff" "\somefolder5\Diff" "\somefolder6" "\somefolder7" "\somefolder8\differentdiff" "\somefolder9\Diff" ) ForEach($directory in $directories) { Get-ChildItem -Path (Join-Path $rootdir $directory) | Sort-Object CreationTime -Descending | Select-Object -First 1 | Select-Object CreationTime, LastWriteTime, FullName, Length }
Format-Table turns the file system objects into a formatting object, which if you try to use Write-Host on converts to a very unhelpful string. If you replace Format-Table with Select-Object and then just let it fall out off the pipeline without catching it in a variable, you should get what you want. I also powershellerized the loop.
Your logic is a bit messed up. In your post you don't show what you are running the Format-Table against, but you are overwriting it each time. There are two methods of creating an object with all results, I like assigning the results to the for loop and the other appends data as it goes (currently remarked out):
$rootdir = "C:\Windows" $directories = @("\Diagnostics", "\Debug", "\Fonts") $results = foreach ($directory in $directories) { Get-ChildItem -path ("{0}{1}" -f $rootdir, $directory) | Sort-Object CreationTime -Descending | Select -First 1 } #$results = @() #Create a blank object (array) to add items to #foreach ($directory in $directories) { #Add each result to the blank object (array) # $results += Get-ChildItem -path ("{0}{1}" -f $rootdir, $directory) | Sort-Object CreationTime -Descending | Select -First 1 #} $results | Format-Table -Property CreationTime, LastWriteTime, FullName, Length
Awesome, it works like a dream. One month into my learning and i'm really proud i've done this by myself !!
##Import App-V application
#Set Application details to add to SCCM from text template
$DefaultAppPath = "\\theaa.local\dfsdata\sccm\software\"
$Content = get-content "\\aa-cm002v\e$\scripts\AppV_Template.txt"
$App_DT_Name = $Content[3]
$App_Name = $Content[5]
$App_Source_Location = $Content[7]
$OptRef =
$Publisher = $Content[9]
$SoftVer = $Content[11]
$Folder = $Content[13]
$DPGroup = "All Distribution Points"
#Full location path
$LocationFull = "$DefaultAppPath"+"$App_Source_Location"
#Set Module, CMsite directory and revert back to orginal prompt
$ModulePath = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
$SetDriveStart = "set-location AAC:"
$SetDriveEnd = "set-location E:"
#Import module
Import-Module $ModulePath\ConfigurationManager.psd1
try {
#Set directory
Invoke-expression $SetDriveStart
#Create new application. "#" if the below command is required.
Try {
New-CMApplication -Name $App_Name -AutoInstall $true -Publisher $Publisher -SoftwareVersion $SoftVer | out-null
Write-Output "Created $App_Name succesfully" }
Catch {
Write-Output "Creating $App_Name failed" }
#Create New Application deployment file
Try {
Add-CMDeploymentType -ApplicationName $App_Name -DeploymentTypeName $App_DT_Name -AppV5xInstaller -ForceForUnknownPublisher $true -InstallationFileLocation $LocationFull | out-null
Write-Output "Created $App_DT_Name succesfully" }
Catch {
Write-Output "Creating $App_DT_Name failed" }
#Move Application to folder
Try {
$GetApp = Get-CMApplication -name $App_Name
Move-CMObject -FolderPath ".\Application\Publisher\$Folder" -InputObject $GetApp
Write-Output "Moved $App_Name to $Folder succesfully" }
Catch {
Write-Output "Moving $App_Name to $Folder failed" }
#Distribute application
Try {
Start-CMContentDistribution -ApplicationName $App_Name -DistributionPointGroupName $DPGroup
Write-Output "Distributed content to $DPGroup" }
Catch {
Write-Output "Failed to Distribute content to $DPGroup" }
#Set location back to E drive
Invoke-expression $SetDriveEnd
Write-Output "Virtual App created in SCCM and currently distributing"
exit 0 }
Catch {
Write-Output "Failed to Create Virtual App"
Exit 1001 }
Thank you guys!
Craig, yeah, true the "select-object" works, but the table is messed up like that, well, I get the data out at-least
Rob, your method works just like I need, thank you so much!
Hi guys,
recently I've ran into issues when DSC is installing Windows Features that require reboot. So in this case DSC starts applying MOF, then it show message "DSC requires reboot…" But when machine reboots, MOF does not continue to apply. It takes time for DSC to recognize this fact and resume MOF application. It might take up to 1 hour (30min is DSC configured period for node MOF update check). I have to invoke pull manually to speed up the process. I use WMF 4.0. Node is 2008R2 Ent. One of features that requires reboot is "RSAT features"
Can anyone either confrim or clarify this moment? Maybe there is a workaround for this.
Many thanks in advance!
Max
A lot of people see this. You're looking less at a DSC problem and more at the way the WindowsFeature module just works at the moment, I think. Keep in mind that DSC is a little like SCCM in that you're meant to be patient with it, not hurry it along. I think this'll likely get better going forward, but right now feature/software installation is definitely a point where the underlying OS sort of demands more patience. I'm not saying it's *acceptable*, mind you, just that it sort of is what it is right now.
Although frankly, this could also just be Windows' way of punishing you for installing GUI tools on a server. That sort of presumes you're also RDP-ing into the server to manage it. There's a reason the "R" in RSAT stands for "Remote." Slight grin here, but only a little ;).
Don Jones
Curriculum Director for IT Pro Content, Pluralsight.com
As you learn Powershell, keep in mind that not indenting your code results in the death of kittens and puppies are kicked. As your experience grows, so will your scripts, so you need to learn indention to see the flow of the script and be able to troubleshoot. Also, there isn't really a need to specify "Write-Output" and in your first try\catch (under the main try catch), I updated your catch. You are capturing something failed, but not why. Minimally, grabbing the exception message will get you troubleshooting information. Would you rather have this "Failed to Create Virtual App" or "Failed to Create Virtual App. Access Denied." as your message? Which one can your troubleshoot faster?
##Import App-V application #Set Application details to add to SCCM from text template $DefaultAppPath = "\\theaa.local\dfsdata\sccm\software\" $Content = get-content "\\aa-cm002v\e$\scripts\AppV_Template.txt" $App_DT_Name = $Content[3] $App_Name = $Content[5] $App_Source_Location = $Content[7] $OptRef = $Publisher = $Content[9] $SoftVer = $Content[11] $Folder = $Content[13] $DPGroup = "All Distribution Points" #Full location path $LocationFull = "$DefaultAppPath"+"$App_Source_Location" #Set Module, CMsite directory and revert back to orginal prompt $ModulePath = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin" $SetDriveStart = "set-location AAC:" $SetDriveEnd = "set-location E:" #Import module Import-Module $ModulePath\ConfigurationManager.psd1 try { #Set directory Invoke-expression $SetDriveStart #Create new application. "#" if the below command is required. Try { New-CMApplication -Name $App_Name -AutoInstall $true -Publisher $Publisher -SoftwareVersion $SoftVer | out-null Write-Output "Created $App_Name succesfully" } Catch { "Creating {0} failed. {1}" -f $App_Name, $_.Exception.Message } #Create New Application deployment file Try { Add-CMDeploymentType -ApplicationName $App_Name -DeploymentTypeName $App_DT_Name -AppV5xInstaller -ForceForUnknownPublisher $true -InstallationFileLocation $LocationFull | out-null Write-Output "Created $App_DT_Name succesfully" } Catch { Write-Output "Creating $App_DT_Name failed" } #Move Application to folder Try { $GetApp = Get-CMApplication -name $App_Name Move-CMObject -FolderPath ".\Application\Publisher\$Folder" -InputObject $GetApp Write-Output "Moved $App_Name to $Folder succesfully" } Catch { Write-Output "Moving $App_Name to $Folder failed" } #Distribute application Try { Start-CMContentDistribution -ApplicationName $App_Name -DistributionPointGroupName $DPGroup Write-Output "Distributed content to $DPGroup" } Catch { Write-Output "Failed to Distribute content to $DPGroup" } #Set location back to E drive Invoke-expression $SetDriveEnd Write-Output "Virtual App created in SCCM and currently distributing" exit 0 } Catch { Write-Output "Failed to Create Virtual App" Exit 1001 }
I am trying to set a value for a web form. I have followed multiple tutorials with no success. I get the following error
Exception setting "value": "The property 'value' cannot be found on this object. Verify that the property exists and can be set."
Here is my code:
$ie = New-Object -Com "InternetExplorer.Application" $ie.Navigate("https://*******************/ccmadmin/showHome.do") $ie.Visible = $true while($ie.ReadyState -ne 4) {start-sleep -m 100} $ie.Document.getElementsByName("j_username").value = "aaaaa"
When I get the properties I get the following:
className : id : tagName : INPUT parentElement : System.__ComObject style : System.__ComObject onhelp : onclick : ondblclick : onkeydown : onkeyup : onkeypress : onmouseout : onmouseover : onmousemove : onmousedown : onmouseup : document : mshtml.HTMLDocumentClass title : language : onselectstart : sourceIndex : 75 recordNumber : lang : offsetLeft : 1 offsetTop : 2 offsetWidth : 142 offsetHeight : 19 offsetParent : System.__ComObject innerHTML : innerText : outerHTML : outerText : parentTextEdit : System.__ComObject isTextEdit : True filters : System.__ComObject ondragstart : onbeforeupdate : onafterupdate : onerrorupdate : onrowexit : onrowenter : ondatasetchanged : ondataavailable : ondatasetcomplete : onfilterchange : children : System.__ComObject all : System.__ComObject scopeName : HTML onlosecapture : onscroll : ondrag : ondragend : ondragenter : ondragover : ondragleave : ondrop : onbeforecut : oncut : onbeforecopy : oncopy : onbeforepaste : onpaste : currentStyle : System.__ComObject onpropertychange : tabIndex : 0 accessKey : onblur : onfocus : onresize : clientHeight : 17 clientWidth : 140 clientTop : 1 clientLeft : 1 readyState : complete onreadystatechange : onrowsdelete : onrowsinserted : oncellchange : dir : scrollHeight : 17 scrollWidth : 140 scrollTop : 0 scrollLeft : 0 oncontextmenu : canHaveChildren : False runtimeStyle : System.__ComObject behaviorUrns : System.__ComObject tagUrn : onbeforeeditfocus : isMultiLine : False canHaveHTML : False onlayoutcomplete : onpage : onbeforedeactivate : contentEditable : inherit isContentEditable : True hideFocus : False disabled : False isDisabled : False onmove : oncontrolselect : onresizestart : onresizeend : onmovestart : onmoveend : onmouseenter : onmouseleave : onactivate : ondeactivate : onmousewheel : onbeforeactivate : onfocusin : onfocusout : uniqueNumber : 1 uniqueID : ms__id1 nodeType : 1 parentNode : System.__ComObject childNodes : System.__ComObject attributes : System.__ComObject nodeName : INPUT nodeValue : firstChild : lastChild : previousSibling : nextSibling : ownerDocument : mshtml.HTMLDocumentClass prefix : localName : namespaceURI : textContent : dataFld : dataSrc : dataFormatAs : role : ariaBusy : ariaChecked : ariaDisabled : ariaExpanded : ariaHaspopup : ariaHidden : ariaInvalid : ariaMultiselectable : ariaPressed : ariaReadonly : ariaRequired : ariaSecret : ariaSelected : ie8_attributes : ariaValuenow : ariaPosinset : ariaSetsize : ariaLevel : ariaValuemin : ariaValuemax : ariaControls : ariaDescribedby : ariaFlowto : ariaLabelledby : ariaActivedescendant : ariaOwns : ariaLive : ariaRelevant : ie9_tagName : ie9_nodeName : onabort : oncanplay : oncanplaythrough : onchange : ondurationchange : onemptied : onended : onerror : oninput : onload : onloadeddata : onloadedmetadata : onloadstart : onpause : onplay : onplaying : onprogress : onratechange : onreset : onseeked : onseeking : onselect : onstalled : onsubmit : onsuspend : ontimeupdate : onvolumechange : onwaiting : constructor : onmspointerdown : onmspointermove : onmspointerup : onmspointerover : onmspointerout : onmspointercancel : onmspointerhover : onmslostpointercapture : onmsgotpointercapture : onmsgesturestart : onmsgesturechange : onmsgestureend : onmsgesturehold : onmsgesturetap : onmsgesturedoubletap : onmsinertiastart : onmstransitionstart : onmstransitionend : onmsanimationstart : onmsanimationend : onmsanimationiteration : oninvalid : xmsAcceleratorKey : spellcheck : False onmsmanipulationstatechanged : oncuechange : type : text value : name : j_username status : False form : System.__ComObject size : 20 maxLength : 128 defaultValue : readOnly : False indeterminate : False defaultChecked : False checked : False border : vspace : 0 hspace : 0 alt : src : lowsrc : vrml : dynsrc : complete : False loop : 1 align : width : 0 height : 0 start : fileopen accept : useMap : selectionStart : selectionEnd : ie8_src : ie8_lowsrc : ie8_vrml : ie8_dynsrc : min : max : step : valueAsNumber :
Any thoughts on why I can't set the value?
The lack of indentation might be just be on the forums, because the OP didn't use the [ pre ] and [ /pre ] tags (which hopefully show up because I stuck in some extra whitespace.)
It's probably returning a collection class of some sort, and you want to set the value on an element in that collection. Try this, to be sure:
Get-Member -InputObject $ie.Document.getElementsByName("j_username")
I get the following:
TypeName: System.__ComObject#{3050f56b-98b5-11cf-bb82-00aa00bdce0b} Name MemberType Definition —- ———- ———- ie8_item Method IHTMLElement2 ie8_item (int) ie8_namedItem Method IHTMLElement2 ie8_namedItem (string) item Method IDispatch item (Variant, Variant) namedItem Method IDispatch namedItem (string) tags Method IDispatch tags (Variant) toString Method string toString () urns Method IDispatch urns (Variant) constructor Property IDispatch constructor () {get} ie8_length Property int ie8_length () {get} length Property int length () {get} {set}
Hi Rob,
Great tip with the error output, wasn't aware of that.
Dave is right, i did indent the script but its not formatted very well when i pasted it.
Thanks everyone.
Yep, so you probably need to try something like this:
$ie.Document.getElementsByName("j_username").ie8_item(0).value = "aaaaa"
Kittens lives are at stake here, use your [ pre ] and [ /pre ] tags.
Error
Exception setting "value": "Cannot set the Value property for PSMemberInfo object of type "System.Management.Automation.PSMethod"."
Would there be an easy way to find the index or do I just need to keep trying numbers.
I will do in future…can't risk the kittens !
Don — yep, definitely just a "play-with-this" scenario in a local Hyper-V lab.
Trevor — does come up in a Get-DscResource call. And I can even generate a mof with it; should have been clearer above: I only get that exception when I do the Start-DscConfiguration call.