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

Backing up Eventlogs

$
0
0

I am currently backing up the event logs via powershell and have noticed that not all event logs are being backed up.  I am using the WMI Class Win32_NTEventLogFile. 

When I run the following cmdlet, I does not return all the event logs.  Ones that are missing, are the event logs that are listed under the Microsoft folder in the EventViewer under the application and services logs.

Get-WMIObject -Class Win32_NTEventLogFile

I have tried to use Get-ChildItem specifying the path to the event logs, but the cmdlet does have the properties I need. (MaxfileSize, OverWritePolicy).

Is there a cmdlet or WMI Class that I can use to get the remaining event Logs that provides the same of similar properties?

Thanks.

DJ


Trying to change the ACL of a domain user

$
0
0

I am using the Set-Acl cmdlet to add a user to another user's domain account so that the second user will be able to read the permissions available to the first user.  I get an error on the very last line "this security id may not be assigned as the owner of this object".  I suspect that perhaps the error is caused because I am not permitted to change the owner of the account and the code is trying to do a wholesale rewrite of the ACL.  I am allowed to add the entry to the account through the UI and that is all I want to do via powershell.  Any ideas?

$name1 = "someuser" #this is the user whose acl I want to edit
$name2 = "someotheruser"  #this is the user that I want to add to the first user's acl
$objUser = Get-ADUser -LDAPFilter "(sAMAccountName=$Name1)"
$objDelegate = New-Object System.Security.Principal.NTAccount("$name2")
Set-Location AD:
$dn = $objUser.DistinguishedName
$Acl = (Get-Acl $dn)
$Ar = New-Object system.DirectoryServices.ActiveDirectoryAccessRule ($objDelegate,"GenericRead","Allow",$objUser.ObjectGUID)
$Acl.AddAccessRule($Ar)
Set-Acl -Path $dn -AclObject $Acl

Forms in PowerShell: Update form based on script progress

$
0
0

Hello all,

For lack of a better post title, what I have is a simple script that loops through files in a directory and checks them for stuff. What I'd like to do is, while my script is checking the files, display a form with only one single-line field in it, and that field updates with the current file variable the script is checking. This would kind of be like when you're installing a program, and in the installation window above the progress bar it has a single-line field where it lists each file while it's currently installing. I'd like something similar, but I don't need the progress bar. I'd like to just have a single form and have only this single "file" field change, but I worry that I'll have to redisplay the entire form in some kind of "loop" every time I want the field to change. I'd like to display the form once and only have the field change.

Has anyone ever made a form like this, or know of a way I can accomplish this?


Automatically generate a response to a powershell command?

$
0
0

I am executing a powershell script i.e commands in a ps1 file. To run any powershell script on a system, you have to first run Set-ExecutionPolicy RemoteSigned and then ENTER y manually. Only after that, you can run ps scripts. Is there a way I can automatically enter y along with the command to enable powershell scripts ?

Demo:

PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. 
Changing the execution policy might expose you to the security risks described 
in the about_Execution_Policies help topic. Do you want to change the execution 
policy? [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

Keep Receiving: Error is: 'Insufficient access rights to perform the operation' When running script

$
0
0

Hello. I have a powershell script I run in our domain to disable AD accounts. Part of that also removes the users from all AD groups. That part of my script however keeps throwing up this Error is: 'Insufficient access rights to perform the operation' error. 

Now from our Exchange server if I run this script with powershell, things work fine. But running it on the domain controller is when I get this error. Thoughts? 

Disable-UMMailbox performance slow

$
0
0

Can anyone explain why this command processes slowly for Exchange 2007 mailboxes? Might process 10 users then appears to stall for 30-60 seconds. Setting the results of Get-UMMailbox to a variable then piping it results in the same slow performance.

Get-UMMailbox | Disable-UMMailbox

How to execute a ruby command stored in a variable in powershell

$
0
0

I am executing a command of the form rake drive:unit_tests:load_data parameters here'. I get the erroris 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.`

I used the code in my ps1 file :

$dat1 = one ruby command |Out-String# $dat1  will contain the value - rake drive:unit_tests:load_data
$dat2 ="  parameters here"
$dat3 = $dat1 + $dat2& $dat3

Password set to expire script

$
0
0

There is a lot of different on this powershell stuff, but unable to get this working

What I search for is a way to create a file, where the usernames are listed, where password will expire within 5 days

I have found the following - it creates a file, but nothing is inside the file. I am a newbie to powershell, so just trying to look what there is on the internet, but not yet found anything that is working

$a = (get-date).AddDays(7) ; Search-ADAccount -AccountExpiring  -TimeSpan "7" | Select-Object SamAccountName,AccountExpirationDate | Sort-Object AccountExpirationDate | Where-Object  {$_.AccountExpirationDate -like $a } | Export-Csv 7_days.csv


Get list of all users that is not member of spesific group

$
0
0

Hi all,

which PowerShell command can i run if i want to get a list of users that is NOT member of a Group where name contains RG-FULL and RG-SEND,then export it to CSV file?

thanks!


Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

Powershell copy worksheet to after destination worksheet

$
0
0

Hi Guys,

I know how to copy sheet to after destination sheet in VBA.

example copies Sheet1, placing the copy after Sheet3:

Worksheets("Sheet1").Copy After:=Worksheets("Sheet3")

But I don't know how to do it in Powershell!

Who could help me?

Auto export database/tables from Local Sql Server to Azure.

$
0
0

Hi,

I'm new to powershell and currently we use a c# app on the local to export data from local to our azure db. I now want to explore other options for auto exporting
and have pegged looking at powershell for a while, after some initail investigations I have to admit I was surprised how much there was too it but I haven't been succesful in
tracking down specific'ish info or scripts on my requirement.

So I'm looking for some advice/pointers/scripts - anything that might help basically :)

Some of our clients run sql server 2005 and some 2008 (express editions). If need be we can probably upgrade the 2005 although I've noted 2005 can run powershell with some install's applied.

So my requirement really is the auto export of preferably just some tables but maybe the whole database from a local sql server/db to an azure sql server/db using powershell.

thanks,


:)

how to change computer name remotely

$
0
0

Hi, Can i change computer description or computer name remotely? with powershell or smth else.

I don't know powershell, so can u help me with that.

Thanks


Forms in PowerShell: create a "Select All" checkbox in a CheckedListBox

$
0
0

Hello all,

I have the following code that generates a checkedlistbox:

cls
import-module ActiveDirectory

Add-Type -AssemblyName System.Windows.Forms

[void][system.reflection.assembly]::LoadWithPartialName("System.Drawing")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form

$objForm.Text = "Test"
$objForm.Size = New-Object System.Drawing.Size(500,200)
$objForm.StartPosition = "CenterScreen"

$CheckedListBox = New-Object System.Windows.Forms.CheckedListBox
$CheckedListBox.Location = New-Object System.Drawing.Size(20,20)
$CheckedListBox.size = New-Object System.Drawing.Size(300,100) #THIS FIELD AND OTHERS HERE NEED TO BE DYNAMIC BASED ON FILE LENGTHS!
$CheckedListBox.CheckOnClick = $true #so we only have to click once to check a box
$CheckedListBox.Items.Add("Select All")
$CheckedListBox.Items.AddRange(1..10)
$CheckedListBox.ClearSelected()
$objForm.Controls.Add($CheckedListBox)

#put form in front of other windows
$objForm.TopMost = $True

#display the form
$DisplayForm = $objForm.ShowDialog()

I'm trying to get it to when the "Select All" checkbox is checked, the form updates all the other checkboxes to being checked while the form is still up (so the user can see they're all checked). I've seen the following post but I can't quite follow it:

http://social.msdn.microsoft.com/Forums/windows/en-US/4c622dbc-71db-4dbc-af3e-9ed793830ef2/checkedlistbox-selct-all-items?forum=winforms

Anyone have any idea how to make a "select all" checkbox?

Using powershell to protect emails using IRM

$
0
0
Team,

We have a requirement to send emails to customers (customer data is stored in SQL Server) and these emails should be protected using IRM feature in Exchange.

Is this possible via powershell ? If so can you please redirect me to some sample code or links.

Thanks in advance

Joseph Samuel

Powershell copy worksheet to after destination worksheet

$
0
0

Hi Guys,

I know how to copy sheet to after destination sheet in VBA.

example copies Sheet1, placing the copy after Sheet3:

Worksheets("Sheet1").Copy After:=Worksheets("Sheet3")


But I don't know how to do it in Powershell!

Who could help me?


Configuration Data for multiple nodes using Pull server

$
0
0

