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

CurrentVersion\Run vs Scheduled Task

$
0
0

In the VBScript flavor of my deployment tool I used HKLM\Software\Microsoft\Windows\CurrentVersion\Run to trigger a script to handle the user initiation parts of Autodesk deployments. But in my searches for similar ideas in PowerShell I see a lot of references to scheduled tasks for this scenario. My use case is a persistent script that runs at logon for the life of the machine, not a one time or even temporary scenario. And the script needs access to the network and such. But other than that, it is pretty basic, has no user interaction, and completes quickly.
Are there any pros & cons to be aware of, or situations that make Scheduled Tasks consistently the better answer? 

Thanks!
Gordon


Send-MailMessage the server response was: #4.x.2 Too many messages for this session

$
0
0

I have a scheduled task that will check for passwords expiring in 15 days or less and fire off a reminder email to the user that they have x days left to change it.  However, there are usually 70+ addresses in this list and after 10 messages are sent the following error appears:

The server response was: #4.x.2 Too many messages for this session

The script will continue and then after 10 more, the same error.  I have even moved the function using send-mailmessage to a separate .ps1 file and call it from the parent .ps1 but the error continues.  I don't want to bump up the concurrent connection limit on my relay, is there any clean way to close the send-mailmessage session?  Otherwise I'll probably just loop the task to catch the error condition.  For what it's worth, the server running this task has .NET 4.0 installed.

Target a specific domain controller when running a cmdlet

$
0
0
Nearly every cmdlet I'm using in a script supports -DomainController. Except one. Is there a way to force a cmdlet to use a specific DC? In this instance, remote PowerShell is not an option. This is a script running in PowerShell directly on a Lync server.

Remove-Items permissions: Win8.1 vs Win7

$
0
0

Has Windows 8 locked up Program Files in a way that Win 7 didn't? I have a script that uses Remove-Item to delete files and folders from C:\Program Files and it works fine in Win 7 but not in Win 8.1. Both users are local admins, execution policy is Unrestricted and AUC is minimal on both machines. Currently the script is not signed, but ultimately it will be and RemoteSigned will be the policy, if that has any impact. I hope not because it would make development a pain.

Anyway, hoping for some insights. I would guess 99% of my users are not going to Win 8 in any flavor for at least another year or more, likely not till they can go to 9, but I would like to support the new Vista if possible. ;)

EDIT: on a possibly related note, is there anything that needs to be handled in script when launching with elevated privileges via a shortcut? The shortcut passes arguments to the script, so I need that procedure. And when I launch the shortcut with Run as Administrator I get a flash of error red text and the console is gone. Which is odd because the shortcut uses the -noexit flag. 
And lastly, the other way the scripts are launched is with SCCM. I assume if the only way to get things to work in Win 8 and above is elevated privileges, there is a way to push an elevated script in SCCM?

EDIT 2: Seems I have the same problem with deleting reg keys from HKLM. Code worked fine in Win 7, fails with permission errors in Win 8.1. Fun.

Thanks!
Gordon



Failed to enumerate SSL bindings error code 234

$
0
0

Hello, does anybody know how to resolve this issue? Replicate when you type the following command in PowerShell.

dir iis:\sslbindings

Have comes across a forum topic (not allowed to post links yet :\ entitled (on this forum)

Enumerating IIS:\SSLBindings gives failure on one machine, works on another 

However, this doesn't address the problem :(

Hoping Yan Li shows up here or someone from the Microsoft team to aid me in solving this issue.

Thanks in advance, Onam.

Read in specific line numbers from a text file (very large 1.5GB) using PowerShell

$
0
0

Hi all,

I have a large file (a text file) which is over 1.5GB in size. 

I need to read in specific line numbers from the file, I have a list of exact line numbers I wish to read.

If I use "get-content" to read in all the contents, PowerShell consumes 1.3GB in memory then crashes out.  I don't have enough memory to cope with using get-content to read in all the contents.

Is there any way of doing the following:

       $entry = get %linenumber% from %filename%

Any help is greatly appreciated!

Kathy


Kathleen Hayhurst Senior IT Support Analyst

Compare AD to CSV File

$
0
0

I'm fairly new to PowerShell. I've done some programming and very little scripting, but small words would be good :)

