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

ADSI WINNT untick User must change password - will not stay

$
0
0

Hi,

Using powershell remote (w2k12 R2)to try to untick user must change password for a local account. Seems that setinfo() does not save changes.

$strComputer=$env:COMPUTERNAME
$strUser="myUser"
$user= [ADSI]"WinNT://$strComputer/$strUser,user"
$user.Put("PasswordExpired",0)
$user.SetInfo()


After running this powershell shows that Passwordexpired has been changed:

$user.get("PasswordExpired") results in :0

Opening a new session PasswordExpired is still set to 1 thus attribute is not changed.

Any ideas?



Reporting security data- Create a powershell script that reports which security groups have access to machines on the domain

$
0
0

Hello,

I am very new to powershell and was assigned a task build a script that reports which security groups have access to specific machines on the domain. I was also told to try and build a script that will reports which user accounts have local access to machines on the domain. 

I've looked at some scripts that report user data, but they only report which group they're associated with and not which machine. I also tried reading the scripts to get some understanding of how they work, but had no luck. Any help is greatly appreciated! I started youtube'ing tutorial vids, but if anyone would like to share information on good training, I'm all ears!

Thanks,

Michael

Connecting to Sharepoint Online and backing up all users OneDrive for Business data

$
0
0

Hello,

I have been tasked to look into how I can connect to SharePoint Online and copy all the users OneDrive for Business data to a local storage device for backup purposes.

I have easily managed to connect to SharePoint Online using PowerShell however I need advice on how I can access all the users OneDrive for Business data and copy it to a local location, I assume I will be able to use xcopy or robocopy commands to copy the data however it's connecting to the OneDrive for Business that I am strugging with.

Thanks


Find multiple strings in text files powershell

$
0
0

I'm trying to create a script that searches through a folders and subfolders searching all the text files for 2 strings. If a file is found then it copys this to another folder. I'm able to do it for 1 string but i can't seem to figure out a way to do an AND in it. (Using -and in the select-string doesnt seem to work)

