Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Create User PowerShell

$
0
0

Hi friends.

I have a problem with code:

Import-Module Activedirectory

Import-Csv user_conservacao.csv | ForEach-Object{

New-ADUser -Name $_."Nome Completo" -AccountPassword (ConvertTo-SecureString "123456789@WSs" -

AsPlainText -Force) -DisplayName $_."Nome Completo" -GivenName $_."Nome" -Surname $_."Sobrenome" 

-UserPrincipalName $_."account" -SamAccountName $_."samaccount" -Enabled $true -Path 

"OU=Company,OU=Users,OU=Unit,OU=Operactions,DC=Company,DC=local" -verbose

}

They execute normally, more not create nothing in the my AD.

Any sugestions



Assign licenses by OU

$
0
0

I'm working on changing our O365 licenses for 8000+ users.  I need to assign student licenses to accounts in the 'student' OU.  I need to assign employee licenses to users in other OUs.  Is there a way to do it?  How?

Get-msoluser does not output anything with an OU in it so it's out. 

I can filter for users who currently have an old student license to change their license but what about users without a license?  Likewise, I can filter for users who currently have an old employee license but what about users without a license?

Currently I have these scripts as a starting point:

Get-MsolUser -enabledfilter enabledonly -MaxResults 2000 -UnlicensedUsersOnly | fl

Get-MsolUser -all  | fl | where {$_.Licenses -contains 'STANDARDWOFFPACK_STUDENT'}

Get-MsolUser -all  | fl | where {$_.Licenses -contains 'STANDARDWOFFPACK_FACULTY'}

Thanks for any help.

user creation - ou path syntax - lookup path and place it into a variable

$
0
0

We have nested OUs with long complex paths but each OU has a unique name. 

Example - this works: 

$MyName = "Joe Blow"

$MyOUPath = "OU=BigClient Tiny District,OU=BigClient Northwest Region,OU=BigClient Western Area,OU=BigClient,OU=Hosting,DC=HostingProvider,DC=net"

New-ADUser -Name "$MyName" -Path "$MyOUPath"

(Other new-user parameters omitted for clarity)

Example - this doesn't work: 

$MyName = "Joe Blow"

$MyOU = "BigClient Tiny District"

$MyOUPath = dsquery ou -name "$MyOU"

New-ADUser -Name "$MyName" -Path "$MyOUPath"

(other new-user parameters omitted for clarity)

In other words, I'd like to specify the unique OU name in my script and have the script look up the DN and supply that as a variable for the path. It works if I type the entire OU path into the $MyOUPath variable. Using dsquery appears to work at the command line to lookup the OU path and place that in the variable, I can see correct results of dsquery in write-host, but when I supply the results of the dsquery lookup in the new-user command for the path, the new-user command fails. 

It says the object name has bad syntax. 

Hope this makes sense. 


Bill Coulter


add new dfsnamespace server

$
0
0

Hi 

I am adding new dfsnamespace server from below command but getting error:

dfsutil root adddom \\testserver.contos.com\TIBUSDFSROOT

Error: 

Could not execute the command successfully
SYSTEM ERROR - The version of the operating system installed on this server is incompatible with the functio
 the domain or forest.

I have 2003 server DFL and FFL as well and running it on windows 2008 R2 servers.

We have some txt files, Zip files that needs to be deleted which are 7 days older

$
0
0

Hello All,

Can you help me with a link or proper guidance. I am looking for a script to delete the older file in a drive example D, which includes deleting in all the subfolders also which are 7 days old. I am thinking to run in a task scheduler weekly once so that i can clean thi up 

Thanks 

xxxx

Update McAfee Dat on multiple remote servers

$
0
0

Hi All, am new to PS scripting, i have a small requirement , i need to update mcafee dat on multiple remote servers without login to them, so with PS script i tried with following code but it is not working , can someone help me to correct this.

