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

Adding a computer object to a group?

$
0
0

I can add a user with no problem:

Add-ADGroupMember "test_group" -Members 'testuser'

When i am adding a computer i am getting an error:

Add-ADGroupMember : Cannot find an object with identity: 'ComName' under:

However Get-adcomputer ComName works with no issues and test-connection works as well.

what am i missing?

Thank you.


Waiting a process appearing before continuing

$
0
0

Hi,

I have that commandline in batch file:

:LOOP1
tasklist /fi "imagename eq java.exe" /fi "WindowTitle eq Oracle Universal Installer" |find ":" > nul
if errorlevel 1 goto LOOP1
How may I convert it in Powershell?

Thanks,

Remove column from Csv

$
0
0

Hi Experts,

I need to split the csv file with delimiter "," and remove  first two column and last column using Power shell, How to do it, No Heading is available for this CSV file.

start,75678,9/22/2016 6:19,NULL,11254,Severe,end
start,678906,9/22/2016 9:44,NULL,Severe,end

API to copy Nuget packages to local folder using Powershell

$
0
0

Hi,

I'm new to powershell and I want to copy some selected packages from Nuget(https://www.nuget.org) to my local folder using Powershell script.

Please suggest.

Thanks.

Trouble with extraction of multiline AD "Notes" field

$
0
0

Hi guys,

I'm not an expert on Powershell nor english, but I have a problem that I can't find a solution: I need to extract all the text inside the notes field from some AD groups to CSV, and other information, like name or description (among others). I'm running the commands inside Server 2K8 R2 with PS 2.0 (I don't have rights to upgrade or another Windows Server OS). This works fine for a single line "Notes" field:

Get-ADGroup "My Group" -Properties Info | Select Info
#Result:
#My Group				Some Fancy Text

These DON'T work at all for multiline "Notes":

#Joining with `n,`r,`t,[char]0x0a00 or space doesn't work:
Get-ADGroup "My Group" -Properties Info | Select Name,@{n='Info';e={[String]::Join(" ",($_.Info))}}

#Using same chars from join for replace doesn't work too:
Get-ADGroup "My Group" -Properties Info | Select Name,@{n='Info';e={($_ | Select -Expa $_.Info) -Replace " ",";"}}

#I don't know if it's the proper use of OFS, but still the same:
Get-ADGroup "My Group" -Properties Info | Select Name,@{n='Info';e={$OFS=";";$_.Info}}

#All what this shows is the group OU+.info in the end of the line:
Get-ADGroup "My Group" -Properties Info | Select Name,@{n='Info';e={"$_.Info"}}

#Results from all the above (except last command):
My Group				Some...

Let's try again using only the Info attribute:

#Running this:
(Get-ADGroup "My Group" -Properties Info | Select Info) -Join "`n",";"
#Returns:
@{Info=Some
Fancy
Text}

#Running This:
(Get-ADGroup "My Group" -Properties Info | Select Info) -Replace "`n",";"
#Returns:
@{Info=Some;Fancy;Text}

Can someone explain me what the hell is going and how do I solve this?

need help with AD and buttons

$
0
0

Hello together

I Need help concerning create a button .

You see below my Code, but he doesn´t work well.
I want to create a button and then if I click ´the button I can create a user with a Password (AD User). And then I want to create some Folders and datas for him. At least I want to give him some permissions.

Can anyone help me?
I know the code is rubbish

