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

Remote Windows Updates Query

$
0
0

I found this code and am wondering where I can add a variable or how to query a remote machine with the below (I would like to do it throughout the AD OU tree):

#Get All Assigned updates in $SearchResult
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
#$UpdateSession = New-Object("Microsoft.Update.Session")
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")

#Matrix Results for type of updates that are needed
$Critical = $SearchResult.updates | where { $_.MsrcSeverity -eq "Critical" }
$important = $SearchResult.updates | where { $_.MsrcSeverity -eq "Important" }
$other = $SearchResult.updates | where { $_.MsrcSeverity -eq $null }

#Write Results
Write-Host "total=$($SearchResult.updates.count)"
Write-Host "critical=$($Critical.count)"
Write-Host "important=$($Important.count)"
Write-Host "other=$($other.count)"


Modify Non-Viewable attributes through Power Shell or Dos commands.

$
0
0

Hi,

I am trying to modifying the below information for existing users using CSV file. Could you help me to do it through Power Shell.

Scenario:

I have 50 Users where I want to modify "Othertelephone" & "info" for those object. These are AD attributes and you can see under respectively: General >> Telephone Number >>Other & Telephone >> Notes.

I want to look users from .csv file and modify above attributes for mentioned users in csv file.

Thanks

Shambhu Sharma

Currently, I have run the below commands which gave me error and come to know using New-ADUser or Set-ADUser I cannot modify as there is no such attributes belong to both commands.

Error:

Set-ADUser : A parameter cannot be found that matches parameter name 'info'.
At C:\altools\Info.ps1:1 char:115
+ Import-CSV "C:\altools\testaccount55.csv" | % { $User = $_.SamAccountName; $Info = $_.Info; Set-adUser $User -info <<
<<   $info }
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Otherway:

Set-ADUser : A parameter cannot be found that matches parameter name 'othertelephone'.
At C:\altools\Info.ps1:1 char:107
+ Import-CSV "C:\altools\testaccount55.csv" | % {$User = $_.SamAccountName; Set-adUser $User -othertelephone <<<<  $_.o
thertelephone -info $_.info}
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

My Script:

Import-CSV "C:\altools\testaccount55.csv" | % {$User = $_.SamAccountName; Set-adUser $User -othertelephone $_.othertelephone -info $_.info}

From my understanding these two attributed are not acceptable from New-ADUser and Set-ADUser Powershellcommand.

I am not sure whether we have any other option to put these do attributes data using the other command but importing the same csv file.

Absolutely cannot get hashtable columns to line up in email.

$
0
0

OK. So I have been working on a ps script (v2). Everything seems to work fine. editing and running from PowerGUI.

I have this section of code in a function:

$mismatch_ademail = New-Object PSObject -Property @{
LOGON = $_.sAMAccountName
FULLNAME = $rename_user
LASTNAME = $_.lastname
EMAIL = $userprop.Item("mail")
}

$Global:ADmismatch += $mismatch_ademail

If I do a $Global:ADmismatch the columns display on the screen just fine. When I add the variable to the email body nothing is lined it. The columns are there but but not lined up. Ive tried html and that didnt work either.

Here is what I have for email:

$SmtpServer = "smtp.domain.com"
$From = "TEST SCRIPT<AD_USER_UPDATE_SCRIPT@mhg.com>"
[string[]]$To = "user1@email.com"
$Message = New-Object System.Net.Mail.MailMessage( $From , $To )
$Message.Subject = "AD TEST SCRIPT:"
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SmtpServer)

 
Function sendMail
{
  If (!([string]::IsNullOrEmpty($Global:ADmismatch)))
  {
  $Body2 = $Global:ADmismatch | Format-Table -AutoSize | Out-String
  $Message.IsBodyHTML = $false  (also tried $true)
  $Message.body = $Body2
  $SMTPClient.Send($Message)
}

So i tried changing IsBodyHTML - $True (that makes everything in the body to go away.

I'm just trying to get how it looks on the screen to show up even half way like that in the email body. Right now it looks something like this.

FULLNAME LASTNAME LOGON EMAIL
------- -------  ------- ------
Jim A Bob Bob jbob jbob@email.com

Can someone help?

Thx

Export foldel ACL to Excel (Only Show 2 folder level depth)

$
0
0
How to export foldel ACL to Excel  (Only Show 2 folder level depth)

For example,
C:\abc folder
I only want to get NTFS ACL for folder with 2 folder level
C:\abc\XX\XX

And I don't want to get ACL for C:\abc\XX\XX\XX, only 2 folder depth is enough, export it to excel.

RDP and Network configuration verify script.

$
0
0
I have two script and i am trying to compile it to one. But while compiling these two i am not getting the expected output.  

 

Remote network status verification 

 

[cmdletbinding()]

param (

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

    [string[]]$ComputerName = $env:computername

)            

 

begin {}

process {

 foreach ($Computer in $ComputerName) {

 

  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

 

   $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}

 

   foreach ($Network in $Networks) {

 

    $DefaultGateway = $Network.DefaultIPGateway

    $DNSServers  = $Network.DNSServerSearchOrder

 

    $OutputObj  = New-Object -Type PSObject

    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway

    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers

    $OutputObj

   }

  }

 }

}            

 

end {}

Output 

 

get-Content .\serverl.ist.txt | ForEach-Object {.\getgw.ps1 -computername $_}

--------------------------------------------------

ComputerName                            Gateway                                 DNSServers

------------                            -------                                 ----------

QAVMFTC                              {10.247.98.1}                           {10.247.97.10, 10.247.97.11}

DNAS01                             {10.247.98.1}                           {10.247.97.10, 10.247.97.11}

DNAS01

DNAS01

DNAS01                             {198.18.2.1}                            {198.18.2.25, 198.18.2.26}

DNAS01

DNAS01

-------------------------- Output End----------------------------------------------

 

Remote Desktop Status verification 

 

param(

     [parameter(Mandatory=$true,ValueFromPipeline=$true)][string[]]$computername

     )

 

$results = @()

 

foreach($name in $computername){

 

        $result = "" | select Name,RDP

        $result.name = $name

 

        try{

           $socket = New-Object Net.Sockets.TcpClient($name, 3389)

           if($socket -eq $null){

                 $result.RDP = $false

           }else{

                 $result.RDP = $true

                 $socket.close()

           }

        }

        catch{

                 $result.RDP = $false

        }

        $results += $result

}

 

return $results

 

 Output

get-Content .\serverl.ist.txt | ForEach-Object {.\RDP_Port_verify -computername $_}

 

Name                                                                                                                                 RDP

----                                                                                                                                 ---

QAVMFTC                                                                                                                          True

dnas01                                                                                                                         True

------------------------------------------------------

Complied Script

Note: Complied Script does not show output as expected. It was suppose to show RDP and Network status together.But scirpt does not work the server which is having Multiple NIC cards.

 

 

[cmdletbinding()]

param (

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

    [string[]]$ComputerName = $env:computername

 

 

)            

 

 foreach ($Computer in $ComputerName) {

 

if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}

}

foreach ($Network in $Networks) {

   $DefaultGateway = $Network.DefaultIPGateway

       $DNSServers  = $Network.DNSServerSearchOrder

 }

}

 

##################################

 

$results = @()

 

foreach($Computer in $computername){

 ##

        $result = "" 

        try{

           $socket = New-Object Net.Sockets.TcpClient($name, 3389)

 

           if($socket -eq $null){

                 $result = $false

           }else{

                 $result = $true

                 $socket.close()

           }

        }

        catch{

                 $result.RDP = $false

        }

        $results += $result

}

 

 

    $OutputObj  = New-Object -Type PSObject

    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

    $OutputObj | Add-Member -MemberType NoteProperty -Name RDP -Value $results

    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway

    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers

    $OutputObj

 

---------------------------Output bellow--------------------------------------

get-Content .\serverl.ist.txt | ForEach-Object {.\test.ps1 -computername $_}

 

ComputerName                       RDP                                Gateway                          DNSServers

------------                       ---                                -------                          ----------

QAVMFTC                         {True}                             {10.247.98.1}                    {10.247.97.10, 10.247.97.11}

DNAS01                        {True}


