Powershell creating OU's - powershell

$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
}
}

Related

Download all pdfs on a webpage with PowerShell

I found online the following code to download all the pdfs on a webpage:
$psPage = Invoke-WebRequest "https://www.pi.infn.it/~rizzo/ingegneria/appunti_fisII_ing_mecc/
"
$urls = $psPage.ParsedHtml.getElementsByTagName("A") | ? {$_.href -like "*.pdf"} | Select-Object -ExpandProperty href
$urls | ForEach-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Split-Path -Leaf)}
but PS gave me the error:
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not
available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing
parameter and try again.
At C:\Users\Raffaele\Desktop\Nuova cartella\a.ps1:1 char:11
+ $psPage = Invoke-WebRequest "https://www.pi.infn.it/~rizzo/ingegneria ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebReq
uestCommand
You cannot call a method on a null-valued expression.
At C:\Users\Raffaele\Desktop\Nuova cartella\a.ps1:2 char:1
+ $urls = $psPage.ParsedHtml.getElementsByTagName("A") | ? {$_.href -li ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Split-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\Raffaele\Desktop\Nuova cartella\a.ps1:4 char:66
+ ... h-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Split-Path -Leaf)}
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Split-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.S
plitPathCommand
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\Users\Raffaele\Desktop\Nuova cartella\a.ps1:4 char:48
+ $urls | ForEach-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Spli ...
+ ~~
+ CategoryInfo : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebReques
tCommand
How can I overcome this problem? Why it requires internet explorer engine?
EDIT: I tried to modify the code in this way:
$site = "https://www.pi.infn.it/~rizzo/ingegneria/appunti_fisII_ing_mecc/"
$psPage = Invoke-WebRequest -Uri $site -UseBasicParsing
$urls = $psPage.ParsedHtml.getElementsByTagName("A")
$urls | where {$_.pathname -like "*pdf"} | % {Invoke-WebRequest -Uri "$site$($_.pathname)" -OutFile $_.pathname }
and the error is:
You cannot call a method on a null-valued expression.
At C:\Users\Raffaele\Desktop\Nuova cartella\a.ps1:3 char:1
+ $urls = $psPage.ParsedHtml.getElementsByTagName("A")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
EDIT 2 I tried to modify the code in this way. New code:
$psPage = Invoke-WebRequest -Uri -UseBasicParsing "https://www.pi.infn.it/~rizzo/ingegneria/appunti_fisII_ing_mecc/"
$urls = $psPage.ParsedHtml.getElementsByTagName("A") | ? {$_.href -like "*.pdf"} | Select-Object -ExpandProperty href
$urls | ForEach-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Split-Path -Leaf)}
The Windows PowerShell gave me a new error:
Invoke-WebRequest : Missing an argument for parameter 'Uri'. Specify a parameter of type 'System.Uri' and
try again.
At C:\Users\Raffaele\Desktop\Nuova cartella\b.ps1:1 char:29
+ $psPage = Invoke-WebRequest -Uri -UseBasicParsing "https://www.pi.inf ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
You cannot call a method on a null-valued expression.
At C:\Users\Raffaele\Desktop\Nuova cartella\b.ps1:2 char:1
+ $urls = $psPage.ParsedHtml.getElementsByTagName("A") | ? {$_.href -li ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Split-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\Raffaele\Desktop\Nuova cartella\b.ps1:3 char:66
+ ... h-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Split-Path -Leaf)}
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Split-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.S
plitPathCommand
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\Users\Raffaele\Desktop\Nuova cartella\b.ps1:3 char:48
+ $urls | ForEach-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Spli ...
+ ~~
+ CategoryInfo : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebReques
tCommand
In your way : First you have to remove "about:" in your URL or replace it by nothing :
$site = "https://www.pi.infn.it/~rizzo/ingegneria/appunti_fisII_ing_mecc/"
$psPage = Invoke-WebRequest $site
$urls = $psPage.ParsedHtml.getElementsByTagName("A") | ? {$_.href -like "*.pdf"} | Select-Object -ExpandProperty href | ForEach-Object {$_.replace("about:", "")}
Second you have to recreate full URL :
$urls | ForEach-Object {Invoke-WebRequest -Uri "$site$_" -OutFile $_ }
But you can simplify using "textcontent" or "pathname" :
$site = "https://www.pi.infn.it/~rizzo/ingegneria/appunti_fisII_ing_mecc/"
$psPage = Invoke-WebRequest $site
$urls = $psPage.ParsedHtml.getElementsByTagName("A")
$urls | where {$_.pathname -like "*pdf"} | % {Invoke-WebRequest -Uri "$site$($_.pathname)" -OutFile $_.pathname }