I am trying to set registry keys, which contain hostname variables, across multiple computers. I can do this with a Push scenario, as shown by "Hey Scripting Guys - Use Configuration File to Apply PowerShell DSC to Multiple Servers", but when I try to create a single mof file for pull clients the mof file does not contain all nodes specified in configuration data file.

I have included the Configuration Data psd1 file and the Configuration file ps1 below: 

## Configuration Data.psd1

@{

    # Node specific data

    AllNodes = @(

       @{

            NodeName = "CP-DIAG-05"
        }
       @{

            NodeName = "CP-CRIT-01"
        }
    );
    NonNodeData = ""
}

## Client Pull Settings.ps1

Configuration SetClientPull {


     Node $AllNodes.NodeName {
  
            Registry AltDefaultDomainName {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "AltDefaultDomainName"
                ValueData = "LMHS"
                Force = 'True'
            }
            Registry AltDefaultPassword {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "AltDefaultPassword"
                ValueData = "Password"
                Force = 'True'
            }
            Registry AltDefaultUserName {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "AltDefaultUserName"
                ValueData = $Node.NodeName
                Force = 'True'
            }
            Registry AutoAdminLogon {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "AutoAdminLogon"
                ValueData = "1"
                Force = 'True'
            }
            Registry DefaultDomainName {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "DefaultDomainName"
                ValueData = "LMHS"
                Force = 'True'
            }
            Registry DefaultPassword {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "DefaultPassword"
                ValueData = "Password"
                Force = 'True'
            }
            Registry DefaultUserName {
                Ensure = "Present"
                Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
                ValueName = "DefaultUserName"
                ValueData = $Node.NodeName
                Force = 'True'
            }

     }
}

SetClientPull -ConfigurationData .\AllNodes.psd1  -OutputPath "."

$guid = [guid]::NewGuid().Guid
$source = ".\SetClientPull\*"
$dest = "C:\programdata\PSDSCPullServer\Configuration\$guid.mof"
Copy-Item $source $dest -Force
New-DSCCheckSum $dest

How to Add a field in Array

$
0
0

Hi all;

I've this Script:

$arrComputers= get-Content -Path "C:\PowerShell\Computers.txt"$DataHora=get-date$Contador= @{"Data"=$DataHora}#$Contador.Clear()#$Contador["$ContadorSrv"]=$DataHoraforeach ($strComputerin$arrComputers)
{$SO=Get-WmiObject -query "Select Version from Win32_OperatingSystem"-computer $strComputer$Queue=get-wmiobject -query "select Name,AvgDiskQueueLength from Win32_Perfformatteddata_perfdisk_physicaldisk where Name<>'_Total'"-computername $strComputerforeach ($objItemin$Queue)
	{$ContadorSrv=$strComputer+"-"+$objItem.Name$Contador[$ContadorSrv]=$objItem.AvgDiskQueueLength
	}$CPU=get-wmiobject -query "select PercentProcessorTime from Win32_Perfformatteddata_perfos_processor where name='_Total'"-computername $strComputerforeach ($objItemin$CPU)
	{$ContadorSrv=$strComputer+"-PercentProcessorTime"$Contador["$ContadorSrv"]=$objItem.PercentProcessorTime
	}$Memoria=get-wmiobject -query "select AvailableMBytes from Win32_PerfFormattedData_PerfOS_Memory"-computername $strComputerforeach ($objItemin$Memoria)
	{$ContadorSrv=$strComputer+"-AvailableMBytes"$Contador["$ContadorSrv"]=$objItem.AvailableMBytes
	}if ($SO.version -like"6.*")
	{$Buffer=get-wmiobject -query "select Buffercachehitratio from Win32_PerfFormattedData_MSSQLSERVER_SQLServerBufferManager"-computername $strComputerforeach ($objItemin$Buffer)
		{$ContadorSrv=$strComputer+"-Buffercachehitratio"$Contador["$ContadorSrv"]=$objItem.Buffercachehitratio
		}
	}
}$Contador | out-file ".\Resultado.txt"-Append

And a result like this:

Name                           Value                                                                                   ---------
Host1-3 H:                      0                                                                                       
Data                           05/01/2012 11:11:29                                                                     
Host1-PercentProcessorTime      15                                                                                      
Host1-AvailableMBytes           246263                                                                                  
Host1-2 G:                      0                                                                                       
Host1-Buffercachehitratio       100                                                                                     
Host1-1 F:                      0                                                                                       
Host1-0 C: E:                   0