This is what I have so far(Quite sure the -or doesn't work)

$user ="domain\username"Invoke-Command-ComputerNameServer-ScriptBlock{Get-ChildItem-recurse -Include*.txt  -path "File Location"|Select-String-pattern ("TAX=1+005+0950"-or "TAX=1+5+0950+0")-SimpleMatch|Copy-Item-Destination"Destination Location"}-credential $user

I'm needing to search for either of the ones in the code above AND either of these 2 "TAX=1+5+0600""TAX=1+005+0600"

Any idea how I can do this?

So basically I want to be able to do

Select-String-pattern (TAX=1+005+0950 OR TAX=1+5+0950+0) AND (TAX=1+005+0600 OR TAX=1+5+0600)

get-childitem infinite loop

$
0
0

I have written a script to check for (Office) lock files, the ones that start with ~$.  Unfortunately I have come across a folder which seems to have a space as its name, possibly made by using alt+0160.  This is unfortunately where the trouble starts, as using Get-ChildItem -Recurse doesn't take into account this character, and instead reads it as the parent folder, causing it to read the parent folder again until it gets to the 'space' folder, where it starts all over again, causing an infinite loop.

Currently, I have gotten this far:

Get-ChildItem -Path $root -Recurse -Force -Filter "~$*" -Exclude " "

This seems to work, but it causes another problem, as some folders have characters which can be interpreted as wildcards by the -Path parameter.  So instead, I prefer to use the -LiteralPath parameter, but for some reason it then doesn't recognize the -Exclude " ".  In addition to this, I would prefer not to exclude the folder, since it does appear to contain lock files.  Renaming the folder is unfortunately not an option.

In case you want to test this, here's how to try it:

  1. Create a folder using file explorer, and when typing in the name, simply type alt+0160.
  2. In Powershell, run the following command:
    Get-ChildItem -Path (your folder name here) -Recurse -Exclude " "
    This should not create an infinite loop.
  3. Next, run the following command:
    Get-ChildItem -LiteralPath (your folder name here) -Recurse -Exclude " "
    This should create an infinite loop.

Thanks in advance to anyone who can point me in the right direction.

Collect Software Inventory

$
0
0

I am looking for a consistent method for collecting software inventory on servers and workstations using PowerShell. Specifically everything listed in Programs and Features. The systems I am collecting from range from Server 2003 - Server 2012 R2 and Windows 7 - Windows 8.1. I've noticed that the 2003 servers include MS updates in the mix. Bonus points if you can provide a solution that eliminates these from the output!

The two methods that I have been leveraging are not consistent. Any advice is greatly appreciated!

Option 1:

Get-ItemProperty against the HKLM Uninstall keys (both regular and Wow6432Node). I found a need to pull from both locations, otherwise inventory is not all inclusive. However, this results in duplicate entries in my output file, and on occasions, entries are still not visible.

Option 2:

Get-WmiObject -Class Win32_Product. This command takes noticeably longer to execute, and a side-by-side comparison of Programs and Features quickly reveals that inventory does not match.

beginner : parsing "$" character within new-smbshare outlet cmd

$
0
0

Hi All,

I am a newbie here.

I would need your help in order to parse "$" character within new-smbshare outlet cmd, here my example:

New-SmbShare -name "hello$"  -Description 'test_hello' -Path 'C:\temp' -ScopeName 'test_3'

I tried with escape and simple quote character, not matter what, it still gives me the same error

if i remove $ character it works as a charm...

i get the following error:

PS C:\WINDOWS\system32> New-SmbShare -name "hello$"  -Description 'test_hello' -Path 'C:\temp' -ScopeName 'test_3'
New-SmbShare : The parameter is incorrect.
At line:1 char:1
+ New-SmbShare -name "hello$"  -Description 'test_hello' -Path 'C:\temp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare) [New-SmbShare]
   , CimException
    + FullyQualifiedErrorId : Windows System Error 87,New-SmbShare
    + CategoryInfo          : InvalidArgument: (:) [New-SmbShare], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,New-SmbShare

thank you in Advance

Will.

Proxy address filter

$
0
0

Hi,

I'm trying to write a PS script that will filter out users who don't have a specific domain referenced in their primary e-mail address, then search each user's proxyaddresses, and if it doesn't find a specific string in the proxyaddress list, write out information about the user to a .csv file. Here's what I've got so far:

Import-Module activedirectory
$users = Get-ADUser -Filter {emailaddress -notlike "*@contoso.com"} -SearchBase ‘dc=contoso,dc=com’ -Properties name, givenname, sn, sAMAccountName, emailaddress, proxyaddresses | select name, givenname, sn, sAMAccountName,emailaddress, proxyaddresses
$foreach($user in $users){
    $sAMAccountName = $user.samaccountName
    $givenname = $user.givenName
    $sn = $user.sn
    $name = $user.name
    $mail = $user.emailaddress
    $proxyaddresses = $user.proxyaddresses
        if($proxyaddresses -notlike "$givenname.$sn@") {
        $result = "$name,$givenname,$sn,$samaccountname,$mail,$proxyaddresses"
        Out-File -FilePath C:\proxyaddresses.csv -InputObject $result -Append
        }
    }

Is there a more efficient way to look through each person's proxy address list? Since the $proxyaddresses object is a string, I've tried using -notlike, -notmatch and  -notcontains in the IF...statement, but none of them return accurate information. I've also tried sending it through a pipeline using "Where $_.proxyaddresses", but that doesn't seem to work well either.

Any suggestions would be appreciated.

Thanks.


Counting number of lines in a csv file but without counting whitespace or newline feed?

$
0
0

Hi,

I have a csv file but the records (seperated by comma) has spaces. For eg: :  :

,"1113 Riders Club Road

 

",

 

 

Due to these space when I try to read the no. of lines throug get-content, it count these spaces as well and my result is more than that is expected. Please help me in counting the actual no. of lines ignoring these spaces. Let me know if you need more information

Thanks


Get computername and last logged on user from OU

$
0
0

Hi guys,

I'm a newbie with powershell. Could you guys please help me on how to return object names and last logged on user from specific OU? Currently I have this little script but I have to enter an object name everytime:

Get-WmiObject -Class win32_process -ComputerName objectname | 
    Where-Object{ $_.Name -eq "explorer.exe" } | 
    ForEach-Object{ ($_.GetOwner()).Domain + "\\" + ($_.GetOwner()).User; }
echo objectname

Thanks a lot!!

Steve

All PS scripts in windows scheduler suddenly don't work anymore

$
0
0

I have four PS scripts executed daily by windows scheduler and suddenly two weeks ago all stopped working. I checked also if windows (7 home premium) installed new updates, but there was only windows essential updates. All the scripts work if executed manually, but now any PS script executed through windows scheduler fails always, I can't find any error anywhere, just the result of the task is 0x1 without a message.

I have created also a test script:

write-host (get-date) "This is a test"

and the "action" of the task is:

Program/script: powershell.exe
Add arguments: -c .\test.ps1

And it fails too, but two weeks ago they were all working. I'm quite sure about the day that they stopped working because I save the script output in a log file with the following technique:

Program/script: powershell.exe
Add arguments: -c "powershell -c .\test.ps1 2>&1 >> .\test.log"

And the last entry in the log files is dated 05/17/2016, so since then all the scripts fail and I can't find the reason, I looked also in the event viewer and activated the task history, but nothing, no errors. I can't find anywhere an error, a clue that can point me in the right direction. At this point I would appreciate some help because I am out of ideas.

Thanks in advance.

Get Exchange Mailbox Sizes

$
0
0

Hello,

I have a request to get a script together to get all of the mailboxes over 2GB in our company. There are more than 1000 mailboxes. I have the below script and for some reason it seems to be hanging and ignoring my Else If statement. 

I want to be able to have the script prompt for a username to get the results for and exported to a CSV. If no input is entered (by simply hitting enter), I want it to run for all mailboxes. We are running exchange 2010. 

Thanks!

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://SERVER/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session
$NAME = read-host "enter the name of the mailbox, or Press Enter for all mailboxes"

if($NAME -eq "")
{get-mailbox -ResultSize Unlimited | get-mailboxstatistics | select DisplayName,ItemCount,TotalItemSize | export-csv -path "C:\users\jthibeault\desktop\MailboxSizes.csv"}

Else 

{get-mailbox -ResultSize Unlimited | get-mailboxstatistics -identity $NAME | select DisplayName,ItemCount,TotalItemSize | export-csv -path "C:\users\jthibeault\desktop\MailboxSizes.csv"} 

Remove-PSSession $Session

Powershell Kill Background Processes

$
0
0

Hello All,

I am trying to kill back ground processes that appear in the task manager

kill -processname Google Crash Handler

kill -processname Adobe

kill -processname b.exe

etc

I created a power shell file  - when i run it  - the task manager entries are not killed.

Why is this not working :(

thanks for advice

Installation of PowerShell 5.0 on Windows 2012 R2

$
0
0

I am trying to install W2K12-KB3134759-x64.msu package which installs PowerShell 5.0

When I double click on the installer, it throws the message "The update is not applicable on this computer"

The current version of PS is 4.0 and .NET Framework version is 4.5.2. The server is Windows 2012 R2

Are there any other prerequisites to install WMF 5.0?

Thanks

Anand

how to manage the EOP license

$
0
0

Hello,

I just want to know how to manage the EOP licenses.

i have multiple  user in my tenant and i want to know how many users have  license assigned.

So for that i have ran the mentioned Command but noting found.

Get-MSOLUser -All | select userprincipalname,islicensed,{$_.Licenses.AccountSkuId}| Export-CSV c:\userlist.csv -NoTypeInformation

And in the portal their is no such option to assign the license to the user.

Any help would be appreciated.

Thanks

Lovekesh


Invoke-Command to multi-thread processing of files across two servers but not the same files.

$
0
0

I have two servers that have similar environments, one server is supposed to back up the other for redundancy.  It is often necessary when things start lagging to divide up the work between the two servers.  Right now it has to be done manually, so I figured I would write a powershell script to do it in an automated fashion.

So I have a workflow that performs a for each loop using parallel and throttlelimit parameters to limit the number of processes that run at the same time.  I guess I misunderstood how Invoke-Command works because it is trying to process the same file across both servers when what I really want is to use both servers to process files but not the same file.  I'd like to take advantage of the processing power of both servers sort of like a cluster of servers.  Can Invoke-Command be used in this way or should I be looking elsewhere

The script looks like the following, I have removed some of the proprietary elements but the script does currently work, just not like I thought it would because it tries to process each file against each server.  I'd appreciate any constructive feedback that might help me get on track.  Thanks

Workflow Process_Spooled_Documents 
    { 
Param (
        $ThrottleLimit
)

    $SpoolFiles = Get-ChildItem "\\$env:ComputerName\c$\Windows\System32\spool\PRINTERS\*.SPL" | Select FullName, DirectoryName, BaseName, Name
$logfile = "\\$env:ComputerName\D$\Logs\Process_SpoolFiles-$(get-date -format `"yyyyMMdd_hhmmsstt`").log"
ForEach -Parallel -ThrottleLimit $ThrottleLimit ( $SpoolFile in $SpoolFiles) 
{   $fileName = $SpoolFile.FullName
$shadowCopy = $SpoolFile.DirectoryName + "\" + $SpoolFile.BaseName + ".SHD"
Write-Output "Processing $filename" | Out-File $logfile -Append -NoClobber
InlineScript 
{ (Invoke-Command -ComputerName server1, server2 -FilePath C:\Process_Spool_File.ps1 `
-ArgumentList $Using:fileName)
}
If (Test-Path $shadowCopy){
Write-Output "Removing $shadowCopy" | Out-File $logfile -Append -NoClobber
Remove-Item $shadowCopy -Force | Out-File $logfile -Append -NoClobber
}
        }    

}