Error while adding local user to a local group through powershell

$
0
0

I used the following command to set the password and add a group to the user :

$user=[ADSI]'WinNT://localhost/account5';
$user.SetPassword('Passw0rd#');
$OBjOU =[ADSI]'WinNT://localhost/Administrators,group';
$objOU.add($user.path);

The password is getting reset, but I am getting the following error while adding the account to the user :

A member could not be added to or removed from the local group because the member does not exist.

But the local member is already present and it is resting the password of the local user.

While trying to add a user to a group manually, the location in which the user is searched is by default a domain.The local user in the machine is not a part of this domain and so it cannot be added. When I select the location as local machine and then add the user, the user is getting added. This might be the reason for getting the above error. How can we change the location(in which to search for users) to the local machine through powershell commands?

Home directory creation for local user accounts using powershell

$
0
0

Through Computer Management when I create a user, a home directory is created for the same user in the folder C:\Users.I am creating a user through powershell in a remote machine.I am using the following script to create user 

$comp = [ADSI]'WinNT://localhost,computer';
$user = $comp.Create('User', 'account7');
$user.SetPassword('Welcome1');
$user.SetInfo();

The account is getting created. But no home directory is created for this user. How to create a home directory for a user using powershell? Also the user created through GUI is a member of the group 'Users' by default. How to add the user created to the 'Users'  Group.


cisco inventory

$
0
0

Hello,

i found a cisco inventory powershell script on the internet. but when i run this i'm getting some error how can i fix these.

#==================================================================================================
#              File Name : CiscoInventory.ps1
#        Original Author : Kenneth C. Mazie (kcmjr)
#            Description : As written it will poll Cisco routers and switches and if the snmp OID's
#                        :  match it will pull out model, serial, and IOS version.  The resulting 
#                        :  spreadsheet contains IP, host name, serial, model, IOS version, and
#                        :  rack location.
#
#                  Notes : Normal operation is with no command line options. 
#                        :  This PowerShell script was cobbled together from various sources around 
#                        :  the Internet. It was inspired by an article by David Davis over at ZDNet
#                        :  but came about because I had yet to find a PowerShell script to do what
#                        :  it does in any of my searches.  
#                        :
#                        : The script requires net-snmp tools. The script will first attempt to 
#                        :  ping a target, then process it if the ping succeeds. Our devices use a 
#                        :  standard naming convention of 12 characters. The script parses the host 
#                        :  name and determines the location of the device by what it finds in 
#                        :  character position 2 and 3 so you may want to remove that section or 
#                        :  edit it for your needs.
#                        :
#                        : The script creates an excel spreadsheet and saves it as a date & time 
#                        :  stamped file on the root of C:, so you need Excel installed.  Target 
#                        :  systems are read from a file named "devices.txt" that should reside in
#                        :  the same folder as the script and contain a list of target IP addresses,
#                        :  one per line.
#                        :
#               Warnings : None
#                        :
#                  Legal : Script provided "AS IS" without warranties or guarantees of any
#                        :  kind.  USE AT YOUR OWN RISK.  Public domain, no rights reserved.
#                        :  Please keep this header in tact if at all possible.
#                        : 
#                Credits : Code snippets and/or ideas came from many sources including but 
#                        : 
#         Last Update by : Kenneth C. Mazie 
#        Version History : v1.0 - 06-24-10 - Original 
#         Change History : v1.1 - 
#
#=======================================================================================

Clear-Host

#--[ Global presets ]----------------------------------
$Invocation = (Get-Variable MyInvocation -Scope 0).Value
#$ScriptPath = Split-Path $Invocation.MyCommand.Path
$strExe = "c:\usr\bin\snmpget.exe"    #--[ Set the location of the net-snmp tools bin folder ]---------
$strCommunity = " AMS-COMMUNITY"              #--[ set your community string ]---------