In windows powershell ISE, trying to bulk update people information. I get this error message

I'm trying to bulk update people information. I get this error message.
The users2.csv file contains this:
UserPrincipalName,Company,CountryOrRegion,DisplayName,Fax,FirstName,Initials,LastName,MobilePhone,Phone,Title,WindowsEmailAddress,Name
test#bio-dynamics.be,Bio-Dynamics,Belgium,Test,Test,Test,Test,Test,Test,Test,Test,test#bio-dynamics.be,Test
test2#bio-dynamics.be,Bio-Dynamics,France,Test2,Test2,Test2,Test2,Test2,Test2,Test2,Test2,test2#bio-dynamics.be,Test2
The error message is this:
PS C:\WINDOWS\system32> Import-Csv "c:\scripts\users2.csv" | ForEach {Set-user UserPrincipalName $_.UserPrincipalName -Company $_.company -CountryOrRegion $_.CountryOrRegion -DisplayName $_.DisplayName -Fax $_.Fax -FirstName $_.FirstName -Initials $_.Initials -LastName $_.LastName -MobilePhone $_.MobilePhone -Phone $_.Phone -Title $_.Title -WindowsEmailAddress $_.WindowsEmailAddress -Name $_.Name}
A positional parameter cannot be found that accepts argument 'test#bio-dynamics.be'.
+ CategoryInfo : InvalidArgument: (:) [Set-User], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Set-User
+ PSComputerName : outlook.office365.com
A positional parameter cannot be found that accepts argument 'test2#bio-dynamics.be'.
+ CategoryInfo : InvalidArgument: (:) [Set-User], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Set-User
+ PSComputerName : outlook.office365.com
Can anybody help point me toward the problem? Thank you so much!

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

Add a disk on my virtual machine Azure

I am doing the this tutorial https://technet.microsoft.com/library/mt771177.aspx
The thing is I made my virtual machine and asign to the lun a 0.
The problem is I don t quite understand what does it mean to asign 0 to lun, and how does it affect that the following scrip to fail.
disk=Get-Disk | where {$_.PartitionStyle -eq "RAW"}
$diskNumber=$disk.Number
Initialize-Disk -Number $diskNumber
New-Partition -DiskNumber $diskNumber -UseMaximumSize -AssignDriveLetter
Format-Volume -DriveLetter F
disk=Get-Disk : The term 'disk=Get-Disk' 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.
At line:1 char:1
+ disk=Get-Disk | where {$_.PartitionStyle -eq "RAW"}
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (disk=Get-Disk:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Initialize-Disk : Cannot validate argument on parameter 'Number'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At line:3 char:25
+ Initialize-Disk -Number $diskNumber
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Initialize-Disk], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Initialize-Disk
New-Partition : Cannot validate argument on parameter 'DiskNumber'. The argument is null. Provide a valid value for
the argument, and then try running the command again.
At line:4 char:27
+ New-Partition -DiskNumber $diskNumber -UseMaximumSize -AssignDriveLet ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-Partition], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,New-Partition
Format-Volume : No MSFT_Volume objects found with property 'DriveLetter' equal to 'F'. Verify the value of the
property and retry.
At line:5 char:1
+ Format-Volume -DriveLetter F
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (F:Char) [Format-Volume], CimJobException
+ FullyQualifiedErrorId : CmdletizationQuery_NotFound_DriveLetter,Format-Volume
You're not setting the variable correctly.
Your code...
disk=Get-Disk | where {$_.PartitionStyle -eq "RAW"}
Needs to have a $ in front to make "disk" a variable
$disk = Get-Disk | where {$_.PartitionStyle -eq "RAW"}

Receiving odd error message in PS script

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
}