[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
$form= New-Object Windows.Forms.Form
$button = New-Object Windows.Forms.Button
$button.text = "Click Here! TO CREATE A User"
$form.controls.add($button)
$form.ShowDialog()



mohamedhassan_99@hotmail.com

PowerShell Script With Alerts.

$
0
0

The script below works (script1) but has an issue. It contains password. I have modified the script (script2) but for some reason it does not work. I am not sure what I am doing wrong.

Script1 start

##################################################################################
#       Author:Prakash Yadav
# Reviewer: Vikas Sukhija
#       Date: 12/20/2013
#       Description: Schedule Event Failed script.
##################################################################################

#####Declare variables & add logging###################

$email1 = "TestAcct@abc.com"
$from = "TestAcct@abc.com"
$smtpserver = "smtp.office365.com"
$smtpport = "587"
$username = "TestAcct@abc.com"
$password = "Password@1"

$action = "Restart" ###########value should be Restart or Shutdown##############

$resserver=@()

#################Define Logs#############
$date1 = get-date -format d
# replace \ by -
$time = get-date -format t

$date1 = $date1.ToString().Replace("/", "-")

$time = $time.ToString().Replace(":", "-")
$time = $time.ToString().Replace(" ", "")

$logs = ".\Logs" + "\" + "Powershell" + $date1 + "_" + $time + "_.txt"

Start-Transcript -Path $logs

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


##Add server that needs to be restarted or shutdown

$server_list=get-content .\servers.txt
if($server_list -eq $null)

{
write-host "List is empty - script will quit"
exit

}

## Loop thru each server one by one

if ($action -like "Restart")

{

 foreach ($i in $server_list)
 {
 
 restart-Computer $i -Force

 If(Test-Connection -ComputerName $i -Count 10 -Delay 5 -Quiet)
  {

  If(Test-Connection -ComputerName $i -count 2 -Delay 5 -Quiet)
   {
 
   $subject ="System $i is still responding - pls check"
   Write-host "system $i stuck" -ForegroundColor blue
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
  }
 else
  {   
  $resserver += $i
  $subject ="System restart started for $i"
                Write-host "system $i restart process started" -ForegroundColor green
  $message = new-object Net.Mail.MailMessage
  $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
        $smtp.EnableSSL = $true
        $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)
        $message.From = $from
  $message.To.Add($email1)
  $message.subject = $subject
  $smtp.Send($message)
  $message.dispose()
  }
  
  
  }
 } 
  timeout 600
  write-host $resserver  
foreach ($i in $resserver)
  {
  write-host "process $i"
    If(Test-Connection -ComputerName $i -count 5 -Delay 5 -Quiet)
  
      {
  
   $subject ="System Restart for $i Successful"
                        Write-host "System Restart for $i Successful" -ForegroundColor green
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
      }
     else
      {
      $subject ="System Restart for $i failed"
   Write-host "System Restart for $i failed" -ForegroundColor blue
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
      }
      }
  
}
 
if ($action -like "Shutdown")
{

 foreach ($i in $server_list)
 {
 
 Stop-Computer $i -Force

 If(Test-Connection -ComputerName $i -Count 10 -Delay 5 -Quiet)
  {

  If(Test-Connection -ComputerName $i -count 2 -Delay 5 -Quiet)
   {
 
   $subject ="System Shutdown for $i Restart Failed - please check"
   Write-host "System Shutdown for $i Restart Failed - please check" -ForegroundColor blue
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
  }
 else
  {

  $subject ="System has been Shutdown for $i"
  Write-host "System has been Shutdown for $i" -ForegroundColor green
  $message = new-object Net.Mail.MailMessage
  $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
        $smtp.EnableSSL = $true
        $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)
        $message.From = $from
  $message.To.Add($email1)
  $message.subject = $subject
  $smtp.Send($message)
  $message.dispose()
  }

     }
   }
}

Stop-Transcript
##########################################################################################################

Script1 end

I am looking for a way to work around (no password in the script). I updated the script but not working for me.

Script2 start

##################################################################################
#       Author:Prakash Yadav
# Reviewer: Vikas Sukhija
#       Date: 12/20/2013
#       Description: Schedule Event Failed script.
##################################################################################

#####Declare variables & add logging###################

$email1 = "TestAcct@abc.com"
$from = "TestAcct@abc.com"
$smtpserver = "smtp.office365.com"
$smtpport = "587"
$username = "TestAcct@abc.com"
$password = cat C:\Shutdown-Restart\securestring.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $password

$action = "Restart" ###########value should be Restart or Shutdown##############

$resserver=@()

#################Define Logs#############
$date1 = get-date -format d
# replace \ by -
$time = get-date -format t