$RemoteServers = Get-Content "c:\logs\McAfee\Servers.txt"

        @(

           foreach ($Server in $RemoteServers)

          {

            if ( Test-Connection -ComputerName $RemoteServer -Count 1 -ErrorAction SilentlyContinue )

            {

              

              $Path='c:\Program Files (x86)\McAfee\VirusScan Enterprise\mcupdate.exe'

              $parameters='/update /quiet'

              $Path='c:\Program Files (x86)\McAfee\Common Framework\CmdAgent.exe /p'

            }

            else

            {

            $Path='C:\Program Files\Mcafee\VirusScan Enterprise\mcupdate.exe'

            $Parameters='/update /quiet'

            $Path='c:\Program Files\McAfee\Common Framework\CmdAgent.exe /p'

            Write-Output "$name is unrechable please check the server either from ilo or VC console"

            }

          }

            )|Out-File -FilePath 'c:\logs\McAfee\McAfe_DAT.Update.csv'

 


taking data from XML using powershell

$
0
0

Hi,

I have a XML file like:

<?xml version="1.0" encoding="UTF-8"?>

-<classes>


-<classes type="array">


-<class><class_pk type="integer">3900</class_pk><teacher_fk type="integer">2805</teacher_fk>


-<meeting_times type="array">


-<meeting_time><block>3rd period Primary</block><block_abbreviation>3PP</block_abbreviation><day>Monday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>4th period Primary</block><block_abbreviation>4PP</block_abbreviation><day>Monday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>5th period Primary</block><block_abbreviation>5PP</block_abbreviation><day>Monday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>8th period Primary</block><block_abbreviation>8PP</block_abbreviation><day>Monday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>9th period Primary</block><block_abbreviation>9PP</block_abbreviation><day>Monday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>Homeroom Primary E</block><block_abbreviation>HMP</block_abbreviation><day>Monday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>2nd period Primary</block><block_abbreviation>2PP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>3rd period Primary</block><block_abbreviation>3PP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>4th period Primary</block><block_abbreviation>4PP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>5th period Primary</block><block_abbreviation>5PP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>8th period Primary</block><block_abbreviation>8PP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>9th period Primary</block><block_abbreviation>9PP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>Homeroom Primary E</block><block_abbreviation>HMP</block_abbreviation><day>Tuesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>2nd period Primary</block><block_abbreviation>2PP</block_abbreviation><day>Wednesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>3rd period Primary</block><block_abbreviation>3PP</block_abbreviation><day>Wednesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>4th period Primary</block><block_abbreviation>4PP</block_abbreviation><day>Wednesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>5th period Primary</block><block_abbreviation>5PP</block_abbreviation><day>Wednesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>Homeroom Primary E</block><block_abbreviation>HMP</block_abbreviation><day>Wednesday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>1st period Primary</block><block_abbreviation>1PP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>3rd period Primary</block><block_abbreviation>3PP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>4th period Primary</block><block_abbreviation>4PP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>5th period Primary</block><block_abbreviation>5PP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>8th period Primary</block><block_abbreviation>8PP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>9th period Primary</block><block_abbreviation>9PP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>Homeroom Primary E</block><block_abbreviation>HMP</block_abbreviation><day>Thursday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>1st period Primary</block><block_abbreviation>1PP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>2nd period Primary</block><block_abbreviation>2PP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>3rd period Primary</block><block_abbreviation>3PP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>4th period Primary</block><block_abbreviation>4PP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>5th period Primary</block><block_abbreviation>5PP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>8th period Primary</block><block_abbreviation>8PP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>Homeroom Primary E</block><block_abbreviation>HMP</block_abbreviation><day>Friday</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time>


-<meeting_time><block>Homeroom Primary M</block><block_abbreviation>HMP</block_abbreviation><day>M-F</day><end_time/><grading_period>ALL</grading_period><room>P212</room><start_time/></meeting_time></meeting_times></class>

I need to take data from this file as:

Class_pkTeacher_fkDayblockblock_abbreviationroomgrading_period
39002805Monday3rd period Primary3PPP212ALL
39002805Monday4th period Primary4PPP212ALL

and import in to my SQL database.

Can somebody help me please?

I am new on this...

import-csv scripting issue