#--[ Assorted Excel presets settings ]----------------------------------
$xlAutomatic = -4105     # 
$xlBottom = -4107        # Text alignment bottom
$xlCenter = -4108        # Text alignment center
$xlContext = -5002       # Text alignment
$xlContinuous = 1        # 
$xlDiagonalDown = 5      # Cell line position
$xlDiagonalUp = 6        # Cell line position
$xlEdgeBottom = 9        # Cell line position
$xlEdgeLeft = 7          # Cell line position
$xlEdgeRight = 10        # Cell line position
$xlEdgeTop = 8           # Cell line position
$xlInsideHorizontal = 12 # Cell line position
$xlInsideVertical = 11   # Cell line position
$xlDash = -4115          # Dashed line
$xlDashDot = 4           # Alternating dashes and dots
$xlDashDotDot = 5        # Dash followed by two dots
$xlDot = -4118           # Dotted line
$xlDouble = -4119        # Double line
$xlNone = -4142          # No line
$xlSlantDashDot = 13     # Slanted dashes.
$xlThick = 4             # Thick line
$xlThin = 2              # Thin line
$sortCol = 5             # what column to place sort code in

#--[ Create Spreadsheet ]-------------------------------
$Excel = New-Object -comobject Excel.Application
$Excel.Visible = $True
$Excel = $Excel.Workbooks.Add(1)
$WorkSheet = $Excel.Worksheets.Item(1)
$WorkSheet.Cells.Item(1,1) = "Target IP"
$WorkSheet.Cells.Item(1,2) = "Hostname"
$WorkSheet.Cells.Item(1,3) = "Model #"
$WorkSheet.Cells.Item(1,4) = "Serial #"
$WorkSheet.Cells.Item(1,5) = "IOS Ver"
$WorkSheet.Cells.Item(1,6) = "Location"
$Workbook = $WorkSheet.UsedRange
$WorkBook.Interior.ColorIndex = 8
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
$WorkBook.EntireColumn.AutoFit()

#--[ Formatting ]----------------------------
$Col = 1
while ($Col -le 6){
	$Edge = 7
	while ($Edge -le 10){
		$WorkSheet.Cells.Item(1,$Col).Borders.Item($Edge).LineStyle = 1
		#$WorkSheet.Cells.Item(1,$Col).Borders.Item($Edge).Weight = 4   #--[ uncomment to make borders bold ]---------
		$Edge++
	}
	$Col++
}

#$arrDevices = @("192.168.10.2","192.168.10.252")
$arrDevices = Get-Content ($ScriptPath + "\devicelist.txt")

$intRow = 1
$count = 0

# NOTE: Cisco MIB for chassis serial # = mib-2.47.1.1.1.1.11.1001
# NOTE: Cisco MIB for chassis model # = mib-2.47.1.1.1.1.13.1001
# NOTE: Cisco MIB for IOS Ver = mib-2.47.1.1.1.1.13.1001
# NOTE: Cisco MIB for hostname = sysName.0