My organization had about 5,300 users we needed to disable for a client. Someone decided the best use of our time was have people go through AD and disable them one at a time. Soon as I got wind of this I put a stop to it and used PowerShell to take the CSV list we already had, and ran a cmdlet to disable all of the users in the CSV list.

This appeared to work, but I wanted to run a comparison. I want to compare the users from the CSV file, to the users in AD, and confirm that they are all disabled without having to check all 5300 individually. We checked about 60 random ones to verify my run worked, but I want to make sure none slipped through the cracks.

I've tried a couple scripts and I've tried some variations of cmdlets. None of the scripts I tried even worked, spammed with errors. When I try to run a search of AD either using get-content or import-CSV from the csv file, when I export its giving me about 7600 disabled users (if I search by disabled). There were only 5300 users in total, so it must be giving me all of the disabled users in AD. Other cmdlets i've run appear to do the same thing, its exporting an entire AD list instead of just comparing against my CSV file.

Any assistance anyone can provide would be helpful.

Retrieving specific information (email addresses) from Active Directory in text/Excel file

$
0
0

Hello, out there. I'm just beginning to learn PowerShell finally, I'm very interested in learning cooler and better things.

I wanted to know if retrieving information from Active Directory based on a text or spreadsheet file was possible.

An example: I have a list of Windows Usernames from an Excel file, and I need to pull what email addresses they have from AD. They're a part of different OUs either. Rather than manually look up each individual account I'm researching a way to grab this info.

I would very much appreciate a push in the right direction.

Thank you!


LiQuiD_FuSioN


Remote Removal Of Windows Shares

$
0
0

Hi,

I am trying to automate a migration process involving thousands of user shares. In the past they were all entered as \\server\username$ & I am trying to move to DFS with just a few shares per drive. Once I can get this script to work, I will use Import-Csv to pass the data in chunks, the problem is getting this to work.

cls
Write-Host "********************************************************************"
Write-Host "**                       User Admin Tool                      **"
Write-Host "********************************************************************"
$ServerName = (Read-Host "Please Enter The Target Server")
$ShareName = (Read-Host "Please Enter The User Share To Remove")
write-host "Retrieving user objects...." -ForegroundColor Magenta
start-sleep -s 1
#([wmi]'$ServerName\root\cimv2:Win32_Share="$ShareName"').Delete()
Get-WmiObject Win32_Share -Filter "Name='$ServerName\$ShareName'" | Remove-WmiObject
write-host "Saving user objects...." -ForegroundColor Blue
start-sleep -s 1

The line that is #'d out will work if I replace the variables with real data, but will not resolve the variables. The line below that (Get-WmiObject) will resolve the variables, but gives the following error;

Get-WmiObject : Invalid query "select * from Win32_Share where Name='\\Server\joebloggs$'"
At Z:\PS Scripts\RemoveUserShare.ps1:10 char:1
+ Get-WmiObject Win32_Share -Filter "Name='$ServerName\$ShareName'" | Remove-WmiOb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObje 
   ctCommand

Any help will be greatly appreciated, although I am sure it is probably something simple.

Thanks,

Peaca


What permissions are needed on the client side for RunspaceFactory.CreateRunspace?

$
0
0

Hi.

I am running a remote powershell command from an IIS application to an Exchange server getting the below error. Everything works fine if the IIS application pool identity is in the local administrators group on the IIS server so we can rule out issues with firewall or anything on the Exchange server. It is a problem with lack of privileges on the local server. 

So my question is: What permissions are required on the local server for RunspaceFactory.CreateRunspace? I find good documentation on the permissions required on the server side, but nothing about the client side.

The last Win32 error code after failure is 1008.

An internal error occurred. 
at at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.Initialize(Uri connectionUri, WSManConnectionInfo connectionInfo) 
at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager..ctor(Guid runspacePoolInstanceId, WSManConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper) 
at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl..ctor(ClientRemoteSession session, PSRemotingCryptoHelper cryptoHelper, RunspaceConnectionInfo connectionInfo, URIDirectionReported uriRedirectionHandler) 
at System.Management.Automation.Remoting.ClientRemoteSessionImpl..ctor(RemoteRunspacePoolInternal rsPool, URIDirectionReported uriRedirectionHandler) 
at System.Management.Automation.Internal.ClientRunspacePoolDataStructureHandler..ctor(RemoteRunspacePoolInternal clientRunspacePool, TypeTable typeTable) 
at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal..ctor(Int32 minRunspaces, Int32 maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo) 
at System.Management.Automation.Runspaces.RunspacePool..ctor(Int32 minRunspaces, Int32 maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo) 
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspacePool(Int32 minRunspaces, Int32 maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) 
at System.Management.Automation.RemoteRunspace..ctor(TypeTable typeTable, RunspaceConnectionInfo connectionInfo, PSHost host, PSPrimitiveDictionary applicationArguments) 
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) 
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(RunspaceConnectionInfo connectionInfo) 

