public static void SetReadAccessOnDefinitionFile(string definitionName, string user) { string filePathName = ScheduledJobStore.GetFilePathName(definitionName, "ScheduledJobDefinition"); FileSecurity fileSecurity = new FileSecurity(filePathName, AccessControlSections.Access); FileSystemAccessRule fileSystemAccessRule = new FileSystemAccessRule(user, FileSystemRights.Read, AccessControlType.Allow); fileSecurity.AddAccessRule(fileSystemAccessRule); File.SetAccessControl(filePathName, fileSecurity); }
public static FileStream GetFileForJobDefinition(string definitionName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { if (!string.IsNullOrEmpty(definitionName)) { string filePathName = ScheduledJobStore.GetFilePathName(definitionName, "ScheduledJobDefinition"); return(File.Open(filePathName, fileMode, fileAccess, fileShare)); } else { throw new PSArgumentException("definitionName"); } }