speckled Posted July 5, 2018 Posted July 5, 2018 (edited) I have a problem running a powershell script since i moved to w10 as my workstation this is the script content: ###################################### # Script to prestage a computer in SCCM # Creates SCCM entry, puts it in the OSD collection # and then creates an AD account and puts # it in the Test OU. ###################################### param ( [parameter(ValueFromPipelineByPropertyName,Mandatory)] [Alias('Computer Name','Computer','Device','Device Name','Name')] [string]$ComputerName, [parameter(ValueFromPipelineByPropertyName,Mandatory)] [validateScript({ if ($_ -match '^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$') { $True } else { Throw "$_ is not a valid MAC Address." } })] [Alias('MAC')] [string]$MACAddress ) Process { $ComputerName = $ComputerName.ToUpper() $MACAddress = $MACAddress.ToUpper() $ValidateComputerName = $ComputerName.Split("-") if ($ValidateComputerName.Count -eq 3) { if ($ValidateComputerName[0] -notmatch "WSH" -or $ValidateComputerName[2] -notmatch "^[TD\d]+$") { Write-Host "This isn't a valid computer name" Exit } } else { Write-Host "This isn't a valid computer name" Exit } Invoke-Command -ComputerName "WSH-SCCM-01" -FilePath "A:\Tools\PowershellScripts\Create-SCCMEntry.ps1" -ArgumentList $ComputerName,$MACAddress New-ADComputer -Name $ComputerName -SamAccountName $ComputerName -Enabled:$True } the script ic calls is this: param ( [string]$ComputerName = $(Read-Host "Enter a computer name"), [string]$MACAddress = $(Read-Host "Enter a MAC Address") ) Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' Set-Location WSH: Import-CMComputerInformation -CollectionName "Windows 7 Clients" -ComputerName $ComputerName -MacAddress $MACAddress #Get-CMDevice -Name $ComputerName | Foreach {Add-CMDeviceCollectionDirectMembershipRule -Collection "Windows 7 Clients" -ResourceId $_.ResourceID} start-sleep -seconds 5 #Invoke-CMDeviceCollectionUpdate -Name "Deployment Test" Invoke-CMDeviceCollectionUpdate -Name "Windows 7 Clients" and this is the error i get when i run the script: Cannot find drive. A drive with the name 'WSH' does not exist. + CategoryInfo : ObjectNotFound: (WSH:String) [set-Location], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand + PSComputerName : WSH-SCCM-01 This command cannot be run from the current drive. To run this command you must first connect to a Configuration Manager drive. + CategoryInfo : DeviceError: (Microsoft.Confi...ormationCommand:ImportComputerInformationCommand) [impor t-CMComputerInformation], InvalidOperationException + FullyQualifiedErrorId : CommandCannotExecuteFromCurrentDrive,Microsoft.ConfigurationManagement.Cmdlets.Oob.Comma nds.ImportComputerInformationCommand + PSComputerName : WSH-SCCM-01 I have been battling with this for quite some time and dont seem to be making any progress, any help would be appreciated. Edited July 5, 2018 by speckled
HPlum78 Posted July 5, 2018 Posted July 5, 2018 first pass and I cannot see anywhere that is setting up a psdrive called WSH I can see it being used by set location mind...
speckled Posted July 5, 2018 Author Posted July 5, 2018 i can run the called script manually fine, it seems to be how the script is called that is causing the issue, something must have change with W10 to cause this issue?
speckled Posted July 6, 2018 Author Posted July 6, 2018 its just referenced in the first file: Invoke-Command -ComputerName "WSH-SCCM-01" -FilePath "A:\Tools\PowershellScripts\Create-SCCMEntry.ps1" -ArgumentList $ComputerName,$MACAddress
HPlum78 Posted July 6, 2018 Posted July 6, 2018 so running this from ISE on your win 10 client it runs without error, do you logon to your client with a privileged account? My guess and this is just a guess.... is that you need to pass some creds (that has interactive login rights). Try:- Invoke-Command -ComputerName "WSH-SCCM-01" -FilePath "A:\Tools\PowershellScripts\Create-SCCMEntry.ps1" -ArgumentList $ComputerName,$MACAddress -Credential (get-Credential) when prompted give it some creds that have the above rights.
speckled Posted July 9, 2018 Author Posted July 9, 2018 I added the the credentials option and it did indeed work, strange how this worked in W7 though with the same scripts and account, the only change being the OS Thanks very much for your help with this problem.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now