Move Users Favorites Folder in Roaming Profile and then Delete?

$
0
0

Hello,

My current scenario is as follows for user accounts:

\\90.244.233.10\userprofile$\User-16 (this is their profile path)

\\90.244.233.10\userprofile$\User-16\Favorites (this is their favorites folder)

I need to take the above favorites folder and move it to their userhome$ folder found here:

\\90.244.233.10\userhome$\%username%\Favorites (these folders already exist) 

Then delete their complete userprofile$ folder.

How can I achieve this using powershell? I think the tricky part for me is going through each folder in userprofile$ and looking for a \Favorites folder and then matching that userprofile$ foldername to %username% since they're the same.

Thank you.

Find text(regex) in excel cell

$
0
0

Hi,

Is it possible to search a spreadsheet for a regex and output it to a file?  The spreadsheet has many occurences of test beginning A.## (hash being a number between 0-10)

IS this possible... 

Sorry for the lack of code ....


Alter De Ruine

Add-Computer to domain with new name returns error

$
0
0

Hi Folks:

I am writing a script that configures servers and joins them to a domain. Near the end of the script I've added the command,

Add-Computer -DomainName 'domainname' -Credential (Get-Credential 'domain\Administrator') -OUPath 'path' -NewName 'CONSOLE' -Force

I receive the error message:

Add-Computer : Computer 'WIN-TLDK7T4SNDE' was successfully joined to the new domain 'domainname', but renaming it to 'CONSOLE' failed with the following error message: The directory service is busy.

CategoryInfo: OperationStopped: (WIN-TLDK7T4SNDE:String) [Add-Computer], InvalidOperationException

FullyQualifiedErrorId: FailToRenameAfterJoinDomain,Microsoft.Powershell.Commands.AddComputerCommand

The error is intermittent and I've tried this on various configurations using Windows Server 2012 core for the domain controller(s). Here are the configurations that I've tried:

1. A primary domain controller in its own forest

2. A primary domain controller in its own forest with a backup domain controller (DNS on primary domain controller points to backup domain controller address with loopback address as secondary, DNS on backup points to primary domain controller address with loopback as secondary.) I've run 'repadmin /syncall' and it seems to replicated just fine.

I'm testing the system on VMware Workstation 9.2 where the occurs with some frequency and I've also but a sandbox system using older computers and it occurs nearly all the time.

I've scanned the forums and Googled the error without much success. Any ideas? Thanks in advance!

Have a GREAT DAY!!

Shaun

What does ">>" mean in powershell 2.0?

$
0
0

I entered the command

Set-OABVirtualDirectory <CAS2010>\OAB* -ExternalUrl "https://mail.contoso.com/OAB"

and got >>

Then I entered a simple.    Get-Eventlog system -newest 100 | where {$_.eventid -eq 20}

and got >>


lejon

Powershell scripts run in console but does not run as Job

$
0
0

Hello,

I have a Powerscript script that run great when run in the console but as soon as I create a schedule Job is stops running.

The script spawns off child jobs, these child jobs are the one that are not running. 

The child jobs are simple jobs that call an other script with pass in a couple parameters.

The Jobs do start but quickly stop, (state changes to Stopped) I do not see any error messages or returned results from the child job.  I do register for the change State event of the child job and I am getting the event but the as I said the job has stopped and no error or results are in the job itself.

I have a number of other script that are scheduled like this, plus they have to same architecture, this is the only one that does not seem to work.

How do I go about trying to figure way these child jobs are no running?

Thanks

Brian


Brian Jon Hopenwasser MSTS: TFS 2010 Admin MSTS: TFS 2005 Developer


Exchange - Contacts and Mailbox permissions

$
0
0

Hi,

I need to setup forwarding for multiple users to a contact of the same name. (contacts are created)