$
0
0

Hi all,

I have an issue with using a csv as input for a script to add multiple workergroups to a xenapp published app. I have created a csv with a custom delimiter ";" because the paramater value needed to add multiple workergroups need to be seperated by a comma.

In my csv the exported data looks like this after running this command.

Get-XAApplicationReport * |where {($_.ApplicationType -ne"Content") -and($_.ApplicationType -ne"ServerDesktop") -and($_.Enabled -eq"True")} |selectBrowserName,@{n="WorkerGroups";e={[string]::join(",",$_.WorkerGroupNames)}},Folderpath | export-csv c:\workergroup.csv-Delimiter";"-NoTypeInformation  

CSV content:

"Test_APP_NAME";"CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo";"Applications/TEST"

When running the following script

$vars=Import-Csvc:\workergroups.csv-Delimiter";"-Header "BrowserName","WorkerGroups","FolderPath"

Foreach ($line in $Vars)

{

Set-XAApplication-BrowserName$line.BrowserName -WorkerGroupNames $line.WorkerGroups -Enabled$True

  }

It wil interpret the "CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo" (without quotes) as a single name instead of 2 names seperated by the comma. Resulting in an error because that combined name ofcourse does not exsist. Running the command  manually wil work fine.

If i run trace-command "Trace-Commandparameterbinding-Expression"  

Trace-Command parameterbinding -Expression {Set-XAApplication -BrowserName $line.BrowserName -WorkerGroupNames $line.WorkerGroups -Enabled $True} -PSHost

with the script i see the following :

DEBUG: ParameterBinding Information: 0 :                 Parameter and arg types the same, no coercion is needed.

DEBUG: ParameterBinding Information: 0 :             Adding scalar element of type String to array position 0

DEBUG: ParameterBinding Information: 0 :         Executing VALIDATION metadata: [System.Management.Automation.ValidateNotNullOrEmptyAttribute]

DEBUG: ParameterBinding Information: 0 :         BIND arg [System.String[]] to param [BrowserName] SUCCESSFUL

DEBUG: ParameterBinding Information: 0 :     BIND arg [CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo] to parameter [WorkerGroupNames]

DEBUG: ParameterBinding Information: 0 :         COERCE arg to [System.String[]]

DEBUG: ParameterBinding Information: 0 :             Trying to convert argument value from System.String to System.String[]

DEBUG: ParameterBinding Information: 0 :             ENCODING arg into collection

DEBUG: ParameterBinding Information: 0 :             Binding collection parameter WorkerGroupNames: argument type [String], parameter type [System.String[]],

Which results in:

Set-XAApplication : Cannot find worker group with name CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo (0x80000001 Failure.)
At line:1 char:45
+ Trace-Command parameterbinding -Expression {Set-XAApplication -BrowserName $line ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (CTX-WG-NewBuild...Build-10.6-Silo:String) [Set-XAApplication], CitrixException
    + FullyQualifiedErrorId : FindWorkerGroupByName,Citrix.XenApp.Commands.SetAppCmdlet
 

When running the same trace-command but with the parameters filled in manually all works fine and i see this:

Trace-Command parameterbinding -Expression {Set-XAApplication -BrowserName "Test_APP_NAME" -WorkerGroupNames CTX-WG-NewBuild-10.6,CTX-WG-NewBuild-10.6-Silo} -PSHost

DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Set-XAApplication]
DEBUG: ParameterBinding Information: 0 :     BIND arg [Test_APP_Name] to parameter [BrowserName]
DEBUG: ParameterBinding Information: 0 :         COERCE arg to [System.String[]]
DEBUG: ParameterBinding Information: 0 :             Trying to convert argument value from System.String to System.String[]
DEBUG: ParameterBinding Information: 0 :             ENCODING arg into collection
DEBUG: ParameterBinding Information: 0 :             Binding collection parameter BrowserName: argument type [String], parameter type [System.String[]], coll
ection type Array, element type [System.String], coerceElementType
DEBUG: ParameterBinding Information: 0 :             Creating array with element type [System.String] and 1 elements
DEBUG: ParameterBinding Information: 0 :             Argument type String is not IList, treating this as scalar
DEBUG: ParameterBinding Information: 0 :             COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 :                 Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 :             Adding scalar element of type String to array position 0
DEBUG: ParameterBinding Information: 0 :         Executing VALIDATION metadata: [System.Management.Automation.ValidateNotNullOrEmptyAttribute]
DEBUG: ParameterBinding Information: 0 :         BIND arg [System.String[]] to param [BrowserName] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 :     BIND arg [System.Object[]] to parameter [WorkerGroupNames]
DEBUG: ParameterBinding Information: 0 :         COERCE arg to [System.String[]]
DEBUG: ParameterBinding Information: 0 :             Trying to convert argument value from System.Object[] to System.String[]
DEBUG: ParameterBinding Information: 0 :             ENCODING arg into collection
DEBUG: ParameterBinding Information: 0 :             Binding collection parameter WorkerGroupNames: argument type [Object[]], parameter type [System.String[]
], collection type Array, element type [System.String], coerceElementType
DEBUG: ParameterBinding Information: 0 :             Arg is IList with 2 elements
DEBUG: ParameterBinding Information: 0 :             Creating array with element type [System.String] and 2 elements
DEBUG: ParameterBinding Information: 0 :             Argument type System.Object[] is IList
DEBUG: ParameterBinding Information: 0 :             COERCE collection element from type String to type System.String
DEBUG: ParameterBinding Information: 0 :             COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 :                 Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 :             Adding element of type String to array position 0

The difference i see is that the later one is converted from a System.Object[] to System.String[] and the line that is used from the CSV is converted from a System.String to System.String[].

Can anyone give me a hint to whats going wrong and what i might be able to do to fix it?


Rename folder on multiple locations

$
0
0

I have different data path for offices on different locations.
Sometimes a folder needs to be renamed, but this has to be done on all locations at once.

Very often it isn't possible since users on one or more locations are working on documents within this folder, so the rename action cannot take place.

In that case I need to revert back the name of the data path on the locations where it was possible to change the folder name.

I think this could be done easier.

I have an csv file which contains paths to data folders on various locations.

Now I would like to have a script which asks for a folder name and the script will check on all paths listed in the csv file if the folder can be renamed. If there are no issues, the rename action will take place, if it isn't possible on any one of the locations the folder won't be renamed.

is it possible to setup a script like this ?

Querying result of a command

$
0
0

Hi,

Below is a script I have written with aim of checking if users in an OU have a particular group in there calendar access permission and if not to add a specified permission.

$OU = Get-Mailbox -OrganizationalUnit "ou=IT Users,dc=Blickrothenberg,dc=lan" -resultsize unlimited

$OU | foreach-object{Get-mailboxfolderpermission -identity $_":\Calendar" | where-object -FilterScript {$_.identity -like 'Restricted*'} | ft identity | Out-String

If($_.Identity -ne "RestrictedCalendarAccess"){Add-MailboxFolderPermission -Identity $_":\Calendar" -user 'RestrictedCalendarAccess' -AccessRights None}
}

The problem I have is that it retrieves the permissions for the users but then tries to add the permissions to all the users queried rather than just the ones without the group. Can anyone tell me where I am going wrong?

Inserting a Date/Time stamp to a file name

$
0
0

I want to create a script that will allow me top copy a file addign a date/time stamp to the file name, and delete the original one.

Can someone help me. I've seen a lot of samples but its not very clear to me.


Paul Arbogast

Pipe PS Job data to text file

$
0
0

I converted a "serial" ForEach loop to use Start-Job to kick off a bunch of remote jobs in parallel.  The script loop uses a combination of local commands and PSRemote Invoke-Command's. 

I'm using: Receive-Job $JOBNAME | Out-File .\results.txt as some form of logging. 

What I noticed is that command output that executed locally echoes to the console on Receive-Job, and only the Invoke-Command is piped out to .\results.txt on Receive-Job.