#--[ populate spreadsheet with data ]------------------
foreach ($strTarget in $arrDevices){ #--[ Cycle through targets ]--------
   $intRow = $intRow + 1 
   $WorkSheet.Cells.Item($intRow,1) = $strTarget #--[ Place Target IP in current row, column A ]----------
   Write-Host "Processing..... " $strTarget
   if (test-connection $strTarget) {
		if ($count = 5) {$count = 0}
		$strSerial = iex "cmd.exe /c `"$strExe -v 1 -c $strCommunity $strTarget mib-2.47.1.1.1.1.11.1001`""
		$strModel = iex "cmd.exe /c `"$strExe -v 1 -c $strCommunity $strTarget mib-2.47.1.1.1.1.13.1001`""
		$strIOS = iex "cmd.exe /c `"$strExe -v 1 -c $strCommunity $strTarget mib-2.47.1.1.1.1.9.1001`""
		$strHostName = iex "cmd.exe /c `"$strExe -v 1 -c $strCommunity $strTarget sysName.0`""
		#--[ If we get back a model place it in current row, column C ]----------
		if ($strModel.Length -gt 1) {$WorkSheet.Cells.Item($intRow,3) = ($strModel.Split(''))[1]} 
		#--[ If we get back a serial # place it in current row, column D ]----------
		if ($strSerial.Length -gt 1) {$WorkSheet.Cells.Item($intRow,4) = ($strSerial.Split(''))[1]}
		#--[ If we get back an IOS version place it in current row, column E ]----------
		if ($strIOS.Length -gt 1) {$WorkSheet.Cells.Item($intRow,5) = ($strIOS.Split(''))[1]}
		#--[ If we get back a hostname place it in current row, column B ]----------
		if ($strHostname.Length -gt 1) {
		$strHostName = ($strHostName.Split(''))[3]
		$WorkSheet.Cells.Item($intRow,2) = $strHostName 
		switch($strHostName.substring(1,2)) {"00" { $errorcode = 'Rack 00' }"01" { $errorcode = 'Rack 01' }"02" { $errorcode = 'Rack 02' }"03" { $errorcode = 'Rack 03' }"04" { $errorcode = 'Rack 04' }"05" { $errorcode = 'Rack 05' }"06" { $errorcode = 'Rack 06' }"07" { $errorcode = 'Rack 07' }"08" { $errorcode = 'Rack 08' }"09" { $errorcode = 'Rack 09' }"10" { $errorcode = 'Rack 10' }"11" { $errorcode = 'Rack 11' }"12" { $errorcode = 'Rack 12' }"13" { $errorcode = 'Rack 13' }"14" { $errorcode = 'Rack 14' }
           default { $errorcode = 'Unknown' }
        }  
        $WorkSheet.Cells.Item($intRow,6) = $errorcode #--[ Place location in current row, column F ]----------
	  }
   } 
else
{
   $WorkSheet.Cells.Item($intRow,2) = "Unreachable"       #--[ Place model # in current row, column B ]----------
		}
	$count = $count + 1
	if ($count =5) {$WorkBook.EntireColumn.AutoFit()}
}

	$WorkBook.EntireColumn.AutoFit() #--[ Adjust column width across used columns ]---------
	$WorkSheet.Cells.Item($intRow + 2, 1) = "DONE" 
	$strFilename = "c:\CiscoInventory-{0:dd-MM-yyyy_HHmm}.xls" -f (Get-Date)  #--[ Places a date stamped spreadsheet in the root of C: ]------
	$Excel.SaveAs($StrFilename)
	Write-Host ("Output saved to " + $strFilename)
	Write-Host "Done..."

Thanks!!


powershell get-aduser with two seperate fileds into on csv export

$
0
0

hello

is there any way i can use get-aduser to export two seperate ad fileds into one colume on csv export

basicaly i have description field: 1234, and Deptartment field with  "054321 - Human resources".  i need to export both fileds from get-aduser and dump into csv with one colume which would look like 1234.54321  ( i also want to remove 0 from dept.)

thx

Set-RegString - How to set Data that has $ character

$
0
0

Using PSRemoteRegistry / PSRR

trying to do:

"SERVER1" | Set-RegString -Key $key -Value "Value1" -Data "te$tValue1"

when I do:

"SERVER1" | Get-RegString -Key $key -Value "Value1"

the output of the -Data is : tetValue1

How can I put the $ sign in the Data?

how can copy source path of share folder to another destination share folder from CSV file through powershell 2.0 or 3.0

$
0
0

Hi

how can copy source path of share folder to another destination share folder from CSV file through PowerShell 2.0 or 3.0

Also if possible, can I get the same share and security permission from source to destination would be great..

I have CSV file with below format:

Sourceserver                                                   Destionationserver

\\server1\sharefolder\user1                            \\server3\sharefolder\user1

\\server1\sharefolder\user2                            \\server3\sharefolder\user2

\\server1\sharefolder\user3                              \\server3\sharefolder\user3

\\server1\sharefolder\user4                             \\server3\sharefolder\user4

Add security groups to t he folder acl

$
0
0

Hi,

I have the list of fodlers and the security permision which needs to be added. But i am not sure how to use this csv file to add the sec groups to the acl of the listed folders. am new to powershell and any help on this would be appreciated.

Example:

example\folder1 : e_f1

example\folder1\folder2 :e_f1_f2

example\folder3 : E_f3

example\folder3\folder4 : e_f3_f4

Error during Import-Module PSRR

$
0
0

I have the below specified in my Microsoft.PowerShell_profile.ps1 file

Import-Module PSRR

and I get the below error when launching PowerShell