$date1 = $date1.ToString().Replace("/", "-")

$time = $time.ToString().Replace(":", "-")
$time = $time.ToString().Replace(" ", "")

$logs = ".\Logs" + "\" + "Powershell" + $date1 + "_" + $time + "_.txt"

Start-Transcript -Path $logs

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


##Add server that needs to be restarted or shutdown

$server_list=get-content .\servers.txt
if($server_list -eq $null)

{
write-host "List is empty - script will quit"
exit

}

## Loop thru each server one by one

if ($action -like "Restart")

{

 foreach ($i in $server_list)
 {
 
 restart-Computer $i -Force

 If(Test-Connection -ComputerName $i -Count 10 -Delay 5 -Quiet)
  {

  If(Test-Connection -ComputerName $i -count 2 -Delay 5 -Quiet)
   {
 
   $subject ="System $i is still responding - pls check"
   Write-host "system $i stuck" -ForegroundColor blue
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $cred)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
  }
 else
  {   
  $resserver += $i
  $subject ="System restart started for $i"
                Write-host "system $i restart process started" -ForegroundColor green
  $message = new-object Net.Mail.MailMessage
  $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
        $smtp.EnableSSL = $true
        $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $cred)
        $message.From = $from
  $message.To.Add($email1)
  $message.subject = $subject
  $smtp.Send($message)
  $message.dispose()
  }
  
  
  }
 } 
  timeout 600
  write-host $resserver  
foreach ($i in $resserver)
  {
  write-host "process $i"
    If(Test-Connection -ComputerName $i -count 5 -Delay 5 -Quiet)
  
      {
  
   $subject ="System Restart for $i Successful"
                        Write-host "System Restart for $i Successful" -ForegroundColor green
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $cred)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
      }
     else
      {
      $subject ="System Restart for $i failed"
   Write-host "System Restart for $i failed" -ForegroundColor blue
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $cred)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
      }
      }
  
}
 
if ($action -like "Shutdown")
{

 foreach ($i in $server_list)
 {
 
 Stop-Computer $i -Force

 If(Test-Connection -ComputerName $i -Count 10 -Delay 5 -Quiet)
  {

  If(Test-Connection -ComputerName $i -count 2 -Delay 5 -Quiet)
   {
 
   $subject ="System Shutdown for $i Restart Failed - please check"
   Write-host "System Shutdown for $i Restart Failed - please check" -ForegroundColor blue
   $message = new-object Net.Mail.MailMessage
   $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
            $smtp.EnableSSL = $true
            $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $cred)
            $message.From = $from
   $message.To.Add($email1)
   $message.subject = $subject
   $smtp.Send($message)
   $message.dispose()
  }
 else
  {

  $subject ="System has been Shutdown for $i"
  Write-host "System has been Shutdown for $i" -ForegroundColor green
  $message = new-object Net.Mail.MailMessage
  $smtp = new-object Net.Mail.SmtpClient($smtpserver, $smtpport)
        $smtp.EnableSSL = $true
        $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $cred)
        $message.From = $from
  $message.To.Add($email1)
  $message.subject = $subject
  $smtp.Send($message)
  $message.dispose()
  }

     }
   }
}

Stop-Transcript
##########################################################################################################

Script2 end

Add Users/Groups/Folders/Datas

$
0
0

hello everyone
I wrote a script which should create a user, within a Password, Folders (if they want to) and so one.
But I got a Problem.

I got 2 Buttons, the first one is to create a user you know? ($buttonp)
How can I create now in that a ADUser function?

Great where also, if I can create for the user Folders/permissions and so one too?

Can anyone help me?

#form
$form = New-Object Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(2300,2030)
$Form.StartPosition = "CenterScreen"
$Form.Text = "Create a User" #title

#first Button:
$CbuttonP = New-Object Windows.Forms.Button
$CbuttonP.Text = "Create a User"
$CbuttonP.Left = 100
$CbuttonP.Top = 100
$CbuttonP.Width = 500
$CbuttonP.Height = 250
#Click-Aktion dem Button beifügen
$CbuttonP.Add_Click( {$script:answer = "User"; $form.close()} )

