Unable to create new New-CimInstance - powershell

I'm trying to stop/start Windows service remotely. However, if I remove the -Computer parameter, it is working fine in local machine. If I add the -Computer parameter, it is throwing an exception. Am I missing something?
New-CimInstance : Unable to resolve the parameter set name.
At D:\DevOps\Scripts\StartStopvNextService.ps1:6 char:16
+ ... yInstance = New-CimInstance -Namespace root/cimv2 -ClassName Win32_En ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-CimInstance], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.Management.Infrastructure.CimCmdlets.NewCimInstanceCommand
Param(
[string]$Name,
[string]$Computer
)
Import-Module CimCmdlets
$keyInstance = New-CimInstance -Namespace root/cimv2 -ClassName Win32_Service -Key #('Name') -Property #{Name=$Name;} -ComputerName $Computer -ClientOnly
Invoke-CimMethod $keyInstance -MethodName StartService

Related

Why do I receive an "RPC error" when using Get-WmiObject on a Netapp SVM

How can i get this to show me who's using the shares on our NETAPP.
$computer = "gozer"
$namespace = "root\CIMV2" # note to self find out if this is correct
$userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace
if($userSessions -ne $null)
{
Write-Host "The following users are connected to your PC: "
foreach ($userSession in $userSessions)
{
$userDetails = [string]::Format("User {0} from machine {1} on share: {2}",
$userSession.UserName, $userSession.ComputerName, $userSession.ShareName)
Write-Host $userDetails
}
Read-Host
}
exit
the error i receive when i run this pointing at a NETAPP SVM is:
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\test\whos-using-the-share.ps1:3 char:17
+ $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $compu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

System Center Configuration Manager - PowerShell Remoting

I have a primary SCCM server - "ABC"
Later I installed SCCM console and PowerShell Module on one more machine - "XYZ"
I am running below script from server - "OPQ" and trying to remote "XYZ" (on which i installed SCCM Console Recently)
Script ::
$Session = New-PSSession -ComputerName "XYZ" -Authentication Kerberos -Credential $Cred -ConfigurationName Microsoft.PowerShell32
Invoke-Command -Session $Session -ScriptBlock {
Import-module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
Set-Location PS1:\
}
ERROR ::
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
+ CategoryInfo : OpenError: (PS1:PSDriveInfo) [Import-Module], UnauthorizedAccessException
+ FullyQualifiedErrorId : Drive,Microsoft.PowerShell.Commands.ImportModuleCommand
+ PSComputerName : XYZ
Cannot find drive. A drive with the name '' does not exist.
+ CategoryInfo : ObjectNotFound: (PS1:String) [Set-Location], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
+ PSComputerName : XYZ
Well it appears you have a permissions issue. Here is how I executed a remote command in my SCCM environment, via my PSS:
$device = Invoke-Command -Session $sess -ScriptBlock {
Import-Module (Join-Path (Split-Path $env:SMS_ADMIN_UI_PATH)
ConfigurationManager.psd1)
Push-Location -Path ((Get-WmiObject -Namespace "root\SMS" -Class
"SMS_ProviderLocation" | Select-Object -ExpandProperty SiteCode) + ":")
Get-CMDevice -Name $env:COMPUTERNAME
Pop-Location
}
$device
RunspaceId : cbc7e008-d92c-4ba3-94a3-b75f8005be98
SmsProviderObjectPath : SMS_CM_RES_COLL_SMS00001.ResourceID=16777221
AADDeviceID : 00000000-0000-0000-0000-000000000000
AADTenantID : 00000000-0000-0000-0000-000000000000
ActivationLockBypassState :
ActivationLockState :
ADLastLogonTime : 3/31/2020 11:23:38 PM
ADSiteName : XXXX-XX
...
Note that if you're not remoting to your PSS, you will need to specify your PSS in the Get-WmiObject command, e.g.:
(Get-WmiObject -ComputerName [YOUR PSS] -Namespace "root\SMS" -Class "SMS_ProviderLocation" | Select-Object -ExpandProperty SiteCode) + ":"
I was able to resolve this issue by saving the credentials on the XYZ server and then calling them under my INvoke-Command.
Like This :
$Session = New-PSSession -ComputerName "XYZ"
Invoke-Command -Session $Session -ScriptBlock {
$password = Get-Content -Path D:\Creds\creds.txt | ConvertTo-SecureString
$Cred = New-Object System.Management.Automation.PSCredential ("domain\UserId", $password)
Then the rest of the code. ... .. . . .
}