Process_Spooled_Documents 4

How to test Set-ADForestMode

$
0
0

Hi Gents,

Before we raise our forest level, I would like to test if there will be any issues using powershell but I cannot find anything in the net. The test I'm looking for is like checking the schema if all requirements are met to raise the forest and domain function level to 2012.

I'm hoping to hear from you soon.

Thanks,

Rey


None

Getting Error while running Get-DscConfiguration in Windows Server 2008 R2

$
0
0

Hi ,

I am trying to run "Get-DscConfiguration -Verbose" in server 2008 R2 in order to upload the output of it Pull Server using POST method. But I am getting following error :

Get-DscConfiguration : Current configuration does not exist. Execute Start-DscConfiguration command 
with -Path parameter to specify a configuration file and create a current configuration first.At 
line:1 char:1
+ Get-DscConfiguration -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_DSCLocalConfigurationManager:root/Microsoft/...gura 
   tionManager) [Get-DscConfiguration], CimException
    + FullyQualifiedErrorId : MI RESULT 1,Get-DscConfiguration

The same works pretty well for 2012 server and I able to upload the same.


Regards,

Sudhakar

Using CSV remove users from all Distribution Groups

$
0
0

Presently, I use the following to remove a named user from all distribution groups:

Get-DistributionGroup | Remove-DistributionGroupMember -Member username@domain.com