#second Button:
$CbuttonD = New-Object Windows.Forms.Button
$CbuttonD.Text = "show users"
$CbuttonD.Left = 1120
$CbuttonD.Top = 100
$CbuttonD.Width = 500
$CbuttonD.Height = 250
$CbuttonD.Add_Click( {$script:answer = "users"; $form.close()} )

$form.Controls.Add($CbuttonP)
$form.Controls.Add($CbuttonD)
$form.ShowDialog() | Out-Null


mohamedhassan_99@hotmail.com


Create a user in button

$
0
0

Hello dear

I wrote this Code see below.
If you execute the Code, you can see two Buttons, a "create a user" button and another one.
If I click on "create a user" button, nothing happens.
What does it miss , that I can create a user, if I click on the button.

#form
$form = New-Object Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(2300,2030)
$Form.StartPosition = "CenterScreen"
$Form.Text = "Create a User" #title

#first Button:
$CbuttonP = New-Object Windows.Forms.Button
$CbuttonP.Text = "Create a User"
$CbuttonP.Left = 100
$CbuttonP.Top = 100
$CbuttonP.Width = 500
$CbuttonP.Height = 250
#Click-Aktion dem Button beifügen
$CbuttonP.Add_Click( {$script:answer = "User"; $form.close()} )

#second Button:
$CbuttonD = New-Object Windows.Forms.Button
$CbuttonD.Text = "show users"
$CbuttonD.Left = 1120
$CbuttonD.Top = 100
$CbuttonD.Width = 500
$CbuttonD.Height = 250
$CbuttonD.Add_Click( {$script:answer = "users"; $form.close()} )

$form.Controls.Add($CbuttonP)
$form.Controls.Add($CbuttonD)
$form.ShowDialog() | Out-Null

Kind regards


mohamedhassan_99@hotmail.com

How to change font size in Excel Comment

$
0
0
Is there a way to change font size in MS Excel Comment (Excel 2010) ? Thanks

Create user / folders in button

$
0
0

Hi everybody
I Need some help.
I wrote this Code see below.
Now my main question is, that I want to create a user with the $buttonp.
If you see, I wrote this

$CbuttonP.Add_Click( ( $Username = Read-Host " Give your user a name" $form.close() ) )

But nothing work.
My aim is it, that if I click on $buttonp that I get the opportunity to create some users.

full Code:

#form
$form = New-Object Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(2300,2030)
$Form.StartPosition = "CenterScreen"
$Form.Text = "Create a User" #title

#first Button:
$CbuttonP = New-Object Windows.Forms.Button
$CbuttonP.Text = "Create a User"
$CbuttonP.Left = 100
$CbuttonP.Top = 100
$CbuttonP.Width = 500
$CbuttonP.Height = 250
#Click-Action dem Button beifügen
$CbuttonP.Add_Click( ( $Username = Read-Host " Give your user a name" $form.close() ) )

#second Button:
$CbuttonD = New-Object Windows.Forms.Button
$CbuttonD.Text = "show users"
$CbuttonD.Left = 1120
$CbuttonD.Top = 100
$CbuttonD.Width = 500
$CbuttonD.Height = 250
$CbuttonD.Add_Click( {$script:answer = "users"; $form.close()} )

$form.Controls.Add($CbuttonP)
$form.Controls.Add($CbuttonD)
$form.ShowDialog() | Out-Null


mohamedhassan_99@hotmail.com

create Tool for creating users

$
0
0
Hello everyone
Im supposed to do a tool in WPS inthat I can create some users.
I created two buttons.
Now how can I continue, because I want to create with my first button ($buttonp) some users.
See code below:

#form
$form = New-Object Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(2300,2030)
$Form.StartPosition = "CenterScreen"
$Form.Text = "Create a User" #title

