Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Friday, November 7, 2014 4:26 PM
Hi,
scope: run a PowerShell script to get SCCM Collection member FQDN.
Environment: SCCM 2012 R2+CU3; SCSM 2012 R2 + UR3; SCORCH 2012 R2
Scenario:
I created following powershell script which works perfectly on SCCM machine:
#
# Input parameters
#
$username = "XXX\SCInstaller"
$password = "XXXXXXXX"
# Configuration Manager Shell module import and path setting
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
$session = New-PSSession -ComputerName "$SiteServer" -Credential $cred -Authentication Credssp
$result = Invoke-Command -session $session -ScriptBlock {
$CMAdminConsoleBinPath = 'e:\Program Files\Microsoft Configuration Manager\AdminConsole\bin'
$SiteCode="PHQ"
$SiteCodeLocation = "PHQ:"
$CollectionName = "Software Update Pilot Collection"
$SiteServer = "SYSC-SC01.pradagroup.net"
Import-Module ($CMAdminConsoleBinPath + '\ConfigurationManager.psd1')
$PSD = Get-PSDrive -PSProvider CMSite
CD "$($PSD):"
Set-Location $SiteCodeLocation
# Get Site collection members
$Devices = Get-CMDevice -CollectionName $CollectionName
# Empty array creation
$Results = @()
# get SMS_R_SYSTEM (System Resource) class objects for each Collection element
# and add them to Results array
foreach ( $myDev in $Devices) {
$myFilter = "ResourceID = " + $myDev.ResourceID
$myRes = Get-WmiObject -ComputerName $SiteServer -Namespace root\sms\site_$SiteCode -Class SMS_R_SYSTEM -Filter $myFilter |Select -Property ResourceNames
$Results = $Results + $myRes
}
# Send ResourceNames field value (FQDN) to output file
$Results | Out-File "C:\Users\alessandro.gregnanin\Desktop\alessag\output.txt" -Append
}
Remove-PSSession -Session $Session
Output file reports:
ResourceNames
IT-MIL0982.domainname.com
SYSC-CON04.domainname.com
IT-AI-L0800.domainname.com
IT-MI-D0548.domainname.com
it-mi-d0549.domainname.com
IT-MI-L1416.domainname.com
Great !
Next step were to run again it on SCSM 2012 machine before porting it at SCORCH RB.
I made some changing to powershell script:
#
# Input parameters
#
$username = "XXX\SCInstaller"
$password = "XXXXXXXX"
# Configuration Manager Shell module import and path setting
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
$session = New-PSSession -ComputerName "$SiteServer" -Credential $cred -Authentication Credssp
$result = Invoke-Command -session $session -ScriptBlock {
$CMAdminConsoleBinPath = '\e$\Program Files\Microsoft Configuration Manager\AdminConsole\bin'
$SiteCode="PHQ"
$SiteCodeLocation = "PHQ:"
$CollectionName = "Software Update Pilot Collection"
$SiteServer = "SYSC-SC01.pradagroup.net"
Import-Module ('\' + $SiteServer + $CMAdminConsoleBinPath + '\ConfigurationManager.psd1')
$PSD = Get-PSDrive -PSProvider CMSite
CD "$($PSD):"
Set-Location $SiteCodeLocation
# Get Site collection members
$Devices = Get-CMDevice -CollectionName $CollectionName
# Empty array creation
$Results = @()
# get SMS_R_SYSTEM (System Resource) class objects for each Collection element
# and add them to Results array
foreach ( $myDev in $Devices) {
$myFilter = "ResourceID = " + $myDev.ResourceID
$myRes = Get-WmiObject -ComputerName $SiteServer -Namespace root\sms\site_$SiteCode -Class SMS_R_SYSTEM -Filter $myFilter |Select -Property ResourceNames
$Results = $Results + $myRes
}
# Send ResourceNames field value (FQDN) to output file
$Results | Out-File "C:\Users\alessandro.gregnanin\Desktop\alessag\output.txt" -Append
}
Remove-PSSession -Session $Session
I got following error:
Could not load file or assembly 'file://\SYSC-SC01.pradagroup.net\e$\Program Files\Microsoft Configuration
Manager\AdminConsole\bin\AdminUI.PS.TypeAdapter.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
+ CategoryInfo : InvalidOperation: (:) [Import-Module], FileLoadException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
+ PSComputerName : SYSC-SC01.pradagroup.net
Cannot find a provider with the name 'CMSite'.
+ CategoryInfo : ObjectNotFound: (System.String[]:String[]) [Get-PSDrive], ProviderNotFoundException
+ FullyQualifiedErrorId : GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand
+ PSComputerName : SYSC-SC01.pradagroup.net
Cannot find path 'C:\Users\scinstaller.PRADAGROUP\Documents\' because it does not exist.
+ CategoryInfo : ObjectNotFound: (C:\Users\scinst...OUP\Documents\:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
+ PSComputerName : SYSC-SC01.pradagroup.net
Cannot find drive. A drive with the name 'PHQ' does not exist.
+ CategoryInfo : ObjectNotFound: (PHQ:String) [Set-Location], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
+ PSComputerName : SYSC-SC01.pradagroup.net
The term 'Get-CMDevice' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo : ObjectNotFound: (Get-CMDevice:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : SYSC-SC01.pradagroup.net
FYI: AdminUI.PS.TypeAdapter.dll file is at that path.
Grazie mille Alex
Friday, September 8, 2017 11:46 AM
Ciao Alex.
Your assembly AdminUI.PS.TypeAdapter.dll was found but prohibited to load from a network share (Exception from HRESULT: 0x80131515) and the $PSD variable evaluated to $null or an empty string which led to ItemNotFoundException. The module could not load for the same security reasons apparently. Why you tried to use Set-Location with some fake pseudo-drive 'PHQ:' is a mystery to me.