I need to ADD 1 more column in $Contador with Date and Time to result like this:

Name           Value       Date

_____          _____      _____

Host1-3 H:   0             01/05/2012

What's is the command to add column to a Array, can you help me with a link or another solution?

Tks

 

 


View Ricardo Muramatsu's profile on LinkedIn

DSC configuration data for Script resources

$
0
0

Hi,

I'm trying to use PowerShell DSC to modify a settings file for an in-house application. I'm able to pass configuration data to File resources, but the same syntax doesn't work for Script resources and I'm stuck on how to do this.

The following works for File resources (i.e. $Node.ConfigFolder contains the value specified in the "-ConfigurationData" parameter when I prepared the MOF file):

    File ConfigurationFolder {
            Type = "Directory"
            DestinationPath = $Node.ConfigFolder
            Ensure = "Present"
        }

However, the same thing doesn't work for Script resources:

Script ConfigurationFile { SetScript = { write-verbose "running ConfigurationFile.SetScript"; write-verbose "folder = $($Node.ConfigFolder)"; write-verbose "filename = $($Node.ConfigFile)"; [System.IO.File]::WriteAllText($Node.ConfigFile, "enabled=" + $Node.Enabled); } TestScript = { write-verbose "running ConfigurationFile.TestScript"; write-verbose "folder = $($Node.ConfigFolder)"; write-verbose "filename = $($Node.ConfigFile)"; return (Test-Path $Node.ConfigFile); } GetScript = { @{Configured = (Test-Path $Node.ConfigFile)} } DependsOn = "[File]ConfigurationFolder"

        }

In the Script case, $Node is a null object. All the examples I've seen online for working with configuration data apply to File or Registry resources. Does anyone know how to pass machine-specific values in to a Script resource?

Thanks,

Mike

P.S. I posted the same question to StackOverflow at http://stackoverflow.com/questions/23346901/powershell-dsc-how-to-pass-configuration-parameters-to-scriptresources for anyone else with the same issue.

Forms in PowerShell: Enable Button based on Radio Button click

$
0
0

Hello all,

The following is a basic form with 3 radio buttons:

cls
import-module ActiveDirectory

[void][system.reflection.assembly]::LoadWithPartialName("System.Drawing")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form

$objForm.Text = "Test"
$objForm.Size = New-Object System.Drawing.Size(400,200)
$objForm.StartPosition = "CenterScreen"

$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = New-Object System.Drawing.Size(10,10)
$RadioButton1.Size = New-Object System.Drawing.Size(100,20)
$RadioButton1.Checked = $false
$RadioButton1.text = "Button1"
$objForm.controls.Add($RadioButton1)

$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = New-Object System.Drawing.Size(10,50)
$RadioButton2.Size = New-Object System.Drawing.Size(100,20)
$RadioButton2.Checked = $false
$RadioButton2.text = "Button2"
$objForm.controls.Add($RadioButton2)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(10,120)
$OKButton.Size = New-Object System.Drawing.Size(150,30)
$OKButton.Text = "OK"
$OKButton.Enabled = $false
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$objForm.Controls.Add($OKButton)
$objForm.AcceptButton = $OKButton

$objForm.TopMost = $True

$Form = $objForm.ShowDialog()

What I want is for the "OK" button to become enabled when a radio button is checked. How can I do this?

Modify User's Logonworkstation with multiple workstation list

$
0
0

Hi Genius Guys

I have CSV file with user names and computer names. given example below

SamAccountName Workstations

User1WKS231

User2WKS453

user3Laptop321

Now I need to get all users given above to add workstations in Logon Workstation list. See below snapshot.

Please help me to achieve it.

I got one script below but that is only for one user.

I need to add one user to one workstation which are in the CSV file.

http://community.spiceworks.com/topic/402067-modify-user-s-logonworkstation-with-multipile-stations-list-powershell

===========

Import-ModuleActiveDirectory$complist=Import-Csv-Path"c:\PCList.csv"|ForEach-Object{$_.NetBIOSName}$UserProperties=Get-AdUser-Identityusername-PropertiesLogonWorkstations$comparray=($UserProperties).LogonWorkstationsforeach($compin$complist){$comparray+=","+$comp}Set-ADUser-Identityusername-LogonWorkstations$comparray
Viewing all 21975 articles
Browse latest View live


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