The problem with the above is that it attempts to remove the user from all DG's (not just the ones for which they are a member).  This is inefficient but gets the job done.

I'm consulting this forum because I want to perform the above against a list of users in a CSV.

Use case: Batches of temporary employees sometimes leave organization and I want to process in bulk.

All help is appreciated!  Thanks in advance,

Sean-Colin

Enter-PSSession errorcode 0x80090322

$
0
0

Hi

I've got this ugly error "errorcode 0x80090322" when accessing one specific remote system:

Enter-PSSession : Connecting to remote server SC001407 failed with the following error message : WinRM cannot process
the request. The following error with errorcode 0x80090322 occurred while using Kerberos authentication: An unknown
security error occurred.

i've tryed:

- Connecting with Credential (UPN and User DNS Name)
- Resetting DNS cache (ipconfig /flushdns)
- Resetting NetBios cache (NBTStat –R)
- Resetting Kerberos Tickets (KList purge)
- Checking Trusted hosts (Get-Item wsman:localhost\client\trustedhosts) -> * on source and target system
- Checking for duplicate SPN entries (setspn -X)
- Checking for existance of http SPN entries (setspn -L)
- Enable-PSRemoting
Everything seems to be OK. Latley, I was able to enter a pssession on this machine, now it is not possible anymore (unfortunatley, we have no change history for this server, because it is not productive)
Here my spn's:

PS C:\> setspn -L myserver
Registered ServicePrincipalNames for CN=myserver,OU=Dev_WP-SC,OU=Dev_WP,OU=Dev_Res,OU=Dev,DC=mydomain,DC=ch:
        MSOMHSvc/myserver
        MSOMHSvc/myserver.mydomain.ch
        MSSQLSvc/myserver.mydomain.ch:1433
        MSSQLSvc/myserver.mydomain.ch
        TERMSRV/myserver
        TERMSRV/myserver.mydomain.ch
        WSMAN/myserver
        WSMAN/myserver.mydomain.ch
        RestrictedKrbHost/myserver
        HOST/myserver
        RestrictedKrbHost/myserver.mydomain.ch
        HOST/myserver.mydomain.ch

Any Ideas?

Thomas



Viewing all 21975 articles
Browse latest View live


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