I haven't worked much with Receive-Job in the past, but is this behavior by design?  How can I get all the output piped to a single file?

Example:

Start-Job -Name $SERVER -ScriptBlock {

Write-Host "Running this task on $($SERVER) ..."

Invoke-Command -ComputerName $SERVER -ScriptBlock {Write-Host "Remote command"}

}

When running Receive-Job $SERVER | Out-File .\results.txt:

Running this task on MYSERVER is echoed to the console (but not the results.txt)"

"Remote command" is piped to results.txt (but not on console).

System.Management.Automation.PSNotImplementedException

$
0
0

I am using ManagementScope to login to a server remotely and do some powershell transactions. It is throwing the following exception-

"A first chance exception of type 'System.Management.Automation.PSNotImplementedException' occurred in System.Management.Automation.dll"

How do I fix this ?

Exchange Calendar permission

$
0
0

I would like to give all mailboxes 'Owner' access to all other mailboxes, i.e. all users should be 'owner' of each other's calendar.

To test this, I started it trying to give all mailboxes access to a small list of users but I get an error message. My code is:

****

$list =  ("John.Smith","Alison.Smith","Bernice.Smith","Hilary.Smith")

$allusers = Get-Mailbox | Select -ExpandProperty Alias

Foreach ($user in $list) {Add-MailboxFolderPermission $user":\Calendar" -user $allusers -accessrights Owner}

****

The error I get is:

Cannot process argument transformation on parameter 'User'. Cannot convert the "System.Collections.ArrayList" value of
type "System.Collections.ArrayList" to type "Microsoft.Exchange.Management.StoreTasks.MailboxFolderUserIdParameter".
    + CategoryInfo          : InvalidData: (:) [Add-MailboxFolderPermission], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-MailboxFolderPermission

I think the problem is that I can't use an array for the -User part of the command?

Any help is much appreciated.

Get-ADComputer to query Organizational Unit for active computers

$
0
0

Hi,

I've been looking at creating a powershell script that queries an active directory organizational unit for computers and lists if they're powered on by pings and ideally exports them to a .txt file

Import-Module active*
$rtn = $null
Get-ADComputer -Filter * |
ForEach-Object {
  $rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet
  IF($rtn -match 'True') {write-host -ForegroundColor green $_.dnshostname}
  ELSE { Write-host -ForegroundColor red $_.dnshostname }
}

This script queries our active directory and pings the devices and lists if the device is active by showing the name as green and the same with red for computers it can't ping.

Rather than query our whole active directory I want it to query a particular OU, so I've added in the code;

Import-Module active*
$rtn = $null
Get-ADComputer -Filter "OU=Machines,OU=IT,DC=local,DC=network,DC=co,DC=uk"
ForEach-Object {
  $rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet
  IF($rtn -match 'True') {write-host -ForegroundColor green $_.dnshostname}
  ELSE { Write-host -ForegroundColor red $_.dnshostname }
}

But when I run the script I get this, I can't seem to be able to query AD's organizational unit

Get-ADComputer : Error parsing query: 'OU=Machines,OU=IT,DC=local,DC=network,DC=co,DC=uk' Error Message: 'Ope
rator Not supported: =' at position: '3'.
At line:3 char:15+ Get-ADComputer <<<<  -Filter "OU=Machines,OU=IT,DC=local,DC=network,DC=co,DC=uk"+ CategoryInfo          : ParserError: (:) [Get-ADComputer], ADFilterParsingException+ FullyQualifiedErrorId : Error parsing query: 'OU=Machines,OU=IT,DC=local,DC=network,DC=co,DC=uk' Error
    Message: 'Operator Not supported: =' at position: '3'.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

Test-Connection : 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 comman
d again.
At line:5 char:29
+   $rtn = Test-Connection -CN <<<<  $_.dnshostname -Count 1 -BufferSize 16 -Quiet+ CategoryInfo          : InvalidData: (:) [Test-Connection], ParameterBindingValidationException+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand

though I can run this against the OU and it brings back the list of machines in that OU;

