Receiving odd error message in PS script - powershell

I have a PowerShell script that goes out grabs the currently logged in user on a remote computer and gets the total size of their local profile C:\users\USERNAME\documents, pictures, music, etc. I have confirmed that the remote computer is online and the user is logged in. While the script is working, in the sense that it gets the folder size, it returns this message:
Get-WmiObject : Invalid parameter
At C:\Users\administrator\Desktop\get_folder_size.ps1:4 char:9
+ $user = Get-WmiObject Win32_ComputerSystem -ComputerName $system | Se ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
You cannot call a method on a null-valued expression.
At C:\Users\administrator\Desktop\get_folder_size.ps1:5 char:1
+ $pos = $user.IndexOf("\")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\administrator\Desktop\get_folder_size.ps1:6 char:1
+ $user = $user.Substring($pos+1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I'm confused because if I'm reading the message correctly it shouldn't be able to grab the username thus not get the correct folder and the size.
Here is the code that I'm running
foreach ($system in Get-Content "C:\net_view.txt")
{
$colItems = 0
$user = Get-WmiObject Win32_ComputerSystem -ComputerName $system |
Select-Object -ExpandProperty UserName
$pos = $user.IndexOf("\")
$user = $user.Substring($pos+1)
$path = $system +"\c$\users\" + $user
$colItems = (Get-ChildItem $path -Recurse -ErrorAction SilentlyContinue |
Measure-Object -property length -sum)
"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
Add-Content C:\users\administrator\desktop\profile_size.txt ($colItems.sum / 1MB)
Add-Content C:\users\administrator\desktop\profile_size.txt $system
}

Related

Powershell creating OU's

$DEPsOUs = #("A","B","C","D")
$createOUs = #('Users', 'Tester')
ForEach ($DEPOU In $DEPsOUs) {
$DEPOUDN = Get-ADOrganizationalUnit -Filter "Name -like '$DEPOU'" | select DistinguishedName | Format-Table -HideTableHeaders | Out-String
#write-host "$DEPOUDN" #checking if output is a string
ForEach ($createOU IN $createOUs) {
New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
}
}
this is the script, I just created some test OU's inside active directory. the script works but I get some weird issues which I don't understand.
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Users,
OU=A...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Tester,
OU=...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Users,
OU=B...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Tester,
OU=...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Users,
OU=C...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Tester,
OU=...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Users,
OU=D...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
New-ADOrganizationalUnit : The object name has bad syntax
At line:7 char:9
+ New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (OU=Tester,
OU=...,DC=local
:String) [New-ADOrganizationalUnit], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUni
t
can somebody clarify what is going on ? it creates the OU's with success but this issue appeared.i lauched it in Powershell ISE
I tried a few thing by converting it to string but doesn't really make sense to me when my arrays are string arrays.
You just need to expand the DistinguishedName attribute instead of using Format-Table (meant only for console display) and Out-String:
$DEPsOUs = #("A","B","C","D")
$createOUs = #('Users', 'Tester')
ForEach ($DEPOU In $DEPsOUs) {
$DEPOUDN = (Get-ADOrganizationalUnit -Filter "Name -eq '$DEPOU'").DistinguishedName
ForEach ($createOU IN $createOUs) {
New-ADOrganizationalUnit -Name $createOU -Path $DEPOUDN
}
}

Powershell scripting1

I am running this Script to get the directory listing
It was working few days ago but I keep having this error
New-PSSession : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty.
Provide an argument that is not null or empty, and then try the command again.
At C:\DEV\Powershell3\directory-listing.ps1:11 char:38
+ $session=New-PSSession -ComputerName $servers
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewPSSessionCommand
Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty.
Provide an argument that is not null or empty, and then try the command again.
At C:\DEV\Powershell3\directory-listing.ps1:31 char:25
+ Invoke-Command -Session $session -ScriptBlock $scb
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
$servers=get-content C:\temp\servers.txt
$session=New-PSSession -ComputerName $servers
$scb = {
Write-host "working on $env:COMPUTERNAME" -ForegroundColor Red
$volumes=Get-WmiObject win32_volume -Filter "drivetype=3"
foreach($volume in $volumes) {
$driveletter=$volume.driveletter
if($driveLetter -ne $null) {
$drivename=$volume.name
(Get-ChildItem -path $drivename -Directory) |Select-Object Name,FullName
}
}
}
Invoke-Command -Session $session -ScriptBlock $scb

Passing filepath parameters to function

Below mentioned code is giving error, and I'm not able to troubleshoot issue. Can anyone please help, we are just passing SourceFile and DestinationFile location to this function...
ProcessDocumentsData "D:\Files\Scan1.doc","D:\Files\Scan1.csv"
Clear-Host
function ProcessDocumentsData {
Param(
[string]$SourceFile,
[string]$DestinationFile
)
$DestinationFileName = $DestinationFile
$SourceFileName = $SourceFile
$tableNum = 13
$delimiter = ','
$objWord = New-Object -Com Word.Application
$objWord.Visible = $false # $false
$objDocument = $objWord.Documents.Open($SourceFileName)
$LETable = $objDocument.Tables.Item($tableNum)
$LETableCols = $LETable.Columns.Count
$LETableRows = $LETable.Rows.Count
$RawCSV = for($r=1; $r -le $LETableRows; $r++) {
$content= #()
for($c=1; $c -le $LETableCols; $c++) {
#Write-Host ("R:{0},C:{1}" -f $r,$c)
$content += ("`"{0}`"" -f $LETable.Cell($r,$c).Range.Text -replace "(`r|`n|`t)|$([char]7)?")
}
$Content -join $delimiter
}
$Csv = $RawCSV | ConvertFrom-Csv
$objDocument.Close()
$objWord.Quit()
# Stop Winword Process
$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objWord)
$Csv
$Csv | Export-Csv $DestinationFileName -NoTypeInformation
}
I'm getting the following error:
ProcessDocumentsData "D:\Files\Scan1.doc","D:\Files\Scan1.csv"
Command failed
At line:7 char:1
+ $objDocument = $objWord.Documents.Open($filename)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
You cannot call a method on a null-valued expression.
At line:8 char:1
+ $LETable = $objDocument.Tables.Item($tableNum)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:21 char:1
+ $objDocument.Close()
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
In PowerShell, when calling a function multiple parameters are delimited by a whitespace.
Try to call the function like that:
ProcessDocumentsData "D:\Files\Scan1.doc" "D:\Files\Scan1.csv"

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

powershell get-content path null error

$commonElementsLocation = ((Get-Location).Path + "\FolderMatchingCommonWords.txt")
if ($commonElementsLocation) {
$result += Start-Job -InitializationScript {
$commonElements = Get-Content -Path $commonElementsLocation
} -ScriptBlock $testScriptBlock -ArgumentList "testing" | Wait-Job | Receive-Job
}
Not sure what I am doing wrong here - probably a stupid mistake, but I put a condition around the Start-Job statement, and powershell still gives the following error:
Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:39
+ $commonElements = (Get-Content -Path $commonElementsLocation)
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentC
ommand
Running startup script threw an error: Cannot bind argument to parameter 'Path' because it is null..
+ CategoryInfo : OpenError: (localhost:String) [], RemoteException
+ FullyQualifiedErrorId : PSSessionStateBroken
In v3 add $using:
....(Get-Content -Path $using:commonElementsLocation...
You have already used a variable for a script block once with $testScriptBlock. You could just do that again for -InitializationScript?
$anotherSB = [scriptblock]::create("$commonElements = (Get-Content -Path $commonElementsLocation)")
$result += Start-Job -InitializationScript $anotherSB -ScriptBlock $testScriptBlock -ArgumentList "testing" | Wait-Job | Receive-Job