At C:\Users\user\Documents\WindowsPowerShell\Modules\PSRR\Set-RegMultiString.ps1:16 char:4
+         []
+          ~
Missing type name after '['.
At C:\Users\user\Documents\WindowsPowerShell\Modules\PSRR\Set-RegMultiString.ps1:15 char:39
+         [Alias('CN','__SERVER','IPAddress')]
+                                             ~
Parameter declarations are a comma-separated list of variable names with optional initializer expressions.
At C:\Users\user\Documents\WindowsPowerShell\Modules\PSRR\Set-RegMultiString.ps1:15 char:39
+         [Alias('CN','__SERVER','IPAddress')]
+                                             ~
Missing ')' in function parameter list.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingTypename


I can Import-Module PSRR manually without any errors. Any idea?

How to check a csv file is blank or not using powershell script

$
0
0
Hi,

I am new to windows shell scripting, infact i have no experience at all,but i have a small requirement, Can someone please help me with it?

I have a csv file in this location C:\temp\abc.csv

So, now i have to write a powershell script which will basically check and see if this file is empty or has any data. I cannot go by the size because even if its empty it has the header rows from a sql table and if it gets the data from sql table also the size remains to be 1 KB. So, i think we need to see if this file has any rows other than the header row and return a yes or no.


Can someone please help me with this?

Thanks

Set Registry Key on HKCU:\Software\Policies

$
0
0

Hi, i have a software that needs to add some keys into the registry HKCU:\Software\Policies

But it turns that even this is Current User Key, the user don't have rights to this Key.

I seem to be able to modify everything under HKCU but in this folder the user has only read permissions.

Why?

Is there a way to grant user Full control of this Key and subkeys without giving him Local Admin Rights?

Can i modify this with  a startup script even though this is a HKCU ?

Thanks


powershell using adsi with alternate credentials

$
0
0

Hi,

I would like to check the local admin groups on a list of servers in another domain.

I have a domain admin account there.

I found this script snippet that get's the info for me in the domain I am currently loged on to.

$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
  $Group = $computer.psbase.children.find("Administrators")
  $members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

Is there a way to supply Alternate Credentials for this query? Or is there another method to do this?

Old Dog

Close all popups pulled from running a an executable

$
0
0

I have been using PowerShell to automate some functions.  One of them is when I call an exe file to process user accounts.  The exe file produces a popup.  It looks like a form with no options but to use the x in the corner to close.

Is there a command in PowerShell that will close all opened popups?


pfcjt@hotmail.com

Connect to different domain controller

$
0
0
What will be powershell script to connect  to different domain controller from powershell module to AD?

Getting extensionAttribute1 using Get-ADComputer

$
0
0

All,

I am trying to check extensionAttribute1 value for computer accounts in an OU. I am running the following command

$Computer = Get-ADComputer Filter * -Searchbase <OU path> -Properties *

It runs perfectly and I believe all the information is stored in $Computer. But the extensionAttribute1 is not visible under $Computer (using PowerGUI). However there is a property of $Computer named PropertyNames and I can see extensionAttribute1 under there. 

Can someone please tell me how I can get this value? I would like to do something like this in the bigger picture

1. Get all properties of all the computers (done using Get-ADComputer) and store it in $Computer

2. For each computer under $Computer, get the value of extensionAttribute1

3. If extensionAttribute is X, do something. If it is not X, do something else.

Thanks.

Send email when new file is created in a folder

$
0
0

Main idea here is to send an email when i new file or folder is created in some path.

for $body it should say new file detected: FILENAMEHERE

$path = "Z:\"
$limit=$(Get-Date).AddMinutes(-1)
$sendmail= $To="me@domain.com";$From= "administrator@domain.com";$Subject = "new file created";$Body= "New File Detected";$Message = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body;$smtpServer = "smtp.domain.com";$smtp = new-object Net.Mail.SmtpClient($smtpServer);$smtp.EnableSsl = $false;$smtp.Credentials= New-Object System.net.NetworkCredential("administrator@domain.com","password");$smtp.Send($message);
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit} | Then {$sendmail}

Viewing all 21975 articles
Browse latest View live


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