$ou = [ADSI]"LDAP://OU=Machines,OU=IT,DC=local,DC=network,DC=co,DC=uk"
foreach ($child in $ou.psbase.Children) {
    if ($child.ObjectCategory -like '*computer*') { Write-Host $child.Name }
}

Does anyone have any idea on what specific cmdlets for this filter/search I need to do?

Thanks


Counting how many times a specific string shows up in a CSV file

$
0
0
I'm pretty much brand new to scripting so I'm going to try to explain this as best as I can haha. I'm trying to write a script that uses an excel file that was converted to a CSV and imported into powershell. My goal is to allow the user to type in "low" and have it bring up a unique list of vulnerabilities that are low with a count of how many times each one shows up in the csv file. The only thing I'm missing in my script is the ability to get a count of vulnerabilities that are low without having each plugin number show up and have the count be 1.

here's what I'm getting:

plugin severity count
-----------------------
1        low       1
1        low       1
1        low       1
2        low       1
2        low       1
3        low       1

what I want:

plugin severity count
-----------------------
1        low       3
2        low       2
3        low       1

Best way to access\set AD user attributes not retrieved by Get\Set Aduser

$
0
0

Hi,

I need to set a value in the MS-DS-cloudExtensionattribute20 attribute for a large volume of User accounts, which is not accessed by Get\Set Aduser.  Is Get\Set-Item the recommended approach or some other technique?


Thanks for your help! SdeDot

How To Use powershell.exe –command “&{}” ?

$
0
0

Hello all!

I have a PowerShell script which works as intended through PowerShell, however I want to run the script using the powershell.exe –command {} approach because the script is going to be a recovery script from SCOM and I don’t want have to store the actually script as a .ps1 file in a central repository. MY problem is that when I use the powershell.exe –command {} approach the script bombs. I am assuming that this because the script is running through the CLI, which is not likening the import for some reason. I just don’t have the skills to figure that part out and hopping someone the forums could help out in this space.

Here is my code that I am placing in the {} using this command: powershell.exe –command “&{}”

#filter the system log for events from Server Administrator, level 2, and event ID 2387
$query = @"<QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='Server Administrator'] and (Level=2) and (EventID=2387)]]</Select></Query></QueryList>"@

#retrieve only the latest bad blocks error
$OMerror = Get-WinEvent -FilterXml $query -MaxEvents 1

#obtain variables for controller ID and virtual disk ID from event log
$controllerID = $OMerror.message.Split()[-4]
$vdiskID = $OMerror.message.split()[-7]

#run command to clear bad blocks
omconfig storage vdisk action=clearvdbadblocks controller=$controllerID vdisk=$vdiskID

#log error
new-eventlog -LogName System -source Metrics -ErrorAction SilentlyContinue
Write-EventLog -logname System -source Metrics -eventID 52368 -Message "Running SCOM script to clear bad blocks on controller=$controllerID and vdisk=$vdiskID" 

Does anyone know what I need to do in order to get things to work when using the -Command argument? The script works as intended when saved as a .ps1 file. 

Cheers!

-Tony



Turn on PowerShell Transcription Group Policy

$
0
0

The What's New in PowerShell 5.0 article says:

Windows PowerShell transcription has been improved to apply to all hosting applications (such as Windows PowerShell ISE) in addition to the console host (powershell.exe). Transcription options (including enabling a system-wide transcript) can be configured by enabling the Turn on PowerShell Transcription Group Policy setting, found in Administrative Templates/Windows Components/Windows PowerShell.

I tried using the Group Policy Management Editor from a Windows 10 workstation, but could not locate that setting.

What am I missing?

Unable to export to csv format

$
0
0

Folks,

Im generating a report of all the recent errors recorded on the event viewer, but when i run the get-eventlog with the export-csv switch, i get the data scrambled-

*Normal Way:

*After i try to export it to a csv file-

PS U:\Applications> Get-EventLog -LogName System -EntryType Error -Newest 100 | Format-Table -Wrap | Export-Csv u:\Last100Errors.csv

Do suggest how this can be sorted out.


Cheers, Alan.

Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>