#first Button:
$CbuttonP = New-Object Windows.Forms.Button
$CbuttonP.Text = "Create a User"
$CbuttonP.Left = 100
$CbuttonP.Top = 100
$CbuttonP.Width = 500
$CbuttonP.Height = 250
#Click-Aktion dem Button beifügen
$CbuttonP.Add_Click( $script:answer = $Username | new-ad; $form.close()} )

#second Button:
$CbuttonD = New-Object Windows.Forms.Button
$CbuttonD.Text = "show users"
$CbuttonD.Left = 1120
$CbuttonD.Top = 100
$CbuttonD.Width = 500
$CbuttonD.Height = 250
$CbuttonD.Add_Click( {$script:answer = "users"; $form.close()} )

$form.Controls.Add($CbuttonP)
$form.Controls.Add($CbuttonD)
$form.ShowDialog() | Out-Null

$Username = Read-Host "give a name"
$Password = Read-Host "give a password"

Thanks

mohamedhassan_99@hotmail.com

Notification when outlook email arrives

$
0
0

Hi,

I've written a small script that will hopefully run a taskbar alert notification when an email arrives in my inbox.  So far all it does is searches through an inbox folder and calls the function if it finds the matching sender:

#Function to fire up system tray notifications

Function TaskTrayAlert email, subject, body {

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon

$objNotifyIcon.Icon = "C:\Windows\System32\PerfCenterCpl.ico"
$objNotifyIcon.BalloonTipIcon = "Info"
$objNotifyIcon.BalloonTipText = "Press a button"
$objNotifyIcon.BalloonTipTitle = "Outlook File Contents"
 
$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(20000)
}

 

#Code to search inbox
 $info = New-Object -ComObject Outlook.Application
 $objNamespace = $info.GetNamespace("MAPI")
 $objFolder = $objNamespace.GetDefaultFolder(6).Folders.Item("Alerts")
 $colItems = $objFolder.Items
 foreach ($item in $colItems) {
 If ($item.SenderEmailAddress -eq "Bill.Smith@newsgroup") {
 ("$($item.SenderEmailAddress) `t $($item.SentOn) `t $
 ($item.Subject)")
TaskTrayAlert
 }
 }

The problem I am facing is that my code loops through the complete folder each time. What I really need is for it to find all 'New' items maybe using a real-time monitor or perhaps if it was runing a scheduled task.

I was also thinking maybe if the powershell script was called from an Outlook alert rule but if this is the case is there a way to parse the email for subject body etc add this to the alert information,

Any help

Thanks

Error in code

$
0
0

Hello everybody
I want to create the $buttonb with Outlook, so that if I click on the button, that I can send a mail.

Watch out my Code:

#Layout Mail send
$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)

#2 = high importance email header
$mail.importance = 2
$dasganzgrosseSkript = { Add-Type -AssemblyName Microsoft.VisualBasic
$mail.subject = [Microsoft.VisualBasic.Interaction]::InputBox('write subject', 'subject', $mail.subject)
$mail.body = [Microsoft.VisualBasic.Interaction]::InputBox('write mail', $mail.body )
$mail.To = [Microsoft.VisualBasic.Interaction]::Inputbox('write mailadress', $mail.to )
}


#fourth Button:
$Cbuttonb = New-Object Windows.Forms.Button
$Cbuttonb.Text = "create mail"
$Cbuttonb.Left = 100
$Cbuttonb.Top = 300
$Cbuttonb.Width = 250
$Cbuttonb.Height = 50
$Cbuttonb.Add_Click( {&($DasganzgrosseSkript);$form.close()} )

It doesnt work.

But why?
My aim is to click on button four and do the mail.

The button is called


mohamedhassan_99@hotmail.com

Get-Eventlog

$
0
0

I'm trying to retrieve a list of security event logs from a host. I need to pull the count, event code (instanceID) and the name of each event code. 

Currently I have the following command: 

Get-EventLog -LogName Security | group-object InstanceId | Select-Object Count, Name |  Sort-Object Count -Descending

But I'm getting the following results: 

Count Name
----- ----
95318 4688
 7935 4673
 1088 4985
  832 4624
  647 4907
  578 4672
  375 4634

In addition to what I am able to get, I would like to add another column that lists the name of each code. For example: 