At the same time I would like to remove "self" permission and add the users account from a trusted domain with full mailbox access.

Is this possible via PS script?

Thanks

Using a lookup from one CSV file to another CSV file errors with a name clash

$
0
0

Hi

I have a master CSV file created by querying the AD. I need to populate the "Team" attribute by doing a lookup using Name against  the Name Column any of 6 CSVs,  someone has prepared for me .  The problem is the data is inconsistent in the 6 CSV files so Name can hold either the Name or Username i.e. SAmAccountName or LoginName

Now my ps script works when the data is good. but I have around 30 exception cases whereby there is a mismatch .  To explain:

is in this line ( see the big code block below) 

   $userObject = $nameAndTeamCsvData | Where-Object {$_.Name -eq $masterUserName} 

The $_.Name is using the top level masterCSVData Name but I was hoping that it was using the$nameAndTeamCSVData.Name as in only within the scope of the Where-Object {} ..I guess I have misunderstood the syntax of what I had written.

. A quick a dirty fix would be rename this column in all of the 4 spreadsheets or trying to fix the code.....

# now update the empty team value for user object $csvMasterData | ForEach-Object ` { $masterName = $_.Name $masterUserName = $_.Username # to deal with exception cases #force scope to as the properties in the outer with the same name should be out of scope # lookup the Name to see if we can extract the user's Team $userObject = $nameAndTeamCsvData | Where-Object {$_.Name -eq $masterName } # deal with the situation where the name in the businesses spreadsheets is actually the Username (login name) in the master csv if ( $userObject -eq $null ) { # lookup the username (loginname) to see if we can extract the user's Team

# !!!!error occurs here with the $_.Name !!!!! $userObject = $nameAndTeamCsvData | Where-Object {$_.Name -eq $masterUserName} if ( $userObject -eq $null ) { $_.Team = "UNKNOWN" } else { # replace the mastercsv.Team with the one we have looked up $_.Team = $userObject.Team } } else { # Name matches so replace the mastercsv.Team with the one we have looked up $_.Team = $userObject.Team } }

 


Daniel


How to enable powershell remoting in Powershell V3?

$
0
0

I'm running powershell 3.0 in Windows 7 and I'm connected to a domain.

These are the logs I get when I run Enable-PSRemoting:

WinRM has been updated to receive requests.
WinRM service type changed successfully.

Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2"
Machine="localhost"><f:Message><f:ProviderFault provider="Config provider" path="%systemroot%\system32\WsmSvc.dll"><f:WSManFault
xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2" Machine="mycomputername.mydomainname"><f:Message>Unable to check the sta
the firewall. </f:Message></f:WSManFault></f:ProviderFault></f:Message></f:WSManFault>
At line:1 char:1+ Set-WSManQuickConfig+ ~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException+ FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuickConfigCommand

Thanks in advance !


Validate if a user is a member of group in AD

$
0
0

How do I verify whether a user is a member of "Department" group or not in Active directory using powershell?

I can see the member by going to properties -- Member of -- and can see all the members of users.

How do i do the same in Powershell?

Job powershell fail through scheduler

$
0
0

I have a dilemma.  I am using the Windows Server 2012 scheduler to execute powershell scripts. 

To experiment, poured a new W2012, has created a new domain test.wan isolated network .

- Created by user adm, appointed him as the domain administrator.

- Create a directory c:\temp

- Created script d:\backup\test.ps1 with content:

get-date >> c:\temp\log.txt

Set-ExecutionPolicy RemoteSigned unRegister-ScheduledJob -Name Backup

$t = New-JobTrigger -Weekly -DaysOfWeek 1,2,3,4,5 -At 11:00PM

$cred = Get-Credential test\adm

$o = New-ScheduledJobOption -RunElevated

Register-ScheduledJob -Name Backup -FilePath d:\backup\test.ps1 -Trigger $t -Credential $cred -ScheduledJobOption $o


- Start the scheduler and manually run the task - write to the file worked.

- Then i logout test\adm

- Logged under test\Administrator

- Start the scheduler and manually run the task - write to a file does not work in the job log all ok .

- Launched cmd as test\adm

- Start the scheduler and manually run the task - write to the file worked.

Why ? ?


ps: On Windows Server 2008R2 is no such problem.


Viewing all 21975 articles
Browse latest View live


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