Powershell Script - AD Discovery - Get-CimInstance : Access is denied. - SCCM 2012

I'm trying to create a powershell script to make AD Discovery possible, whenever i start te script i always get Get-CimInstance : Access is denied.
i also try to fill in the values of a Active Directory Container but the script always says that the property .Values cannot be found on this object.
what am i doing wrong ?
this is the full script:
Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager'
Set-Location PS1:
# variable
$CMSiteCode = 'PS1'
$CMSiteServer = 'CM01.local.cursusdom.tm'
$CMNameSpace = "root\SMS\site_$CMSiteCode"
# create a schedule
$CMGroupDiscoverySchedule = New-CMSchedule -RecurInterval Days -RecurCount 7
# Forest Discovery
Set-CMDiscoveryMethod -ActiveDirectoryForestDiscovery ` -SiteCode $CMSiteCode ` -EnableActiveDirectorySiteBoundaryCreation $true ` -EnableSubnetBoundaryCreation $true ` -Enabled $true
# Configure Group Discovery
# Create the base discovery method using the schedule
Set-CMDiscoveryMethod -ActiveDirectoryGroupDiscovery ` -SiteCode $CMSiteCode ` -EnableDeltaDiscovery $true ` -DeltaDiscoveryIntervalMinutes 5 ` -EnableFilteringExpiredLogon $true ` -TimeSinceLastLogonDays 30 ` -EnableFilteringExpiredPassword $true ` -TimeSinceLastPasswordUpdateDays 90 ` -PollingSchedule $CMGroupDiscoverySchedule ` -Enabled $true
# AD containers
$ADGroupDiscovery = Get-CimInstance -ComputerName $CMSiteServer `
-Namespace $CMNameSpace `
-ClassName SMS_SCI_Component `
-Filter 'ComponentName ="SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT"'
$ADContainerProp = $GroupDiscovery.PropLists | where {$_.PropertyListName -eq "AD Containers" }
$ADContainerProp.Values = "Acme - Software groups",0,0,1
$ADGroupDiscovery = Get-CimInstance -ComputerName $CMSiteServer ` -Namespace $CMNameSpace ` -ClassName SMS_SCI_Component ` -Filter 'ComponentName ="SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT"'
$NewGroupProp = New-CimInstance -ClientOnly -Namespace $CMNameSpace -ClassName SMS_EmbeddedPropertyList -Property #{PropertyListName='Search Bases:PS1';Values=[string[]]'LDAP://OU=Software groups,OU=Acme,DC=Local,DC=cursusdom,DC=tm'}
$ADGroupDiscovery.PropLists += $NewGroupProp
# change back to the CIM instance
Get-CimInstance -ComputerName $CMSiteServer ` -Namespace $CMNameSpace ` -ClassName SMS_SCI_Component ` -Filter 'ComponentName ="SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT"' | Set-CimInstance -Property #{PropLists=$ADGroupDiscovery.PropLists}
# Configure System Discovery
# polling schedule
$CMSystemDiscoverySchedule = New-CMSchedule -RecurInterval Days -RecurCount 1
# Create the base discovery method using the schedule
Set-CMDiscoveryMethod -ActiveDirectorySystemDiscovery ` -SiteCode $CMSiteCode ` -EnableDeltaDiscovery $true ` -DeltaDiscoveryIntervalMinutes 5 ` -EnableFilteringExpiredLogon $true ` -TimeSinceLastLogonDays 30 ` -EnableFilteringExpiredPassword $true ` -TimeSinceLastPasswordUpdateDays 90 ` -PollingSchedule $CMSystemDiscoverySchedule ` -Enabled $true
# AD containers
$ADSysDiscovery = Get-CimInstance -ComputerName $CMSiteServer `-Namespace $CMNameSpace ` -ClassName SMS_SCI_Component ` -Filter 'ComponentName ="SMS_AD_SYSTEM_DISCOVERY_AGENT"'
$ADContainerProp =$Sysdiscovery.PropLists | where {$_.PropertyListName -eq "AD Containers" }
$ADContainerProp.Values = "LDAP://OU=Domain Controllers,DC=local,DC=cursusdom,DC=tm",1,1 # Ldap path of the Container, Recursive search, Discover objects within groups
$ADContainerProp =$Sysdiscovery.PropLists | where {$_.PropertyListName -eq "AD Containers" }
$ADContainerProp.Values = "LDAP://OU=Computers,OU=Acme,DC=local,DC=cursusdom,DC=tm",1,1 # Ldap path of the Container, Recursive search, Discover objects within groups
# change back to the CIM instance
Get-CimInstance -ComputerName $CMSiteServer `
-Namespace $CMNameSpace `
-ClassName SMS_SCI_Component `
-Filter 'ComponentName ="SMS_AD_SYSTEM_DISCOVERY_AGENT"' | Set-CimInstance -Property #{PropLists=$ADSysDiscovery.PropLists}
# User Discovery
# polling schedule
$CMUserDiscoverySchedule = New-CMSchedule -RecurInterval Days -RecurCount 1
# Create the base discovery method
Set-CMDiscoveryMethod -ActiveDirectoryUserDiscovery `
-SiteCode $CMSiteCode `
-EnableDeltaDiscovery $true `
-DeltaDiscoveryIntervalMinutes 5 `
-PollingSchedule $CMUserDiscoverySchedule `
-enabled $true
# AD containers
$ADUserDiscovery = Get-CimInstance -ComputerName $CMSiteServer `
-Namespace $CMNameSpace `
-ClassName SMS_SCI_Component `
-Filter 'ComponentName ="SMS_AD_USER_DISCOVERY_AGENT"'
$ADUserContainers = $ADUserDiscovery.PropLists | Where-Object {$_.PropertyListName -eq 'AD Containers'}
$ADContainerProp.Values = "LDAP://OU=Users,OU=Acme,DC=local,DC=cursusdom,DC=tm",0,0
$ADContainerProp.Values = "LDAP://OU=Admins,OU=Acme,DC=local,DC=cursusdom,DC=tm",0,0
# change back to the CIM instance
Get-CimInstance -ComputerName $CMSiteServer `
-Namespace $CMNameSpace `
-ClassName SMS_SCI_Component `
-Filter 'ComponentName ="SMS_AD_USER_DISCOVERY_AGENT"' | Set-CimInstance -Property #{PropLists=$ADUserDiscovery.PropLists}
# 5.0 - Restart SMS_SITE_COMPONENT_MANAGER Service to apply changes
Get-Service -ComputerName $CMSiteServer -Name SMS_SITE_COMPONENT_MANAGER | Restart-Service
these are the errors i'm getting:
PS C:\Users\Admin> C:\Users\Admin\Downloads\AD discovery.ps1
Get-CimInstance : Access is denied.
At C:\Users\Admin\Downloads\AD discovery.ps1:34 char:21
+ $ADGroupDiscovery = Get-CimInstance -ComputerName $CMSiteServer `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : CM01.local.cursusdom.tm
The property 'Values' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Admin\Downloads\AD discovery.ps1:40 char:1
+ $ADContainerProp.Values = "Acme - Software groups",0,0,1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Get-CimInstance : Access is denied.
At C:\Users\Admin\Downloads\AD discovery.ps1:43 char:21
+ ... Discovery = Get-CimInstance -ComputerName $CMSiteServer ` -Namespa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : CM01.local.cursusdom.tm
The property 'PropLists' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Admin\Downloads\AD discovery.ps1:47 char:1
+ $ADGroupDiscovery.PropLists += $NewGroupProp
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Get-CimInstance : Access is denied.
At C:\Users\Admin\Downloads\AD discovery.ps1:51 char:1
+ Get-CimInstance -ComputerName $CMSiteServer ` -Namespace $CMNameSp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : CM01.local.cursusdom.tm
Get-CimInstance : A positional parameter cannot be found that accepts argument '-Namespace'.
At C:\Users\Admin\Downloads\AD discovery.ps1:74 char:19
+ ... Discovery = Get-CimInstance -ComputerName $CMSiteServer `-Namespace $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-CimInstance], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstan
ceCommand
The property 'Values' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Admin\Downloads\AD discovery.ps1:77 char:1
+ $ADContainerProp.Values = "LDAP://OU=Domain Controllers,DC=local,DC=c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
The property 'Values' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Admin\Downloads\AD discovery.ps1:80 char:1
+ $ADContainerProp.Values = "LDAP://OU=Computers,OU=Acme,DC=local,DC=cu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Get-CimInstance : Access is denied.
At C:\Users\Admin\Downloads\AD discovery.ps1:84 char:1
+ Get-CimInstance -ComputerName $CMSiteServer `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : CM01.local.cursusdom.tm
Get-CimInstance : Access is denied.
At C:\Users\Admin\Downloads\AD discovery.ps1:110 char:20
+ $ADUserDiscovery = Get-CimInstance -ComputerName $CMSiteServer `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : CM01.local.cursusdom.tm
The property 'Values' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Admin\Downloads\AD discovery.ps1:117 char:1
+ $ADContainerProp.Values = "LDAP://OU=Users,OU=Acme,DC=local,DC=cursus ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
The property 'Values' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Admin\Downloads\AD discovery.ps1:119 char:1
+ $ADContainerProp.Values = "LDAP://OU=Admins,OU=Acme,DC=local,DC=cursu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Get-CimInstance : Access is denied.
At C:\Users\Admin\Downloads\AD discovery.ps1:124 char:1
+ Get-CimInstance -ComputerName $CMSiteServer `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : CM01.local.cursusdom.tm
Restart-Service : Service 'SMS_SITE_COMPONENT_MANAGER (SMS_SITE_COMPONENT_MANAGER)' cannot be stopped due to the follo
wing error: Cannot open SMS_SITE_COMPONENT_MANAGER service on computer 'CM01.local.cursusdom.tm'.
At C:\Users\Admin\Downloads\AD discovery.ps1:131 char:76
+ ... Name $CMSiteServer -Name SMS_SITE_COMPONENT_MANAGER | Restart-Service
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Restart-Servic
e], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.RestartServiceCommand
PS PS1:\>
Could anyone help me ? :) i'm still trying to learn powershell.
thanks

Unable to get PowerShell code to work

I am trying to run a script from my Active Directory host to the other hosts on the network that will pull device info for each of the hosts.
The code I am using is:
# Exports Local System Information to CSV
# Run this PowerShelll script at log on to collect PC information to a CSV file on a network share
# Thom McKiernan 28/08/2014
#Get hostnames
#$Computers = Get-Content ("C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\ComputerListAug2015.txt") -ErrorAction SilentlyContinue
foreach ($computer in Get-Content "C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\ComputerListAug2015.txt")
{
# Collect the info from WMI
$computerSystem = get-wmiobject Win32_ComputerSystem -Computer $computer.$deviceinfile
$computerBIOS = get-wmiobject Win32_BIOS -Computer $computer.$deviceinfile
$computerOS = get-wmiobject Win32_OperatingSystem -Computer $computer.$deviceinfile
$computerCPU = get-wmiobject Win32_Processor -Computer $computer.$deviceinfile
$computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $computer.$deviceinfile -Filter drivetype=3
$macAddress = Get-WmiObject win32_networkadapterconfiguration -Computer $computer.$deviceinfile -Filter "IpEnabled = TRUE"
#Build the CSV file
$csvObject = New-Object PSObject -property #{
"PCName" = $computerSystem.Name
"Manufacturer" = $computerSystem.Manufacturer
"Model" = $computerSystem.Model
"SerialNumber" = $computerBIOS.SerialNumber
"RAM" = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"HDDSize" = "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
"HDDFree" = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + "GB"
"CPU" = $computerCPU.Name
"OS" = $computerOS.caption
"SP" = $computerOS.ServicePackMajorVersion
"User" = $computerSystem.UserName
"BootTime" = $computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
"MACAddress" = $macAddress.MacAddress
}
#Export the fields you want from above in the specified order
$csvObject | Select PCName, Maufacturer, Model, SerialNumber, RAM, HDDSize, HDDFree, CPU, OS, SP, User, BootTime, MACAddress | Export-Csv 'system-info.csv' -NoTypeInformation -Append
}
# Open CSV file for review (leave this line out when deploying)
notepad system-info.csv
However, I am continuously getting the following error:
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
I have tried to set up the txt file as just computer names (exported from Active Directory) and I have tried to append each name with ".domain.com" and neither have worked.
I tried to have just my own device in the list, and no error occurred, but there was no output either. It was as if it didn't run when using "powershell -noexit .\ComputerDetails.ps1" but when I just run the script by right-clicking on it I can see the errors fly by, and an error from Notepad saying the file does not exist.
I have tried to google this issue, and found countless resources, that do not seem to help get rid of this error.
Full list of errors recieved:
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
the command again.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:12 char:63
+ $computerSystem = get-wmiobject Win32_ComputerSystem -Computer <<<< $compute
r.$deviceinfile
+ CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi
ngValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.GetWmiObjectCommand
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
the command again.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:13 char:51
+ $computerBIOS = get-wmiobject Win32_BIOS -Computer <<<< $computer.$deviceinf
ile
+ CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi
ngValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.GetWmiObjectCommand
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
the command again.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:14 char:60
+ $computerOS = get-wmiobject Win32_OperatingSystem -Computer <<<< $computer.$
deviceinfile
+ CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi
ngValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.GetWmiObjectCommand
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
the command again.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:15 char:55
+ $computerCPU = get-wmiobject Win32_Processor -Computer <<<< $computer.$devic
einfile
+ CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi
ngValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.GetWmiObjectCommand
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
the command again.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:16 char:61
+ $computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName <<<< $computer.
$deviceinfile -Filter drivetype=3
+ CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi
ngValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.GetWmiObjectCommand
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
the command again.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:17 char:72
+ $macAddress = Get-WmiObject win32_networkadapterconfiguration -Computer <<<<
$computer.$deviceinfile -Filter "IpEnabled = TRUE"
+ CategoryInfo : InvalidData: (:) [Get-WmiObject], ParameterBindi
ngValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.GetWmiObjectCommand
Attempted to divide by zero.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:27 char:53
+ "HDDFree" = "{0:P2}" -f ($computerHDD.FreeSpace/ <<<< $computerHDD.Size)
+ "GB"
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Export-Csv : A parameter cannot be found that matches parameter name 'Append'.
At C:\Users\Administrator.ESP\Documents\SoftwareAuditing\ComputerDetails\Comput
erDetails.ps1:37 char:183
+ $csvObject | Select PCName, Maufacturer, Model, SerialNumber, RAM, HDDSize, H
DDFree, CPU, OS, SP, User, BootTime, MACAddress | Export-Csv 'system-info.csv'
-NoTypeInformation -Append <<<<
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBind
ingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
ands.ExportCsvCommand
The issue you are having here is that PowerShell is trying to get the property defined by $deviceinfile from the object $computer. However $computer is just a string that does not have a property $deviceinfile. Is that supposed to be a suffix as part of your naming convention?
Brief Explanation of the issue
Look at the following example
$Computer = "comp1"
$deviceinfile = "Test"
$Computer.$deviceinfile
That returned nothing since there is not "Test" property on the $computer string object. I think the result you were expecting was comp1.Test. Now look at this example.
$deviceinfile = "Test"
$computer = New-Object -TypeName PSCustomObject -Property #{Test = "Bagel"}
$Computer.$deviceinfile
We made an object with a property called Test. "Bagel" is what is returned from that code.
What you can do in your code
If this is a naming convention you need to put that into quotes to stop it from being treated like a property call. Those variable will be expanded the way you would expect them. That is of course assuming you have $deviceinfile defined before it is called.
$computerSystem = get-wmiobject Win32_ComputerSystem -Computer "$computer.$deviceinfile"
Else just remove it.
$computerSystem = get-wmiobject Win32_ComputerSystem -Computer $computer

powerhsell remote wmi query failing

The following query asks for the credential password but then fails (I've also tried putting -credential between -computer and -filter:
$running = Get-WMIObject Win32_Process -computer servname -filter "Name =‘process.exe’” -credential domain\administrator
foreach ($objItem in $running){
write-host $objitem.Path
}
The error is:
PS C:\Users\ME> $running = Get-WMIObject Win32_Process -compute
r servername -filter "Name = 'process.exe'" -credential domain\administrator
Get-WmiObject : Invalid query
At line:1 char:25
+ $running = Get-WMIObject <<<< Win32_Process -computer 172.20.10.114 -filter
"Name = 'process.exe'" -credential domain\administrator
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], Managemen
tException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C
ommands.GetWmiObjectCommand
PS C:\Users\ME> foreach ($objItem in $running){
>> write-host $objitem.Path
>> }
>>
Thanks, Charlotte.
Copy & paste this:
$running = Get-WMIObject Win32_Process -computer servname -filter "Name ='process.exe'” -credential domain\administrator
check the char (')!