Count Name Message
----- ---- ----
95318 4688 A new process has been created. 

Thank you in advance for your help. 




Check for privileged account

$
0
0

Hi Guy's,

I'm trying to pull a list of users from an OU and check if there is another account lets call these "Priv-UID" where the privileged account will just have "Priv-" at the start. I can pull the list from the OU but I'm having trouble trying to generate a list of "Priv" accounts to check.  

Here is the code I'm trying to use:

#Get all users and check if there is a privileged account#
$DisabledUsers = Get-ADuser -LDAPFilter '(name=*)'-SearchBase 'OU=Enterprise,DC=corp,DC=com'| FT SamAccountName
foreach ($user in $DisabledUsers) {        $PrivAccount += -join "priv-"+$user    }      $PrivAccount

Issue is I keep getting this back at the moment:

Priv-Microsoft.PowerShell.Commands.Internal.Format.FormatEntryDataPriv-Microsoft.PowerShell.Commands.Internal.Format.GroupEndData


My next step after this is to try and use the table against get users in AD something like below.

if (Get-ADUser $PrivAccount -eq $true) {$PrivAccount += $RealAccount} 

Any help with the error's and advice if this is the correct direction would be awesome, Thanks you.


Powershell 3.0 command in combination with CredSSP

$
0
0

Hi all,

I wrote a Powershell script to discover and install a SCOM Agent on Linux servers. This script involves a command that requires Powershell 3.0 or higher, the command is:

Invoke-SCXDiscovery -Name $MonitoredServer -ResourcePool $Pool -WsManCredential $WSCredential -SshCredential $SSHcredential

So far so good, when I run the script in my Powershell 4.0 it works perfect. But the purpose of this script, is to be used remotely with CredSSP, and as soon as I do that, I get the following error:

Error: This cmdlet requires PowerShell version 3.0 or greater.

All servers involved run Powershell 4.0, also when I log the value of $PSVersionTable it Always says version 4.0, but I do keep getting this error. Does anyone have a suggestion to get this work?

What is the best way to distrubute powershell script?

$
0
0

Hi

We have developed couple of script. Some of the script has static and dynamic variables. Now I want to share the script with my end users, but dont want any user should see the code. Secondly some of the script will pushed thru GPO whenever user logged in.

Now my question what is the best way to distribute PowerShell script i.e. create exe or cmdlet?

Avian

get-aduser filtered on OU level

$
0
0

Hi in my Domain test.local I want to get users from severals OUs

when I use

Get-ADUser -Filter {(DistinguishedName -like "*") }

I get all users of my domain

when I use

Get-ADUser -Filter {(DistinguishedName -like "*DC=local") }

I get no users. This is strange because every  DistinguishedName of my users should end with DC=local.

My goal is to get all users of my domain exept those from ~10 OUs.  


ADSI password reset is not working with alternative credentials

$
0
0

Hello, 

im trying to reset a domain user using admin permission but it is not working and giving below error 

 

Exception setting "PwdLastSet": "The following exception occurred while 
retrieving member "PwdLastSet": "Unknown error (0x80005000)""
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationExceptio 
   n
    + FullyQualifiedErrorId : ExceptionWhenSetting
    + PSComputerName        : secedu-admin.secedu.qa

The following exception occurred while retrieving member "SetInfo": "Unknown 
error (0x80005000)"
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemExceptio

any help please

$ComputerName= "remote_server"
$Credential = Get-Credential
$NewPassword = "P@ssw0rd"
$User = "domain\user"
Invoke-Command -ComputerName $ComputerName -Credential $Credential -ErrorVariable e -ArgumentList $NewPassword,$User -ScriptBlock {
            Param($ComputerName,$NewPassword,$User)
            $Account = [adsi]$user="WinNT://my_DC/$user,user"
            $Account.PwdLastSet = 0
            $Account.SetInfo()
            $Account.SetPassword($NewPassword)
            $Account.SetInfo()

        }



Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer"

Viewing all 21975 articles
Browse latest View live


Latest Images